clockwerk-opensim-stable – Blame information for rev 3

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  
3 vero 73 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", m_iarStream);
1 vero 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());
3 vero 82 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xA", archiveReadStream);
1 vero 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());
3 vero 91 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", archiveReadStream);
1 vero 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");
3 vero 113 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/Objects", m_iarStream);
1 vero 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  
131 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
132  
133 Scene scene = new SceneHelpers().SetupScene();
134 SceneHelpers.SetupSceneModules(scene, archiverModule);
135  
136 // Create user
137 string userFirstName = "Jock";
138 string userLastName = "Stirrup";
139 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
140 UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");
141  
142 // Create asset
143 SceneObjectGroup object1;
144 SceneObjectPart part1;
145 {
146 string partName = "part name";
147 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
148 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
149 Vector3 groupPosition = new Vector3(10, 20, 30);
150 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
151 Vector3 offsetPosition = new Vector3(5, 10, 15);
152  
153 part1
154 = new SceneObjectPart(
155 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
156 part1.Name = partName;
157  
158 object1 = new SceneObjectGroup(part1);
159 scene.AddNewSceneObject(object1, false);
160 }
161  
162 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
163 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
164 scene.AssetService.Store(asset1);
165  
166 // Create item
167 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
168 InventoryItemBase item1 = new InventoryItemBase();
169 item1.Name = itemName;
170 item1.AssetID = asset1.FullID;
171 item1.ID = item1Id;
172 InventoryFolderBase objsFolder
173 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, "Objects")[0];
174 item1.Folder = objsFolder.ID;
175 scene.AddInventoryItem(item1);
176  
177 MemoryStream archiveWriteStream = new MemoryStream();
178 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
179  
180 mre.Reset();
181 archiverModule.ArchiveInventory(
3 vero 182 Guid.NewGuid(), userFirstName, userLastName, "Objects", archiveWriteStream);
1 vero 183 mre.WaitOne(60000, false);
184  
185 // LOAD ITEM
186 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
187  
3 vero 188 archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", archiveReadStream);
1 vero 189  
190 InventoryItemBase foundItem1
191 = InventoryArchiveUtils.FindItemByPath(
192 scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);
193  
194 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
195 // Assert.That(
196 // foundItem1.CreatorId, Is.EqualTo(userUuid),
197 // "Loaded item non-uuid creator doesn't match that of the loading user");
198 Assert.That(
199 foundItem1.Name, Is.EqualTo(itemName),
200 "Loaded item name doesn't match saved name");
201 }
202  
203 /// <summary>
204 /// Test replication of an archive path to the user's inventory.
205 /// </summary>
206 [Test]
207 public void TestNewIarPath()
208 {
209 TestHelpers.InMethod();
210 // log4net.Config.XmlConfigurator.Configure();
211  
212 Scene scene = new SceneHelpers().SetupScene();
213 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
214  
215 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
216 HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>();
217  
218 string folder1Name = "1";
219 string folder2aName = "2a";
220 string folder2bName = "2b";
221  
222 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random());
223 string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random());
224 string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random());
225  
226 string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName });
227 string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName });
228  
229 {
230 // Test replication of path1
231 new InventoryArchiveReadRequest(scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
232 .ReplicateArchivePathToUserInventory(
233 iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
234 foldersCreated, nodesLoaded);
235  
236 List<InventoryFolderBase> folder1Candidates
237 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
238 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
239  
240 InventoryFolderBase folder1 = folder1Candidates[0];
241 List<InventoryFolderBase> folder2aCandidates
242 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
243 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
244 }
245  
246 {
247 // Test replication of path2
248 new InventoryArchiveReadRequest(scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
249 .ReplicateArchivePathToUserInventory(
250 iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
251 foldersCreated, nodesLoaded);
252  
253 List<InventoryFolderBase> folder1Candidates
254 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
255 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
256  
257 InventoryFolderBase folder1 = folder1Candidates[0];
258  
259 List<InventoryFolderBase> folder2aCandidates
260 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
261 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
262  
263 List<InventoryFolderBase> folder2bCandidates
264 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2bName);
265 Assert.That(folder2bCandidates.Count, Is.EqualTo(1));
266 }
267 }
268  
269 /// <summary>
270 /// Test replication of a partly existing archive path to the user's inventory. This should create
271 /// a duplicate path without the merge option.
272 /// </summary>
273 [Test]
274 public void TestPartExistingIarPath()
275 {
276 TestHelpers.InMethod();
277 //log4net.Config.XmlConfigurator.Configure();
278  
279 Scene scene = new SceneHelpers().SetupScene();
280 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
281  
282 string folder1ExistingName = "a";
283 string folder2Name = "b";
284  
285 InventoryFolderBase folder1
286 = UserInventoryHelpers.CreateInventoryFolder(
287 scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
288  
289 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
290 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
291  
292 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
293  
294 new InventoryArchiveReadRequest(scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
295 .ReplicateArchivePathToUserInventory(
296 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
297 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
298  
299 List<InventoryFolderBase> folder1PostCandidates
300 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
301 Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));
302  
303 // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
304 InventoryFolderBase folder1Post = null;
305 foreach (InventoryFolderBase folder in folder1PostCandidates)
306 {
307 if (folder.ID != folder1.ID)
308 {
309 folder1Post = folder;
310 break;
311 }
312 }
313 // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
314  
315 List<InventoryFolderBase> folder2PostCandidates
316 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1Post, "b");
317 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
318 }
319  
320 /// <summary>
321 /// Test replication of a partly existing archive path to the user's inventory. This should create
322 /// a merged path.
323 /// </summary>
324 [Test]
325 public void TestMergeIarPath()
326 {
327 TestHelpers.InMethod();
328 // log4net.Config.XmlConfigurator.Configure();
329  
330 Scene scene = new SceneHelpers().SetupScene();
331 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
332  
333 string folder1ExistingName = "a";
334 string folder2Name = "b";
335  
336 InventoryFolderBase folder1
337 = UserInventoryHelpers.CreateInventoryFolder(
338 scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
339  
340 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
341 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
342  
343 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
344  
345 new InventoryArchiveReadRequest(scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, folder1ExistingName, (Stream)null, true)
346 .ReplicateArchivePathToUserInventory(
347 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
348 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
349  
350 List<InventoryFolderBase> folder1PostCandidates
351 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
352 Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
353 Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));
354  
355 List<InventoryFolderBase> folder2PostCandidates
356 = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1PostCandidates[0], "b");
357 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
358 }
359 }
360 }
361