diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs new file mode 100644 index 0000000..363e258 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -0,0 +1,274 @@ | |||
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 System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
41 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Region.Framework.Scenes; | ||
45 | using OpenSim.Region.Framework.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// Attachment tests | ||
53 | /// </summary> | ||
54 | [TestFixture] | ||
55 | public class AttachmentsModuleTests | ||
56 | { | ||
57 | private Scene scene; | ||
58 | private AttachmentsModule m_attMod; | ||
59 | private ScenePresence m_presence; | ||
60 | |||
61 | [SetUp] | ||
62 | public void Init() | ||
63 | { | ||
64 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
65 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
66 | |||
67 | IConfigSource config = new IniConfigSource(); | ||
68 | config.AddConfig("Modules"); | ||
69 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
70 | |||
71 | scene = SceneHelpers.SetupScene(); | ||
72 | m_attMod = new AttachmentsModule(); | ||
73 | SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule()); | ||
74 | } | ||
75 | |||
76 | [TearDown] | ||
77 | public void TearDown() | ||
78 | { | ||
79 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
80 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
81 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// Add the standard presence for a test. | ||
86 | /// </summary> | ||
87 | private void AddPresence() | ||
88 | { | ||
89 | UUID userId = TestHelpers.ParseTail(0x1); | ||
90 | UserAccountHelpers.CreateUserWithInventory(scene, userId); | ||
91 | m_presence = SceneHelpers.AddScenePresence(scene, userId); | ||
92 | } | ||
93 | |||
94 | [Test] | ||
95 | public void TestAddAttachmentFromGround() | ||
96 | { | ||
97 | TestHelpers.InMethod(); | ||
98 | // log4net.Config.XmlConfigurator.Configure(); | ||
99 | |||
100 | AddPresence(); | ||
101 | string attName = "att"; | ||
102 | |||
103 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; | ||
104 | |||
105 | m_attMod.AttachObject(m_presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false); | ||
106 | |||
107 | // Check status on scene presence | ||
108 | Assert.That(m_presence.HasAttachments(), Is.True); | ||
109 | List<SceneObjectGroup> attachments = m_presence.GetAttachments(); | ||
110 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
111 | SceneObjectGroup attSo = attachments[0]; | ||
112 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
113 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
114 | Assert.That(attSo.IsAttachment); | ||
115 | Assert.That(attSo.UsesPhysics, Is.False); | ||
116 | Assert.That(attSo.IsTemporary, Is.False); | ||
117 | |||
118 | // Check item status | ||
119 | Assert.That(m_presence.Appearance.GetAttachpoint( | ||
120 | attSo.GetFromItemID()), Is.EqualTo((int)AttachmentPoint.Chest)); | ||
121 | } | ||
122 | |||
123 | [Test] | ||
124 | public void TestAddAttachmentFromInventory() | ||
125 | { | ||
126 | TestHelpers.InMethod(); | ||
127 | // log4net.Config.XmlConfigurator.Configure(); | ||
128 | |||
129 | AddPresence(); | ||
130 | |||
131 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
132 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
133 | string attName = "att"; | ||
134 | |||
135 | UserInventoryHelpers.CreateInventoryItem( | ||
136 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
137 | |||
138 | m_attMod.RezSingleAttachmentFromInventory( | ||
139 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
140 | |||
141 | // Check scene presence status | ||
142 | Assert.That(m_presence.HasAttachments(), Is.True); | ||
143 | List<SceneObjectGroup> attachments = m_presence.GetAttachments(); | ||
144 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
145 | SceneObjectGroup attSo = attachments[0]; | ||
146 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
147 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
148 | Assert.That(attSo.IsAttachment); | ||
149 | Assert.That(attSo.UsesPhysics, Is.False); | ||
150 | Assert.That(attSo.IsTemporary, Is.False); | ||
151 | |||
152 | // Check appearance status | ||
153 | Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); | ||
154 | } | ||
155 | |||
156 | [Test] | ||
157 | public void TestDetachAttachmentToGround() | ||
158 | { | ||
159 | TestHelpers.InMethod(); | ||
160 | // log4net.Config.XmlConfigurator.Configure(); | ||
161 | |||
162 | AddPresence(); | ||
163 | |||
164 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
165 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
166 | string attName = "att"; | ||
167 | |||
168 | UserInventoryHelpers.CreateInventoryItem( | ||
169 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
170 | |||
171 | ISceneEntity so = m_attMod.RezSingleAttachmentFromInventory( | ||
172 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
173 | m_attMod.DetachSingleAttachmentToGround(so.LocalId, m_presence.ControllingClient); | ||
174 | |||
175 | // Check scene presence status | ||
176 | Assert.That(m_presence.HasAttachments(), Is.False); | ||
177 | List<SceneObjectGroup> attachments = m_presence.GetAttachments(); | ||
178 | Assert.That(attachments.Count, Is.EqualTo(0)); | ||
179 | |||
180 | // Check appearance status | ||
181 | Assert.That(m_presence.Appearance.GetAttachments().Count, Is.EqualTo(0)); | ||
182 | |||
183 | // Check item status | ||
184 | Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null); | ||
185 | |||
186 | // Check object in scene | ||
187 | Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null); | ||
188 | } | ||
189 | |||
190 | [Test] | ||
191 | public void TestDetachAttachmentToInventory() | ||
192 | { | ||
193 | TestHelpers.InMethod(); | ||
194 | // log4net.Config.XmlConfigurator.Configure(); | ||
195 | |||
196 | AddPresence(); | ||
197 | |||
198 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
199 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
200 | string attName = "att"; | ||
201 | |||
202 | UserInventoryHelpers.CreateInventoryItem( | ||
203 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
204 | |||
205 | m_attMod.RezSingleAttachmentFromInventory( | ||
206 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
207 | m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient); | ||
208 | |||
209 | // Check status on scene presence | ||
210 | Assert.That(m_presence.HasAttachments(), Is.False); | ||
211 | List<SceneObjectGroup> attachments = m_presence.GetAttachments(); | ||
212 | Assert.That(attachments.Count, Is.EqualTo(0)); | ||
213 | |||
214 | // Check item status | ||
215 | Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo(0)); | ||
216 | } | ||
217 | |||
218 | [Test] | ||
219 | public void TestRezAttachmentsOnAvatarEntrance() | ||
220 | { | ||
221 | TestHelpers.InMethod(); | ||
222 | // log4net.Config.XmlConfigurator.Configure(); | ||
223 | |||
224 | UUID userId = TestHelpers.ParseTail(0x1); | ||
225 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
226 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
227 | string attName = "att"; | ||
228 | |||
229 | UserAccountHelpers.CreateUserWithInventory(scene, userId); | ||
230 | InventoryItemBase attItem | ||
231 | = UserInventoryHelpers.CreateInventoryItem( | ||
232 | scene, attName, attItemId, attAssetId, userId, InventoryType.Object); | ||
233 | |||
234 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
235 | acd.Appearance = new AvatarAppearance(); | ||
236 | acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID); | ||
237 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd); | ||
238 | |||
239 | Assert.That(presence.HasAttachments(), Is.True); | ||
240 | List<SceneObjectGroup> attachments = presence.GetAttachments(); | ||
241 | |||
242 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
243 | SceneObjectGroup attSo = attachments[0]; | ||
244 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
245 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
246 | Assert.That(attSo.IsAttachment); | ||
247 | Assert.That(attSo.UsesPhysics, Is.False); | ||
248 | Assert.That(attSo.IsTemporary, Is.False); | ||
249 | } | ||
250 | |||
251 | // I'm commenting this test because scene setup NEEDS InventoryService to | ||
252 | // be non-null | ||
253 | //[Test] | ||
254 | // public void T032_CrossAttachments() | ||
255 | // { | ||
256 | // TestHelpers.InMethod(); | ||
257 | // | ||
258 | // ScenePresence presence = scene.GetScenePresence(agent1); | ||
259 | // ScenePresence presence2 = scene2.GetScenePresence(agent1); | ||
260 | // presence2.AddAttachment(sog1); | ||
261 | // presence2.AddAttachment(sog2); | ||
262 | // | ||
263 | // ISharedRegionModule serialiser = new SerialiserModule(); | ||
264 | // SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser); | ||
265 | // SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser); | ||
266 | // | ||
267 | // Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross"); | ||
268 | // | ||
269 | // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); | ||
270 | // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); | ||
271 | // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); | ||
272 | // } | ||
273 | } | ||
274 | } \ No newline at end of file | ||