AvatarFactoryModuleTests.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.CoreModules.Asset;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Tests.Common;
  36. using OpenSim.Tests.Common.Mock;
  37. namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
  38. {
  39. [TestFixture]
  40. public class AvatarFactoryModuleTests : OpenSimTestCase
  41. {
  42. /// <summary>
  43. /// Only partial right now since we don't yet test that it's ended up in the avatar appearance service.
  44. /// </summary>
  45. [Test]
  46. public void TestSetAppearance()
  47. {
  48. TestHelpers.InMethod();
  49. // log4net.Config.XmlConfigurator.Configure();
  50. UUID userId = TestHelpers.ParseTail(0x1);
  51. AvatarFactoryModule afm = new AvatarFactoryModule();
  52. TestScene scene = new SceneHelpers().SetupScene();
  53. SceneHelpers.SetupSceneModules(scene, afm);
  54. ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
  55. byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
  56. for (byte i = 0; i < visualParams.Length; i++)
  57. visualParams[i] = i;
  58. afm.SetAppearance(sp, new Primitive.TextureEntry(TestHelpers.ParseTail(0x10)), visualParams);
  59. // TODO: Check baked texture
  60. Assert.AreEqual(visualParams, sp.Appearance.VisualParams);
  61. }
  62. [Test]
  63. public void TestSaveBakedTextures()
  64. {
  65. TestHelpers.InMethod();
  66. // log4net.Config.XmlConfigurator.Configure();
  67. UUID userId = TestHelpers.ParseTail(0x1);
  68. UUID eyesTextureId = TestHelpers.ParseTail(0x2);
  69. // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
  70. // to the AssetService, which will then store temporary and local assets permanently
  71. CoreAssetCache assetCache = new CoreAssetCache();
  72. AvatarFactoryModule afm = new AvatarFactoryModule();
  73. TestScene scene = new SceneHelpers(assetCache).SetupScene();
  74. SceneHelpers.SetupSceneModules(scene, afm);
  75. ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
  76. // TODO: Use the actual BunchOfCaps functionality once we slot in the CapabilitiesModules
  77. AssetBase uploadedAsset;
  78. uploadedAsset = new AssetBase(eyesTextureId, "Baked Texture", (sbyte)AssetType.Texture, userId.ToString());
  79. uploadedAsset.Data = new byte[] { 2 };
  80. uploadedAsset.Temporary = true;
  81. uploadedAsset.Local = true; // Local assets aren't persisted, non-local are
  82. scene.AssetService.Store(uploadedAsset);
  83. byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
  84. for (byte i = 0; i < visualParams.Length; i++)
  85. visualParams[i] = i;
  86. Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
  87. uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
  88. Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
  89. eyesFace.TextureID = eyesTextureId;
  90. afm.SetAppearance(sp, bakedTextureEntry, visualParams);
  91. afm.SaveBakedTextures(userId);
  92. // Dictionary<BakeType, Primitive.TextureEntryFace> bakedTextures = afm.GetBakedTextureFaces(userId);
  93. // We should also inpsect the asset data store layer directly, but this is difficult to get at right now.
  94. assetCache.Clear();
  95. AssetBase eyesBake = scene.AssetService.Get(eyesTextureId.ToString());
  96. Assert.That(eyesBake, Is.Not.Null);
  97. Assert.That(eyesBake.Temporary, Is.False);
  98. Assert.That(eyesBake.Local, Is.False);
  99. }
  100. }
  101. }