29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
33 using NUnit.Framework;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Serialization;
38 using OpenSim.Framework.Serialization.External;
39 using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
40 using OpenSim.Region.CoreModules.World.Serialiser;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.Framework.Scenes.Serialization;
43 using OpenSim.Services.Interfaces;
44 using OpenSim.Tests.Common;
46 namespace OpenSim.
Region.CoreModules.
Avatar.Inventory.Archiver.Tests
63 SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule);
75 TestHelpers.InMethod();
78 MemoryStream archiveReadStream =
new MemoryStream(m_iarStreamBytes);
81 TarArchiveReader.TarEntryType tarEntryType;
83 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
84 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
88 iarr.LoadControlFile(filePath, data);
90 Assert.That(iarr.ControlFileLoaded, Is.True);
96 TestHelpers.InMethod();
99 string userFirstName =
"Jock";
100 string userLastName =
"Stirrup";
101 string userPassword =
"troll";
102 UUID userId = TestHelpers.ParseTail(0x20);
104 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
106 MemoryStream archiveWriteStream =
new MemoryStream();
107 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
110 m_archiverModule.ArchiveInventory(
111 UUID.Random(), userFirstName, userLastName,
"/", userPassword, archiveWriteStream);
112 mre.WaitOne(60000,
false);
115 byte[] archive = archiveWriteStream.ToArray();
116 MemoryStream archiveReadStream =
new MemoryStream(archive);
120 bool gotObjectsFolder =
false;
122 string objectsFolderName
125 ArchiveConstants.INVENTORY_PATH,
126 InventoryArchiveWriteRequest.CreateArchiveFolderName(
127 UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, userId,
"Objects")));
130 TarArchiveReader.TarEntryType tarEntryType;
132 while (tar.
ReadEntry(out filePath, out tarEntryType) != null)
139 if (filePath == objectsFolderName)
140 gotObjectsFolder =
true;
143 Assert.That(gotObjectsFolder, Is.True);
149 TestHelpers.InMethod();
152 string userFirstName =
"Jock";
153 string userLastName =
"Stirrup";
154 string userPassword =
"troll";
155 UUID userId = TestHelpers.ParseTail(0x20);
157 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
161 = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId,
"f1",
true);
164 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId,
"My Little Dog Object", 0x5);
165 InventoryItemBase i1 = UserInventoryHelpers.AddInventoryItem(m_scene, so1, 0x50, 0x60,
"f1");
169 = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId,
"f1/f1.1",
true);
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");
175 MemoryStream archiveWriteStream =
new MemoryStream();
176 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
179 m_archiverModule.ArchiveInventory(
180 UUID.Random(), userFirstName, userLastName,
"f1", userPassword, archiveWriteStream);
181 mre.WaitOne(60000,
false);
184 byte[] archive = archiveWriteStream.ToArray();
185 MemoryStream archiveReadStream =
new MemoryStream(archive);
189 bool gotf1 =
false, gotf1_1 =
false, gotso1 =
false, gotso2 =
false;
192 = string.Format(
"{0}{1}", ArchiveConstants.INVENTORY_PATH, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1));
194 = string.Format(
"{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1_1));
196 = string.Format(
"{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i1));
198 = string.Format(
"{0}{1}", f1_1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i2));
201 TarArchiveReader.TarEntryType tarEntryType;
203 while (tar.
ReadEntry(out filePath, out tarEntryType) != null)
207 if (filePath == f1FileName)
209 else if (filePath == f1_1FileName)
211 else if (filePath == so1FileName)
213 else if (filePath == so2FileName)
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);
233 TestHelpers.InMethod();
237 string userFirstName =
"Jock";
238 string userLastName =
"Stirrup";
239 string userPassword =
"troll";
240 UUID userId = UUID.Parse(
"00000000-0000-0000-0000-000000000020");
241 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
244 UUID ownerId = UUID.Parse(
"00000000-0000-0000-0000-000000000040");
245 SceneObjectGroup object1 = SceneHelpers.CreateSceneObject(1, ownerId,
"My Little Dog Object", 0x50);
247 UUID asset1Id = UUID.Parse(
"00000000-0000-0000-0000-000000000060");
248 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
249 m_scene.AssetService.Store(asset1);
252 UUID item1Id = UUID.Parse(
"00000000-0000-0000-0000-000000000080");
253 string item1Name =
"My Little Dog";
255 item1.Name = item1Name;
256 item1.AssetID = asset1.FullID;
259 = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId,
"Objects")[0];
260 item1.Folder = objsFolder.ID;
261 m_scene.AddInventoryItem(item1);
263 MemoryStream archiveWriteStream =
new MemoryStream();
264 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
267 m_archiverModule.ArchiveInventory(
268 UUID.Random(), userFirstName, userLastName,
"Objects/" + item1Name, userPassword, archiveWriteStream);
269 mre.WaitOne(60000,
false);
271 byte[] archive = archiveWriteStream.ToArray();
272 MemoryStream archiveReadStream =
new MemoryStream(archive);
276 bool gotObject1File =
false;
278 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
279 string expectedObject1FilePath = string.Format(
281 ArchiveConstants.INVENTORY_PATH,
282 expectedObject1FileName);
285 TarArchiveReader.TarEntryType tarEntryType;
289 while (tar.
ReadEntry(out filePath, out tarEntryType) != null)
291 Console.WriteLine(
"Got {0}", filePath);
304 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
305 gotObject1File =
true;
316 Assert.That(gotObject1File, Is.True,
"No item1 file in archive");
328 TestHelpers.InMethod();
332 string userFirstName =
"Jock";
333 string userLastName =
"Stirrup";
334 string userPassword =
"troll";
335 UUID userId = UUID.Parse(
"00000000-0000-0000-0000-000000000020");
336 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
339 UUID ownerId = UUID.Parse(
"00000000-0000-0000-0000-000000000040");
340 SceneObjectGroup object1 = SceneHelpers.CreateSceneObject(1, ownerId,
"My Little Dog Object", 0x50);
342 UUID asset1Id = UUID.Parse(
"00000000-0000-0000-0000-000000000060");
343 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
344 m_scene.AssetService.Store(asset1);
347 UUID item1Id = UUID.Parse(
"00000000-0000-0000-0000-000000000080");
348 string item1Name =
"My Little Dog";
350 item1.Name = item1Name;
351 item1.AssetID = asset1.FullID;
354 = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId,
"Objects")[0];
355 item1.Folder = objsFolder.ID;
356 m_scene.AddInventoryItem(item1);
358 MemoryStream archiveWriteStream =
new MemoryStream();
360 Dictionary<string, Object>
options =
new Dictionary<string, Object>();
361 options.Add(
"noassets",
true);
364 m_archiverModule.ArchiveInventory(
365 UUID.Random(), userFirstName, userLastName,
"Objects/" + item1Name, userPassword, archiveWriteStream, options);
367 byte[] archive = archiveWriteStream.ToArray();
368 MemoryStream archiveReadStream =
new MemoryStream(archive);
372 bool gotObject1File =
false;
374 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
375 string expectedObject1FilePath = string.Format(
377 ArchiveConstants.INVENTORY_PATH,
378 expectedObject1FileName);
381 TarArchiveReader.TarEntryType tarEntryType;
385 while (tar.
ReadEntry(out filePath, out tarEntryType) != null)
387 Console.WriteLine(
"Got {0}", filePath);
400 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
401 gotObject1File =
true;
411 Assert.Fail(
"Found asset path in TestSaveItemToIarNoAssets()");
416 Assert.That(gotObject1File, Is.True,
"No item1 file in archive");
Temporary code to do the bare minimum required to read a tar archive for our purposes ...
Constants for the archiving module
OpenSim.Framework.Serialization.TarArchiveReader TarArchiveReader
void TestSaveItemToIarNoAssets()
Test saving a single inventory item to an IAR without its asset
InventoryArchiverModule m_archiverModule
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void TestSaveRootFolderToIar()
Asset class. All Assets are reference by this class or a class derived from this class ...
This module loads and saves OpenSimulator inventory archives
void TestSaveNonRootFolderToIar()
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
byte[] ReadEntry(out string filePath, out TarEntryType entryType)
Read the next entry in the tar file.
void TestSaveItemToIar()
Test saving a single inventory item to an IAR (subject to change since there is no fixed format yet)...
const string INVENTORY_PATH
void TestOrder()
Test that the IAR has the required files in the right order.