AvatarFactoryModuleTests.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
  37. {
  38. [TestFixture]
  39. public class AvatarFactoryModuleTests : OpenSimTestCase
  40. {
  41. /// <summary>
  42. /// Only partial right now since we don't yet test that it's ended up in the avatar appearance service.
  43. /// </summary>
  44. [Test]
  45. public void TestSetAppearance()
  46. {
  47. TestHelpers.InMethod();
  48. // TestHelpers.EnableLogging();
  49. UUID userId = TestHelpers.ParseTail(0x1);
  50. UUID bakedTextureID = TestHelpers.ParseTail(0x2);
  51. // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
  52. // to the AssetService, which will then store temporary and local assets permanently
  53. TestsAssetCache assetCache = new TestsAssetCache();
  54. AvatarFactoryModule afm = new AvatarFactoryModule();
  55. TestScene scene = new SceneHelpers(assetCache).SetupScene();
  56. SceneHelpers.SetupSceneModules(scene, afm);
  57. ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
  58. // TODO: Use the actual BunchOfCaps functionality once we slot in the CapabilitiesModules
  59. AssetBase bakedTextureAsset;
  60. bakedTextureAsset
  61. = new AssetBase(
  62. bakedTextureID, "Test Baked Texture", (sbyte)AssetType.Texture, userId.ToString());
  63. bakedTextureAsset.Data = new byte[] { 2 }; // Not necessary to have a genuine JPEG2000 asset here yet
  64. bakedTextureAsset.Temporary = true;
  65. bakedTextureAsset.Local = true;
  66. scene.AssetService.Store(bakedTextureAsset);
  67. byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
  68. for (byte i = 0; i < visualParams.Length; i++)
  69. visualParams[i] = i;
  70. Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
  71. uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
  72. Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
  73. int rebakeRequestsReceived = 0;
  74. ((TestClient)sp.ControllingClient).OnReceivedSendRebakeAvatarTextures += id => rebakeRequestsReceived++;
  75. // This is the alpha texture
  76. eyesFace.TextureID = bakedTextureID;
  77. afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
  78. Assert.That(rebakeRequestsReceived, Is.EqualTo(0));
  79. AssetBase eyesBake = scene.AssetService.Get(bakedTextureID.ToString());
  80. Assert.That(eyesBake, Is.Not.Null);
  81. Assert.That(eyesBake.Temporary, Is.True);
  82. Assert.That(eyesBake.Local, Is.True);
  83. }
  84. /// <summary>
  85. /// Test appearance setting where the baked texture UUID are library alpha textures.
  86. /// </summary>
  87. /// <remarks>
  88. /// For a mesh avatar, it appears these 'baked textures' are used. So these should not trigger a request to
  89. /// rebake.
  90. /// </remarks>
  91. [Test]
  92. public void TestSetAppearanceAlphaBakedTextures()
  93. {
  94. TestHelpers.InMethod();
  95. // TestHelpers.EnableLogging();
  96. UUID userId = TestHelpers.ParseTail(0x1);
  97. UUID alphaTextureID = new UUID("3a367d1c-bef1-6d43-7595-e88c1e3aadb3");
  98. // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
  99. // to the AssetService, which will then store temporary and local assets permanently
  100. TestsAssetCache assetCache = new TestsAssetCache();
  101. AvatarFactoryModule afm = new AvatarFactoryModule();
  102. TestScene scene = new SceneHelpers(assetCache).SetupScene();
  103. SceneHelpers.SetupSceneModules(scene, afm);
  104. ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
  105. AssetBase libraryAsset;
  106. libraryAsset
  107. = new AssetBase(
  108. alphaTextureID, "Default Alpha Layer Texture", (sbyte)AssetType.Texture, userId.ToString());
  109. libraryAsset.Data = new byte[] { 2 }; // Not necessary to have a genuine JPEG2000 asset here yet
  110. libraryAsset.Temporary = false;
  111. libraryAsset.Local = false;
  112. scene.AssetService.Store(libraryAsset);
  113. byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
  114. for (byte i = 0; i < visualParams.Length; i++)
  115. visualParams[i] = i;
  116. Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
  117. uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
  118. Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
  119. int rebakeRequestsReceived = 0;
  120. ((TestClient)sp.ControllingClient).OnReceivedSendRebakeAvatarTextures += id => rebakeRequestsReceived++;
  121. // This is the alpha texture
  122. eyesFace.TextureID = alphaTextureID;
  123. afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
  124. Assert.That(rebakeRequestsReceived, Is.EqualTo(0));
  125. }
  126. [Test]
  127. public void TestSaveBakedTextures()
  128. {
  129. TestHelpers.InMethod();
  130. // log4net.Config.XmlConfigurator.Configure();
  131. UUID userId = TestHelpers.ParseTail(0x1);
  132. UUID eyesTextureId = TestHelpers.ParseTail(0x2);
  133. // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
  134. // to the AssetService, which will then store temporary and local assets permanently
  135. TestsAssetCache assetCache = new TestsAssetCache();
  136. AvatarFactoryModule afm = new AvatarFactoryModule();
  137. TestScene scene = new SceneHelpers(assetCache).SetupScene();
  138. SceneHelpers.SetupSceneModules(scene, afm);
  139. ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
  140. // TODO: Use the actual BunchOfCaps functionality once we slot in the CapabilitiesModules
  141. AssetBase uploadedAsset;
  142. uploadedAsset = new AssetBase(eyesTextureId, "Baked Texture", (sbyte)AssetType.Texture, userId.ToString());
  143. uploadedAsset.Data = new byte[] { 2 };
  144. uploadedAsset.Temporary = true;
  145. uploadedAsset.Local = true; // Local assets aren't persisted, non-local are
  146. scene.AssetService.Store(uploadedAsset);
  147. byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
  148. for (byte i = 0; i < visualParams.Length; i++)
  149. visualParams[i] = i;
  150. Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
  151. uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
  152. Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
  153. eyesFace.TextureID = eyesTextureId;
  154. afm.SetAppearance(sp, bakedTextureEntry, visualParams, new WearableCacheItem[0]);
  155. afm.SaveBakedTextures(userId);
  156. // Dictionary<BakeType, Primitive.TextureEntryFace> bakedTextures = afm.GetBakedTextureFaces(userId);
  157. // We should also inpsect the asset data store layer directly, but this is difficult to get at right now.
  158. assetCache.Clear();
  159. AssetBase eyesBake = scene.AssetService.Get(eyesTextureId.ToString());
  160. Assert.That(eyesBake, Is.Not.Null);
  161. Assert.That(eyesBake.Temporary, Is.False);
  162. Assert.That(eyesBake.Local, Is.False);
  163. }
  164. }
  165. }