OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AvatarFactoryModuleTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using Nini.Config;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Region.CoreModules.Asset;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Tests.Common;
37 
38 namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
39 {
40  [TestFixture]
42  {
46  [Test]
47  public void TestSetAppearance()
48  {
49  TestHelpers.InMethod();
50 // TestHelpers.EnableLogging();
51 
52  UUID userId = TestHelpers.ParseTail(0x1);
53  UUID bakedTextureID = TestHelpers.ParseTail(0x2);
54 
55  // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
56  // to the AssetService, which will then store temporary and local assets permanently
57  CoreAssetCache assetCache = new CoreAssetCache();
58 
60  TestScene scene = new SceneHelpers(assetCache).SetupScene();
61  SceneHelpers.SetupSceneModules(scene, afm);
62  ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
63 
64  // TODO: Use the actual BunchOfCaps functionality once we slot in the CapabilitiesModules
65  AssetBase bakedTextureAsset;
66  bakedTextureAsset
67  = new AssetBase(
68  bakedTextureID, "Test Baked Texture", (sbyte)AssetType.Texture, userId.ToString());
69  bakedTextureAsset.Data = new byte[] { 2 }; // Not necessary to have a genuine JPEG2000 asset here yet
70  bakedTextureAsset.Temporary = true;
71  bakedTextureAsset.Local = true;
72  scene.AssetService.Store(bakedTextureAsset);
73 
74  byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
75  for (byte i = 0; i < visualParams.Length; i++)
76  visualParams[i] = i;
77 
78  Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
79  uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
80  Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
81 
82  int rebakeRequestsReceived = 0;
83  ((TestClient)sp.ControllingClient).OnReceivedSendRebakeAvatarTextures += id => rebakeRequestsReceived++;
84 
85  // This is the alpha texture
86  eyesFace.TextureID = bakedTextureID;
87  afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
88 
89  Assert.That(rebakeRequestsReceived, Is.EqualTo(0));
90 
91  AssetBase eyesBake = scene.AssetService.Get(bakedTextureID.ToString());
92  Assert.That(eyesBake, Is.Not.Null);
93  Assert.That(eyesBake.Temporary, Is.True);
94  Assert.That(eyesBake.Local, Is.True);
95  }
96 
104  [Test]
106  {
107  TestHelpers.InMethod();
108 // TestHelpers.EnableLogging();
109 
110  UUID userId = TestHelpers.ParseTail(0x1);
111  UUID alphaTextureID = new UUID("3a367d1c-bef1-6d43-7595-e88c1e3aadb3");
112 
113  // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
114  // to the AssetService, which will then store temporary and local assets permanently
115  CoreAssetCache assetCache = new CoreAssetCache();
116 
118  TestScene scene = new SceneHelpers(assetCache).SetupScene();
119  SceneHelpers.SetupSceneModules(scene, afm);
120  ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
121 
122  AssetBase libraryAsset;
123  libraryAsset
124  = new AssetBase(
125  alphaTextureID, "Default Alpha Layer Texture", (sbyte)AssetType.Texture, userId.ToString());
126  libraryAsset.Data = new byte[] { 2 }; // Not necessary to have a genuine JPEG2000 asset here yet
127  libraryAsset.Temporary = false;
128  libraryAsset.Local = false;
129  scene.AssetService.Store(libraryAsset);
130 
131  byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
132  for (byte i = 0; i < visualParams.Length; i++)
133  visualParams[i] = i;
134 
135  Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
136  uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
137  Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
138 
139  int rebakeRequestsReceived = 0;
140  ((TestClient)sp.ControllingClient).OnReceivedSendRebakeAvatarTextures += id => rebakeRequestsReceived++;
141 
142  // This is the alpha texture
143  eyesFace.TextureID = alphaTextureID;
144  afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
145 
146  Assert.That(rebakeRequestsReceived, Is.EqualTo(0));
147  }
148 
149  [Test]
150  public void TestSaveBakedTextures()
151  {
152  TestHelpers.InMethod();
153 // log4net.Config.XmlConfigurator.Configure();
154 
155  UUID userId = TestHelpers.ParseTail(0x1);
156  UUID eyesTextureId = TestHelpers.ParseTail(0x2);
157 
158  // We need an asset cache because otherwise the LocalAssetServiceConnector will short-circuit directly
159  // to the AssetService, which will then store temporary and local assets permanently
160  CoreAssetCache assetCache = new CoreAssetCache();
161 
163  TestScene scene = new SceneHelpers(assetCache).SetupScene();
164  SceneHelpers.SetupSceneModules(scene, afm);
165  ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);
166 
167  // TODO: Use the actual BunchOfCaps functionality once we slot in the CapabilitiesModules
168  AssetBase uploadedAsset;
169  uploadedAsset = new AssetBase(eyesTextureId, "Baked Texture", (sbyte)AssetType.Texture, userId.ToString());
170  uploadedAsset.Data = new byte[] { 2 };
171  uploadedAsset.Temporary = true;
172  uploadedAsset.Local = true; // Local assets aren't persisted, non-local are
173  scene.AssetService.Store(uploadedAsset);
174 
175  byte[] visualParams = new byte[AvatarAppearance.VISUALPARAM_COUNT];
176  for (byte i = 0; i < visualParams.Length; i++)
177  visualParams[i] = i;
178 
179  Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
180  uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
181  Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
182  eyesFace.TextureID = eyesTextureId;
183 
184  afm.SetAppearance(sp, bakedTextureEntry, visualParams, new WearableCacheItem[0]);
185  afm.SaveBakedTextures(userId);
186 // Dictionary<BakeType, Primitive.TextureEntryFace> bakedTextures = afm.GetBakedTextureFaces(userId);
187 
188  // We should also inpsect the asset data store layer directly, but this is difficult to get at right now.
189  assetCache.Clear();
190 
191  AssetBase eyesBake = scene.AssetService.Get(eyesTextureId.ToString());
192  Assert.That(eyesBake, Is.Not.Null);
193  Assert.That(eyesBake.Temporary, Is.False);
194  Assert.That(eyesBake.Local, Is.False);
195  }
196  }
197 }
void TestSetAppearance()
Only partial right now since we don't yet test that it's ended up in the avatar appearance service...
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
void TestSetAppearanceAlphaBakedTextures()
Test appearance setting where the baked texture UUID are library alpha textures.
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60