clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
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 System.IO;
31 using System.Reflection;
32 using System.Threading;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenSim.Data;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Serialization;
38 using OpenSim.Framework.Serialization.External;
39 using OpenSim.Framework.Communications;
40 using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
41 using OpenSim.Region.CoreModules.World.Serialiser;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Region.Framework.Scenes.Serialization;
44 using OpenSim.Services.Interfaces;
45 using OpenSim.Tests.Common;
46 using OpenSim.Tests.Common.Mock;
47  
48 namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
49 {
50 [TestFixture]
51 public class InventoryArchiveLoadPathTests : InventoryArchiveTestCase
52 {
53 /// <summary>
54 /// Test loading an IAR to various different inventory paths.
55 /// </summary>
56 [Test]
57 public void TestLoadIarToInventoryPaths()
58 {
59 TestHelpers.InMethod();
60 // log4net.Config.XmlConfigurator.Configure();
61  
62 SerialiserModule serialiserModule = new SerialiserModule();
63 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
64  
65 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
66 Scene scene = new SceneHelpers().SetupScene();
67  
68 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
69  
70 UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "meowfood");
71 UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire");
72  
73 archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/", m_iarStream);
74 InventoryItemBase foundItem1
75 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, m_item1Name);
76  
77 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
78  
79 // Now try loading to a root child folder
80 UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xA", false);
81 MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray());
82 archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xA", archiveReadStream);
83  
84 InventoryItemBase foundItem2
85 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xA/" + m_item1Name);
86 Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");
87  
88 // Now try loading to a more deeply nested folder
89 UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC", false);
90 archiveReadStream = new MemoryStream(archiveReadStream.ToArray());
91 archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", archiveReadStream);
92  
93 InventoryItemBase foundItem3
94 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC/" + m_item1Name);
95 Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
96 }
97  
98 /// <summary>
99 /// Test that things work when the load path specified starts with a slash
100 /// </summary>
101 [Test]
102 public void TestLoadIarPathStartsWithSlash()
103 {
104 TestHelpers.InMethod();
105 // log4net.Config.XmlConfigurator.Configure();
106  
107 SerialiserModule serialiserModule = new SerialiserModule();
108 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
109 Scene scene = new SceneHelpers().SetupScene();
110 SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
111  
112 UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "password");
113 archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/Objects", m_iarStream);
114  
115 InventoryItemBase foundItem1
116 = InventoryArchiveUtils.FindItemByPath(
117 scene.InventoryService, m_uaMT.PrincipalID, "/Objects/" + m_item1Name);
118  
119 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()");
120 }
121  
122 [Test]
123 public void TestLoadIarPathWithEscapedChars()
124 {
125 TestHelpers.InMethod();
126 // log4net.Config.XmlConfigurator.Configure();
127  
128 string itemName = "You & you are a mean/man/";
129 string humanEscapedItemName = @"You & you are a mean\/man\/";
130 string userPassword = "meowfood";
131  
132 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
133  
134 Scene scene = new SceneHelpers().SetupScene();
135 SceneHelpers.SetupSceneModules(scene, archiverModule);
136  
137 // Create user
138 string userFirstName = "Jock";
139 string userLastName = "Stirrup";
140 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
141 UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");
142  
143 // Create asset
144 SceneObjectGroup object1;
145 SceneObjectPart part1;
146 {
147 string partName = "part name";
148 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
149 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
150 Vector3 groupPosition = new Vector3(10, 20, 30);
151 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
152 Vector3 offsetPosition = new Vector3(5, 10, 15);
153  
154 part1
155 = new SceneObjectPart(
156 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
157 part1.Name = partName;
158  
159 object1 = new SceneObjectGroup(part1);
160 scene.AddNewSceneObject(object1, false);
161 }
162  
163 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
164 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
165 scene.AssetService.Store(asset1);
166  
167 // Create item
168 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
169 InventoryItemBase item1 = new InventoryItemBase();
170 item1.Name = itemName;
171 item1.AssetID = asset1.FullID;
172 item1.ID = item1Id;
173 InventoryFolderBase objsFolder
174 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, "Objects")[0];
175 item1.Folder = objsFolder.ID;
176 scene.AddInventoryItem(item1);
177  
178 MemoryStream archiveWriteStream = new MemoryStream();
179 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
180  
181 mre.Reset();
182 archiverModule.ArchiveInventory(
183 UUID.Random(), userFirstName, userLastName, "Objects", archiveWriteStream);
184 mre.WaitOne(60000, false);
185  
186 // LOAD ITEM
187 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
188  
189 archiverModule.DearchiveInventory(UUID.Random(), userFirstName, userLastName, "Scripts", archiveReadStream);
190  
191 InventoryItemBase foundItem1
192 = InventoryArchiveUtils.FindItemByPath(
193 scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);
194  
195 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
196 // Assert.That(
197 // foundItem1.CreatorId, Is.EqualTo(userUuid),
198 // "Loaded item non-uuid creator doesn't match that of the loading user");
199 Assert.That(
200 foundItem1.Name, Is.EqualTo(itemName),
201 "Loaded item name doesn't match saved name");
202 }
203  
204 /// <summary>
205 /// Test replication of an archive path to the user's inventory.
206 /// </summary>
207 [Test]
208 public void TestNewIarPath()
209 {
210 TestHelpers.InMethod();
211 // log4net.Config.XmlConfigurator.Configure();
212  
213 Scene scene = new SceneHelpers().SetupScene();
214 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
215  
216 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
217 HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>();
218  
219 string folder1Name = "1";
220 string folder2aName = "2a";
221 string folder2bName = "2b";
222  
223 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random());
224 string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random());
225 string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random());
226  
227 string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName });
228 string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName });
229  
230 {
231 // Test replication of path1
232 new InventoryArchiveReadRequest(UUID.Random(), scene.InventoryService, null, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
233 .ReplicateArchivePathToUserInventory(
234 iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
235 foldersCreated, nodesLoaded);
236  
237 List<InventoryFolderBase> folder1Candidates
238 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
239 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
240  
241 InventoryFolderBase folder1 = folder1Candidates[0];
242 List<InventoryFolderBase> folder2aCandidates
243 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
244 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
245 }
246  
247 {
248 // Test replication of path2
249 new InventoryArchiveReadRequest(UUID.Random(), scene.InventoryService, null, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
250 .ReplicateArchivePathToUserInventory(
251 iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
252 foldersCreated, nodesLoaded);
253  
254 List<InventoryFolderBase> folder1Candidates
255 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
256 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
257  
258 InventoryFolderBase folder1 = folder1Candidates[0];
259  
260 List<InventoryFolderBase> folder2aCandidates
261 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
262 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
263  
264 List<InventoryFolderBase> folder2bCandidates
265 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2bName);
266 Assert.That(folder2bCandidates.Count, Is.EqualTo(1));
267 }
268 }
269  
270 /// <summary>
271 /// Test replication of a partly existing archive path to the user's inventory. This should create
272 /// a duplicate path without the merge option.
273 /// </summary>
274 [Test]
275 public void TestPartExistingIarPath()
276 {
277 TestHelpers.InMethod();
278 //log4net.Config.XmlConfigurator.Configure();
279  
280 Scene scene = new SceneHelpers().SetupScene();
281 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
282  
283 string folder1ExistingName = "a";
284 string folder2Name = "b";
285  
286 InventoryFolderBase folder1
287 = UserInventoryHelpers.CreateInventoryFolder(
288 scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
289  
290 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
291 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
292  
293 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
294  
295 new InventoryArchiveReadRequest(UUID.Random(), scene.InventoryService, null, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
296 .ReplicateArchivePathToUserInventory(
297 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
298 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
299  
300 List<InventoryFolderBase> folder1PostCandidates
301 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
302 Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));
303  
304 // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
305 InventoryFolderBase folder1Post = null;
306 foreach (InventoryFolderBase folder in folder1PostCandidates)
307 {
308 if (folder.ID != folder1.ID)
309 {
310 folder1Post = folder;
311 break;
312 }
313 }
314 // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
315  
316 List<InventoryFolderBase> folder2PostCandidates
317 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1Post, "b");
318 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
319 }
320  
321 /// <summary>
322 /// Test replication of a partly existing archive path to the user's inventory. This should create
323 /// a merged path.
324 /// </summary>
325 [Test]
326 public void TestMergeIarPath()
327 {
328 TestHelpers.InMethod();
329 // log4net.Config.XmlConfigurator.Configure();
330  
331 Scene scene = new SceneHelpers().SetupScene();
332 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
333  
334 string folder1ExistingName = "a";
335 string folder2Name = "b";
336  
337 InventoryFolderBase folder1
338 = UserInventoryHelpers.CreateInventoryFolder(
339 scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
340  
341 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
342 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
343  
344 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
345  
346 new InventoryArchiveReadRequest(UUID.Random(), scene.InventoryService, null, scene.AssetService, scene.UserAccountService, ua1, folder1ExistingName, (Stream)null, true)
347 .ReplicateArchivePathToUserInventory(
348 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
349 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
350  
351 List<InventoryFolderBase> folder1PostCandidates
352 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
353 Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
354 Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));
355  
356 List<InventoryFolderBase> folder2PostCandidates
357 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1PostCandidates[0], "b");
358 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
359 }
360 }
361 }
362