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