diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs (renamed from OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs) | 275 |
1 files changed, 140 insertions, 135 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs index 06f6e49..7265405 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs | |||
@@ -36,19 +36,17 @@ using OpenSim.Data; | |||
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Serialization; | 37 | using OpenSim.Framework.Serialization; |
38 | using OpenSim.Framework.Serialization.External; | 38 | using OpenSim.Framework.Serialization.External; |
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | 39 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; |
41 | using OpenSim.Region.CoreModules.World.Serialiser; | 40 | using OpenSim.Region.CoreModules.World.Serialiser; |
42 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
43 | using OpenSim.Region.Framework.Scenes.Serialization; | 42 | using OpenSim.Region.Framework.Scenes.Serialization; |
44 | using OpenSim.Services.Interfaces; | 43 | using OpenSim.Services.Interfaces; |
45 | using OpenSim.Tests.Common; | 44 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | ||
47 | 45 | ||
48 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | 46 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests |
49 | { | 47 | { |
50 | [TestFixture] | 48 | [TestFixture] |
51 | public class InventoryArchiverTests : InventoryArchiveTestCase | 49 | public class InventoryArchiveSaveTests : InventoryArchiveTestCase |
52 | { | 50 | { |
53 | protected TestScene m_scene; | 51 | protected TestScene m_scene; |
54 | protected InventoryArchiverModule m_archiverModule; | 52 | protected InventoryArchiverModule m_archiverModule; |
@@ -64,36 +62,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
64 | m_scene = new SceneHelpers().SetupScene(); | 62 | m_scene = new SceneHelpers().SetupScene(); |
65 | SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule); | 63 | SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule); |
66 | } | 64 | } |
67 | |||
68 | [Test] | ||
69 | public void TestLoadCoalesecedItem() | ||
70 | { | ||
71 | TestHelpers.InMethod(); | ||
72 | // TestHelpers.EnableLogging(); | ||
73 | |||
74 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL1, "password"); | ||
75 | m_archiverModule.DearchiveInventory(m_uaLL1.FirstName, m_uaLL1.LastName, "/", "password", m_iarStream); | ||
76 | |||
77 | InventoryItemBase coaItem | ||
78 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaLL1.PrincipalID, m_coaItemName); | ||
79 | |||
80 | Assert.That(coaItem, Is.Not.Null, "Didn't find loaded item 1"); | ||
81 | |||
82 | string assetXml = AssetHelpers.ReadAssetAsString(m_scene.AssetService, coaItem.AssetID); | ||
83 | |||
84 | CoalescedSceneObjects coa; | ||
85 | bool readResult = CoalescedSceneObjectsSerializer.TryFromXml(assetXml, out coa); | ||
86 | |||
87 | Assert.That(readResult, Is.True); | ||
88 | Assert.That(coa.Count, Is.EqualTo(2)); | ||
89 | |||
90 | List<SceneObjectGroup> coaObjects = coa.Objects; | ||
91 | Assert.That(coaObjects[0].UUID, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000120"))); | ||
92 | Assert.That(coaObjects[0].AbsolutePosition, Is.EqualTo(new Vector3(15, 30, 45))); | ||
93 | |||
94 | Assert.That(coaObjects[1].UUID, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000140"))); | ||
95 | Assert.That(coaObjects[1].AbsolutePosition, Is.EqualTo(new Vector3(25, 50, 75))); | ||
96 | } | ||
97 | 65 | ||
98 | /// <summary> | 66 | /// <summary> |
99 | /// Test that the IAR has the required files in the right order. | 67 | /// Test that the IAR has the required files in the right order. |
@@ -115,12 +83,145 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
115 | byte[] data = tar.ReadEntry(out filePath, out tarEntryType); | 83 | byte[] data = tar.ReadEntry(out filePath, out tarEntryType); |
116 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); | 84 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); |
117 | 85 | ||
118 | InventoryArchiveReadRequest iarr | 86 | InventoryArchiveReadRequest iarr |
119 | = new InventoryArchiveReadRequest(null, null, null, (Stream)null, false); | 87 | = new InventoryArchiveReadRequest(UUID.Random(), null, null, null, null, null, null, (Stream)null, false); |
120 | iarr.LoadControlFile(filePath, data); | 88 | iarr.LoadControlFile(filePath, data); |
121 | 89 | ||
122 | Assert.That(iarr.ControlFileLoaded, Is.True); | 90 | Assert.That(iarr.ControlFileLoaded, Is.True); |
123 | } | 91 | } |
92 | |||
93 | [Test] | ||
94 | public void TestSaveRootFolderToIar() | ||
95 | { | ||
96 | TestHelpers.InMethod(); | ||
97 | // TestHelpers.EnableLogging(); | ||
98 | |||
99 | string userFirstName = "Jock"; | ||
100 | string userLastName = "Stirrup"; | ||
101 | string userPassword = "troll"; | ||
102 | UUID userId = TestHelpers.ParseTail(0x20); | ||
103 | |||
104 | UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword); | ||
105 | |||
106 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
107 | m_archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
108 | |||
109 | mre.Reset(); | ||
110 | m_archiverModule.ArchiveInventory( | ||
111 | UUID.Random(), userFirstName, userLastName, "/", userPassword, archiveWriteStream); | ||
112 | mre.WaitOne(60000, false); | ||
113 | |||
114 | // Test created iar | ||
115 | byte[] archive = archiveWriteStream.ToArray(); | ||
116 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
117 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
118 | |||
119 | // InventoryArchiveUtils. | ||
120 | bool gotObjectsFolder = false; | ||
121 | |||
122 | string objectsFolderName | ||
123 | = string.Format( | ||
124 | "{0}{1}", | ||
125 | ArchiveConstants.INVENTORY_PATH, | ||
126 | InventoryArchiveWriteRequest.CreateArchiveFolderName( | ||
127 | UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, userId, "Objects"))); | ||
128 | |||
129 | string filePath; | ||
130 | TarArchiveReader.TarEntryType tarEntryType; | ||
131 | |||
132 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
133 | { | ||
134 | // Console.WriteLine("Got {0}", filePath); | ||
135 | |||
136 | // Lazily, we only bother to look for the system objects folder created when we call CreateUserWithInventory() | ||
137 | // XXX: But really we need to stop all that stuff being created in tests or check for such folders | ||
138 | // more thoroughly | ||
139 | if (filePath == objectsFolderName) | ||
140 | gotObjectsFolder = true; | ||
141 | } | ||
142 | |||
143 | Assert.That(gotObjectsFolder, Is.True); | ||
144 | } | ||
145 | |||
146 | [Test] | ||
147 | public void TestSaveNonRootFolderToIar() | ||
148 | { | ||
149 | TestHelpers.InMethod(); | ||
150 | // TestHelpers.EnableLogging(); | ||
151 | |||
152 | string userFirstName = "Jock"; | ||
153 | string userLastName = "Stirrup"; | ||
154 | string userPassword = "troll"; | ||
155 | UUID userId = TestHelpers.ParseTail(0x20); | ||
156 | |||
157 | UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword); | ||
158 | |||
159 | // Create base folder | ||
160 | InventoryFolderBase f1 | ||
161 | = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1", true); | ||
162 | |||
163 | // Create item1 | ||
164 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Dog Object", 0x5); | ||
165 | InventoryItemBase i1 = UserInventoryHelpers.AddInventoryItem(m_scene, so1, 0x50, 0x60, "f1"); | ||
166 | |||
167 | // Create embedded folder | ||
168 | InventoryFolderBase f1_1 | ||
169 | = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1/f1.1", true); | ||
170 | |||
171 | // Create embedded item | ||
172 | SceneObjectGroup so1_1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Cat Object", 0x6); | ||
173 | InventoryItemBase i2 = UserInventoryHelpers.AddInventoryItem(m_scene, so1_1, 0x500, 0x600, "f1/f1.1"); | ||
174 | |||
175 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
176 | m_archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
177 | |||
178 | mre.Reset(); | ||
179 | m_archiverModule.ArchiveInventory( | ||
180 | UUID.Random(), userFirstName, userLastName, "f1", userPassword, archiveWriteStream); | ||
181 | mre.WaitOne(60000, false); | ||
182 | |||
183 | // Test created iar | ||
184 | byte[] archive = archiveWriteStream.ToArray(); | ||
185 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
186 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
187 | |||
188 | // InventoryArchiveUtils. | ||
189 | bool gotf1 = false, gotf1_1 = false, gotso1 = false, gotso2 = false; | ||
190 | |||
191 | string f1FileName | ||
192 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1)); | ||
193 | string f1_1FileName | ||
194 | = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1_1)); | ||
195 | string so1FileName | ||
196 | = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i1)); | ||
197 | string so2FileName | ||
198 | = string.Format("{0}{1}", f1_1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i2)); | ||
199 | |||
200 | string filePath; | ||
201 | TarArchiveReader.TarEntryType tarEntryType; | ||
202 | |||
203 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
204 | { | ||
205 | // Console.WriteLine("Got {0}", filePath); | ||
206 | |||
207 | if (filePath == f1FileName) | ||
208 | gotf1 = true; | ||
209 | else if (filePath == f1_1FileName) | ||
210 | gotf1_1 = true; | ||
211 | else if (filePath == so1FileName) | ||
212 | gotso1 = true; | ||
213 | else if (filePath == so2FileName) | ||
214 | gotso2 = true; | ||
215 | } | ||
216 | |||
217 | // Assert.That(gotControlFile, Is.True, "No control file in archive"); | ||
218 | Assert.That(gotf1, Is.True); | ||
219 | Assert.That(gotf1_1, Is.True); | ||
220 | Assert.That(gotso1, Is.True); | ||
221 | Assert.That(gotso2, Is.True); | ||
222 | |||
223 | // TODO: Test presence of more files and contents of files. | ||
224 | } | ||
124 | 225 | ||
125 | /// <summary> | 226 | /// <summary> |
126 | /// Test saving a single inventory item to an IAR | 227 | /// Test saving a single inventory item to an IAR |
@@ -155,7 +256,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
155 | item1.AssetID = asset1.FullID; | 256 | item1.AssetID = asset1.FullID; |
156 | item1.ID = item1Id; | 257 | item1.ID = item1Id; |
157 | InventoryFolderBase objsFolder | 258 | InventoryFolderBase objsFolder |
158 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, userId, "Objects")[0]; | 259 | = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId, "Objects")[0]; |
159 | item1.Folder = objsFolder.ID; | 260 | item1.Folder = objsFolder.ID; |
160 | m_scene.AddInventoryItem(item1); | 261 | m_scene.AddInventoryItem(item1); |
161 | 262 | ||
@@ -164,7 +265,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
164 | 265 | ||
165 | mre.Reset(); | 266 | mre.Reset(); |
166 | m_archiverModule.ArchiveInventory( | 267 | m_archiverModule.ArchiveInventory( |
167 | Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream); | 268 | UUID.Random(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream); |
168 | mre.WaitOne(60000, false); | 269 | mre.WaitOne(60000, false); |
169 | 270 | ||
170 | byte[] archive = archiveWriteStream.ToArray(); | 271 | byte[] archive = archiveWriteStream.ToArray(); |
@@ -250,7 +351,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
250 | item1.AssetID = asset1.FullID; | 351 | item1.AssetID = asset1.FullID; |
251 | item1.ID = item1Id; | 352 | item1.ID = item1Id; |
252 | InventoryFolderBase objsFolder | 353 | InventoryFolderBase objsFolder |
253 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, userId, "Objects")[0]; | 354 | = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId, "Objects")[0]; |
254 | item1.Folder = objsFolder.ID; | 355 | item1.Folder = objsFolder.ID; |
255 | m_scene.AddInventoryItem(item1); | 356 | m_scene.AddInventoryItem(item1); |
256 | 357 | ||
@@ -261,7 +362,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
261 | 362 | ||
262 | // When we're not saving assets, archiving is being done synchronously. | 363 | // When we're not saving assets, archiving is being done synchronously. |
263 | m_archiverModule.ArchiveInventory( | 364 | m_archiverModule.ArchiveInventory( |
264 | Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream, options); | 365 | UUID.Random(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream, options); |
265 | 366 | ||
266 | byte[] archive = archiveWriteStream.ToArray(); | 367 | byte[] archive = archiveWriteStream.ToArray(); |
267 | MemoryStream archiveReadStream = new MemoryStream(archive); | 368 | MemoryStream archiveReadStream = new MemoryStream(archive); |
@@ -317,101 +418,5 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
317 | 418 | ||
318 | // TODO: Test presence of more files and contents of files. | 419 | // TODO: Test presence of more files and contents of files. |
319 | } | 420 | } |
320 | |||
321 | /// <summary> | ||
322 | /// Test case where a creator account exists for the creator UUID embedded in item metadata and serialized | ||
323 | /// objects. | ||
324 | /// </summary> | ||
325 | [Test] | ||
326 | public void TestLoadIarCreatorAccountPresent() | ||
327 | { | ||
328 | TestHelpers.InMethod(); | ||
329 | // log4net.Config.XmlConfigurator.Configure(); | ||
330 | |||
331 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL1, "meowfood"); | ||
332 | |||
333 | m_archiverModule.DearchiveInventory(m_uaLL1.FirstName, m_uaLL1.LastName, "/", "meowfood", m_iarStream); | ||
334 | InventoryItemBase foundItem1 | ||
335 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaLL1.PrincipalID, m_item1Name); | ||
336 | |||
337 | Assert.That( | ||
338 | foundItem1.CreatorId, Is.EqualTo(m_uaLL1.PrincipalID.ToString()), | ||
339 | "Loaded item non-uuid creator doesn't match original"); | ||
340 | Assert.That( | ||
341 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL1.PrincipalID), | ||
342 | "Loaded item uuid creator doesn't match original"); | ||
343 | Assert.That(foundItem1.Owner, Is.EqualTo(m_uaLL1.PrincipalID), | ||
344 | "Loaded item owner doesn't match inventory reciever"); | ||
345 | |||
346 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
347 | string xmlData = Utils.BytesToString(asset1.Data); | ||
348 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
349 | |||
350 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL1.PrincipalID)); | ||
351 | } | ||
352 | |||
353 | // /// <summary> | ||
354 | // /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
355 | // /// an account exists with the same name as the creator, though not the same id. | ||
356 | // /// </summary> | ||
357 | // [Test] | ||
358 | // public void TestLoadIarV0_1SameNameCreator() | ||
359 | // { | ||
360 | // TestHelpers.InMethod(); | ||
361 | // TestHelpers.EnableLogging(); | ||
362 | // | ||
363 | // UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaMT, "meowfood"); | ||
364 | // UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL2, "hampshire"); | ||
365 | // | ||
366 | // m_archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream); | ||
367 | // InventoryItemBase foundItem1 | ||
368 | // = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); | ||
369 | // | ||
370 | // Assert.That( | ||
371 | // foundItem1.CreatorId, Is.EqualTo(m_uaLL2.PrincipalID.ToString()), | ||
372 | // "Loaded item non-uuid creator doesn't match original"); | ||
373 | // Assert.That( | ||
374 | // foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL2.PrincipalID), | ||
375 | // "Loaded item uuid creator doesn't match original"); | ||
376 | // Assert.That(foundItem1.Owner, Is.EqualTo(m_uaMT.PrincipalID), | ||
377 | // "Loaded item owner doesn't match inventory reciever"); | ||
378 | // | ||
379 | // AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
380 | // string xmlData = Utils.BytesToString(asset1.Data); | ||
381 | // SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
382 | // | ||
383 | // Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL2.PrincipalID)); | ||
384 | // } | ||
385 | |||
386 | /// <summary> | ||
387 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
388 | /// the creator or an account with the creator's name does not exist within the system. | ||
389 | /// </summary> | ||
390 | [Test] | ||
391 | public void TestLoadIarV0_1AbsentCreator() | ||
392 | { | ||
393 | TestHelpers.InMethod(); | ||
394 | // log4net.Config.XmlConfigurator.Configure(); | ||
395 | |||
396 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaMT, "password"); | ||
397 | m_archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "password", m_iarStream); | ||
398 | |||
399 | InventoryItemBase foundItem1 | ||
400 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); | ||
401 | |||
402 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
403 | Assert.That( | ||
404 | foundItem1.CreatorId, Is.EqualTo(m_uaMT.PrincipalID.ToString()), | ||
405 | "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
406 | Assert.That( | ||
407 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaMT.PrincipalID), | ||
408 | "Loaded item uuid creator doesn't match that of the loading user"); | ||
409 | |||
410 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
411 | string xmlData = Utils.BytesToString(asset1.Data); | ||
412 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
413 | |||
414 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaMT.PrincipalID)); | ||
415 | } | ||
416 | } | 421 | } |
417 | } \ No newline at end of file | 422 | } \ No newline at end of file |