OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
InventoryTransferModuleTests.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 System.Reflection;
31 using log4net.Config;
32 using Nini.Config;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenMetaverse.Assets;
36 using OpenSim.Framework;
37 using OpenSim.Region.CoreModules.Avatar.Inventory.Transfer;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Services.Interfaces;
41 using OpenSim.Tests.Common;
42 
43 namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer.Tests
44 {
45  [TestFixture]
47  {
48  protected TestScene m_scene;
49 
50  [SetUp]
51  public override void SetUp()
52  {
53  base.SetUp();
54 
55  IConfigSource config = new IniConfigSource();
56  config.AddConfig("Messaging");
57  config.Configs["Messaging"].Set("InventoryTransferModule", "InventoryTransferModule");
58 
59  m_scene = new SceneHelpers().SetupScene();
60  SceneHelpers.SetupSceneModules(m_scene, config, new InventoryTransferModule());
61  }
62 
63  [Test]
64  public void TestAcceptGivenItem()
65  {
66 // TestHelpers.EnableLogging();
67 
68  UUID initialSessionId = TestHelpers.ParseTail(0x10);
69  UUID itemId = TestHelpers.ParseTail(0x100);
70  UUID assetId = TestHelpers.ParseTail(0x200);
71 
72  UserAccount ua1
73  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
74  UserAccount ua2
75  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
76 
77  ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
78  TestClient giverClient = (TestClient)giverSp.ControllingClient;
79 
80  ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
81  TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
82 
83  // Create the object to test give
84  InventoryItemBase originalItem
85  = UserInventoryHelpers.CreateInventoryItem(
86  m_scene, "givenObj", itemId, assetId, giverSp.UUID, InventoryType.Object);
87 
88  byte[] giveImBinaryBucket = new byte[17];
89  byte[] itemIdBytes = itemId.GetBytes();
90  Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
91 
92  GridInstantMessage giveIm
93  = new GridInstantMessage(
94  m_scene,
95  giverSp.UUID,
96  giverSp.Name,
97  receiverSp.UUID,
98  (byte)InstantMessageDialog.InventoryOffered,
99  false,
100  "inventory offered msg",
101  initialSessionId,
102  false,
103  Vector3.Zero,
104  giveImBinaryBucket,
105  true);
106 
107  giverClient.HandleImprovedInstantMessage(giveIm);
108 
109  // These details might not all be correct.
110  GridInstantMessage acceptIm
111  = new GridInstantMessage(
112  m_scene,
113  receiverSp.UUID,
114  receiverSp.Name,
115  giverSp.UUID,
116  (byte)InstantMessageDialog.InventoryAccepted,
117  false,
118  "inventory accepted msg",
119  initialSessionId,
120  false,
121  Vector3.Zero,
122  null,
123  true);
124 
125  receiverClient.HandleImprovedInstantMessage(acceptIm);
126 
127  // Test for item remaining in the giver's inventory (here we assume a copy item)
128  // TODO: Test no-copy items.
129  InventoryItemBase originalItemAfterGive
130  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, giverSp.UUID, "Objects/givenObj");
131 
132  Assert.That(originalItemAfterGive, Is.Not.Null);
133  Assert.That(originalItemAfterGive.ID, Is.EqualTo(originalItem.ID));
134 
135  // Test for item successfully making it into the receiver's inventory
136  InventoryItemBase receivedItem
137  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, receiverSp.UUID, "Objects/givenObj");
138 
139  Assert.That(receivedItem, Is.Not.Null);
140  Assert.That(receivedItem.ID, Is.Not.EqualTo(originalItem.ID));
141 
142  // Test that on a delete, item still exists and is accessible for the giver.
143  m_scene.InventoryService.DeleteItems(receiverSp.UUID, new List<UUID>() { receivedItem.ID });
144 
145  InventoryItemBase originalItemAfterDelete
146  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, giverSp.UUID, "Objects/givenObj");
147 
148  Assert.That(originalItemAfterDelete, Is.Not.Null);
149 
150  // TODO: Test scenario where giver deletes their item first.
151  }
152 
159  [Test]
160  public void TestRejectGivenItem()
161  {
162 // TestHelpers.EnableLogging();
163 
164  UUID initialSessionId = TestHelpers.ParseTail(0x10);
165  UUID itemId = TestHelpers.ParseTail(0x100);
166  UUID assetId = TestHelpers.ParseTail(0x200);
167 
168  UserAccount ua1
169  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
170  UserAccount ua2
171  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
172 
173  ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
174  TestClient giverClient = (TestClient)giverSp.ControllingClient;
175 
176  ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
177  TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
178 
179  // Create the object to test give
180  InventoryItemBase originalItem
181  = UserInventoryHelpers.CreateInventoryItem(
182  m_scene, "givenObj", itemId, assetId, giverSp.UUID, InventoryType.Object);
183 
184  GridInstantMessage receivedIm = null;
185  receiverClient.OnReceivedInstantMessage += im => receivedIm = im;
186 
187  byte[] giveImBinaryBucket = new byte[17];
188  byte[] itemIdBytes = itemId.GetBytes();
189  Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
190 
191  GridInstantMessage giveIm
192  = new GridInstantMessage(
193  m_scene,
194  giverSp.UUID,
195  giverSp.Name,
196  receiverSp.UUID,
197  (byte)InstantMessageDialog.InventoryOffered,
198  false,
199  "inventory offered msg",
200  initialSessionId,
201  false,
202  Vector3.Zero,
203  giveImBinaryBucket,
204  true);
205 
206  giverClient.HandleImprovedInstantMessage(giveIm);
207 
208  // These details might not all be correct.
209  // Session ID is now the created item ID (!)
210  GridInstantMessage rejectIm
211  = new GridInstantMessage(
212  m_scene,
213  receiverSp.UUID,
214  receiverSp.Name,
215  giverSp.UUID,
216  (byte)InstantMessageDialog.InventoryDeclined,
217  false,
218  "inventory declined msg",
219  new UUID(receivedIm.imSessionID),
220  false,
221  Vector3.Zero,
222  null,
223  true);
224 
225  receiverClient.HandleImprovedInstantMessage(rejectIm);
226 
227  // Test for item remaining in the giver's inventory (here we assume a copy item)
228  // TODO: Test no-copy items.
229  InventoryItemBase originalItemAfterGive
230  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, giverSp.UUID, "Objects/givenObj");
231 
232  Assert.That(originalItemAfterGive, Is.Not.Null);
233  Assert.That(originalItemAfterGive.ID, Is.EqualTo(originalItem.ID));
234 
235  // Test for item successfully making it into the receiver's inventory
236  InventoryItemBase receivedItem
237  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, receiverSp.UUID, "Trash/givenObj");
238 
239  InventoryFolderBase trashFolder
240  = m_scene.InventoryService.GetFolderForType(receiverSp.UUID, FolderType.Trash);
241 
242  Assert.That(receivedItem, Is.Not.Null);
243  Assert.That(receivedItem.ID, Is.Not.EqualTo(originalItem.ID));
244  Assert.That(receivedItem.Folder, Is.EqualTo(trashFolder.ID));
245 
246  // Test that on a delete, item still exists and is accessible for the giver.
247  m_scene.InventoryService.PurgeFolder(trashFolder);
248 
249  InventoryItemBase originalItemAfterDelete
250  = UserInventoryHelpers.GetInventoryItem(m_scene.InventoryService, giverSp.UUID, "Objects/givenObj");
251 
252  Assert.That(originalItemAfterDelete, Is.Not.Null);
253  }
254 
255  [Test]
256  public void TestAcceptGivenFolder()
257  {
258  TestHelpers.InMethod();
259 // TestHelpers.EnableLogging();
260 
261  UUID initialSessionId = TestHelpers.ParseTail(0x10);
262  UUID folderId = TestHelpers.ParseTail(0x100);
263 
264  UserAccount ua1
265  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
266  UserAccount ua2
267  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
268 
269  ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
270  TestClient giverClient = (TestClient)giverSp.ControllingClient;
271 
272  ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
273  TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
274 
275  InventoryFolderBase originalFolder
276  = UserInventoryHelpers.CreateInventoryFolder(
277  m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
278 
279  byte[] giveImBinaryBucket = new byte[17];
280  giveImBinaryBucket[0] = (byte)AssetType.Folder;
281  byte[] itemIdBytes = folderId.GetBytes();
282  Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
283 
284  GridInstantMessage giveIm
285  = new GridInstantMessage(
286  m_scene,
287  giverSp.UUID,
288  giverSp.Name,
289  receiverSp.UUID,
290  (byte)InstantMessageDialog.InventoryOffered,
291  false,
292  "inventory offered msg",
293  initialSessionId,
294  false,
295  Vector3.Zero,
296  giveImBinaryBucket,
297  true);
298 
299  giverClient.HandleImprovedInstantMessage(giveIm);
300 
301  // These details might not all be correct.
302  GridInstantMessage acceptIm
303  = new GridInstantMessage(
304  m_scene,
305  receiverSp.UUID,
306  receiverSp.Name,
307  giverSp.UUID,
308  (byte)InstantMessageDialog.InventoryAccepted,
309  false,
310  "inventory accepted msg",
311  initialSessionId,
312  false,
313  Vector3.Zero,
314  null,
315  true);
316 
317  receiverClient.HandleImprovedInstantMessage(acceptIm);
318 
319  // Test for item remaining in the giver's inventory (here we assume a copy item)
320  // TODO: Test no-copy items.
321  InventoryFolderBase originalFolderAfterGive
322  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
323 
324  Assert.That(originalFolderAfterGive, Is.Not.Null);
325  Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
326 
327  // Test for item successfully making it into the receiver's inventory
328  InventoryFolderBase receivedFolder
329  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "f1");
330 
331  Assert.That(receivedFolder, Is.Not.Null);
332  Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
333 
334  // Test that on a delete, item still exists and is accessible for the giver.
335  m_scene.InventoryService.DeleteFolders(receiverSp.UUID, new List<UUID>() { receivedFolder.ID });
336 
337  InventoryFolderBase originalFolderAfterDelete
338  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
339 
340  Assert.That(originalFolderAfterDelete, Is.Not.Null);
341 
342  // TODO: Test scenario where giver deletes their item first.
343  }
344 
351  [Test]
352  public void TestRejectGivenFolder()
353  {
354  TestHelpers.InMethod();
355 // TestHelpers.EnableLogging();
356 
357  UUID initialSessionId = TestHelpers.ParseTail(0x10);
358  UUID folderId = TestHelpers.ParseTail(0x100);
359 
360  UserAccount ua1
361  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "One", TestHelpers.ParseTail(0x1), "pw");
362  UserAccount ua2
363  = UserAccountHelpers.CreateUserWithInventory(m_scene, "User", "Two", TestHelpers.ParseTail(0x2), "pw");
364 
365  ScenePresence giverSp = SceneHelpers.AddScenePresence(m_scene, ua1);
366  TestClient giverClient = (TestClient)giverSp.ControllingClient;
367 
368  ScenePresence receiverSp = SceneHelpers.AddScenePresence(m_scene, ua2);
369  TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
370 
371  // Create the folder to test give
372  InventoryFolderBase originalFolder
373  = UserInventoryHelpers.CreateInventoryFolder(
374  m_scene.InventoryService, giverSp.UUID, folderId, "f1", true);
375 
376  GridInstantMessage receivedIm = null;
377  receiverClient.OnReceivedInstantMessage += im => receivedIm = im;
378 
379  byte[] giveImBinaryBucket = new byte[17];
380  giveImBinaryBucket[0] = (byte)AssetType.Folder;
381  byte[] itemIdBytes = folderId.GetBytes();
382  Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
383 
384  GridInstantMessage giveIm
385  = new GridInstantMessage(
386  m_scene,
387  giverSp.UUID,
388  giverSp.Name,
389  receiverSp.UUID,
390  (byte)InstantMessageDialog.InventoryOffered,
391  false,
392  "inventory offered msg",
393  initialSessionId,
394  false,
395  Vector3.Zero,
396  giveImBinaryBucket,
397  true);
398 
399  giverClient.HandleImprovedInstantMessage(giveIm);
400 
401  // These details might not all be correct.
402  // Session ID is now the created item ID (!)
403  GridInstantMessage rejectIm
404  = new GridInstantMessage(
405  m_scene,
406  receiverSp.UUID,
407  receiverSp.Name,
408  giverSp.UUID,
409  (byte)InstantMessageDialog.InventoryDeclined,
410  false,
411  "inventory declined msg",
412  new UUID(receivedIm.imSessionID),
413  false,
414  Vector3.Zero,
415  null,
416  true);
417 
418  receiverClient.HandleImprovedInstantMessage(rejectIm);
419 
420  // Test for item remaining in the giver's inventory (here we assume a copy item)
421  // TODO: Test no-copy items.
422  InventoryFolderBase originalFolderAfterGive
423  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
424 
425  Assert.That(originalFolderAfterGive, Is.Not.Null);
426  Assert.That(originalFolderAfterGive.ID, Is.EqualTo(originalFolder.ID));
427 
428  // Test for folder successfully making it into the receiver's inventory
429  InventoryFolderBase receivedFolder
430  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, receiverSp.UUID, "Trash/f1");
431 
432  InventoryFolderBase trashFolder
433  = m_scene.InventoryService.GetFolderForType(receiverSp.UUID, FolderType.Trash);
434 
435  Assert.That(receivedFolder, Is.Not.Null);
436  Assert.That(receivedFolder.ID, Is.Not.EqualTo(originalFolder.ID));
437  Assert.That(receivedFolder.ParentID, Is.EqualTo(trashFolder.ID));
438 
439  // Test that on a delete, item still exists and is accessible for the giver.
440  m_scene.InventoryService.PurgeFolder(trashFolder);
441 
442  InventoryFolderBase originalFolderAfterDelete
443  = UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, giverSp.UUID, "f1");
444 
445  Assert.That(originalFolderAfterDelete, Is.Not.Null);
446  }
447  }
448 }
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55
static ScenePresence AddScenePresence(Scene scene, UUID agentId)
Add a root agent where the details of the agent connection (apart from the id) are unimportant for th...
virtual string Name
The name of this entity
Definition: EntityBase.cs:65