aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs424
1 files changed, 424 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs
new file mode 100644
index 0000000..5e7e24c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveSaveTests.cs
@@ -0,0 +1,424 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Threading;
33using NUnit.Framework;
34using OpenMetaverse;
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Framework.Serialization;
38using OpenSim.Framework.Serialization.External;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
41using OpenSim.Region.CoreModules.World.Serialiser;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
49{
50 [TestFixture]
51 public class InventoryArchiveSaveTests : InventoryArchiveTestCase
52 {
53 protected TestScene m_scene;
54 protected InventoryArchiverModule m_archiverModule;
55
56 [SetUp]
57 public override void SetUp()
58 {
59 base.SetUp();
60
61 SerialiserModule serialiserModule = new SerialiserModule();
62 m_archiverModule = new InventoryArchiverModule();
63
64 m_scene = new SceneHelpers().SetupScene();
65 SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule);
66 }
67
68 /// <summary>
69 /// Test that the IAR has the required files in the right order.
70 /// </summary>
71 /// <remarks>
72 /// At the moment, the only thing that matters is that the control file is the very first one.
73 /// </remarks>
74 [Test]
75 public void TestOrder()
76 {
77 TestHelpers.InMethod();
78// log4net.Config.XmlConfigurator.Configure();
79
80 MemoryStream archiveReadStream = new MemoryStream(m_iarStreamBytes);
81 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
82 string filePath;
83 TarArchiveReader.TarEntryType tarEntryType;
84
85 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
86 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
87
88 InventoryArchiveReadRequest iarr
89 = new InventoryArchiveReadRequest(null, null, null, (Stream)null, false);
90 iarr.LoadControlFile(filePath, data);
91
92 Assert.That(iarr.ControlFileLoaded, Is.True);
93 }
94
95 [Test]
96 public void TestSaveRootFolderToIar()
97 {
98 TestHelpers.InMethod();
99// TestHelpers.EnableLogging();
100
101 string userFirstName = "Jock";
102 string userLastName = "Stirrup";
103 string userPassword = "troll";
104 UUID userId = TestHelpers.ParseTail(0x20);
105
106 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
107
108 MemoryStream archiveWriteStream = new MemoryStream();
109 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
110
111 mre.Reset();
112 m_archiverModule.ArchiveInventory(
113 Guid.NewGuid(), userFirstName, userLastName, "/", userPassword, archiveWriteStream);
114 mre.WaitOne(60000, false);
115
116 // Test created iar
117 byte[] archive = archiveWriteStream.ToArray();
118 MemoryStream archiveReadStream = new MemoryStream(archive);
119 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
120
121// InventoryArchiveUtils.
122 bool gotObjectsFolder = false;
123
124 string objectsFolderName
125 = string.Format(
126 "{0}{1}",
127 ArchiveConstants.INVENTORY_PATH,
128 InventoryArchiveWriteRequest.CreateArchiveFolderName(
129 UserInventoryHelpers.GetInventoryFolder(m_scene.InventoryService, userId, "Objects")));
130
131 string filePath;
132 TarArchiveReader.TarEntryType tarEntryType;
133
134 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
135 {
136// Console.WriteLine("Got {0}", filePath);
137
138 // Lazily, we only bother to look for the system objects folder created when we call CreateUserWithInventory()
139 // XXX: But really we need to stop all that stuff being created in tests or check for such folders
140 // more thoroughly
141 if (filePath == objectsFolderName)
142 gotObjectsFolder = true;
143 }
144
145 Assert.That(gotObjectsFolder, Is.True);
146 }
147
148 [Test]
149 public void TestSaveNonRootFolderToIar()
150 {
151 TestHelpers.InMethod();
152// TestHelpers.EnableLogging();
153
154 string userFirstName = "Jock";
155 string userLastName = "Stirrup";
156 string userPassword = "troll";
157 UUID userId = TestHelpers.ParseTail(0x20);
158
159 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
160
161 // Create base folder
162 InventoryFolderBase f1
163 = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1", true);
164
165 // Create item1
166 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Dog Object", 0x5);
167 InventoryItemBase i1 = UserInventoryHelpers.AddInventoryItem(m_scene, so1, 0x50, 0x60, "f1");
168
169 // Create embedded folder
170 InventoryFolderBase f1_1
171 = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1/f1.1", true);
172
173 // Create embedded item
174 SceneObjectGroup so1_1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Cat Object", 0x6);
175 InventoryItemBase i2 = UserInventoryHelpers.AddInventoryItem(m_scene, so1_1, 0x500, 0x600, "f1/f1.1");
176
177 MemoryStream archiveWriteStream = new MemoryStream();
178 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
179
180 mre.Reset();
181 m_archiverModule.ArchiveInventory(
182 Guid.NewGuid(), userFirstName, userLastName, "f1", userPassword, archiveWriteStream);
183 mre.WaitOne(60000, false);
184
185 // Test created iar
186 byte[] archive = archiveWriteStream.ToArray();
187 MemoryStream archiveReadStream = new MemoryStream(archive);
188 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
189
190// InventoryArchiveUtils.
191 bool gotf1 = false, gotf1_1 = false, gotso1 = false, gotso2 = false;
192
193 string f1FileName
194 = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1));
195 string f1_1FileName
196 = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1_1));
197 string so1FileName
198 = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i1));
199 string so2FileName
200 = string.Format("{0}{1}", f1_1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i2));
201
202 string filePath;
203 TarArchiveReader.TarEntryType tarEntryType;
204
205 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
206 {
207// Console.WriteLine("Got {0}", filePath);
208
209 if (filePath == f1FileName)
210 gotf1 = true;
211 else if (filePath == f1_1FileName)
212 gotf1_1 = true;
213 else if (filePath == so1FileName)
214 gotso1 = true;
215 else if (filePath == so2FileName)
216 gotso2 = true;
217 }
218
219// Assert.That(gotControlFile, Is.True, "No control file in archive");
220 Assert.That(gotf1, Is.True);
221 Assert.That(gotf1_1, Is.True);
222 Assert.That(gotso1, Is.True);
223 Assert.That(gotso2, Is.True);
224
225 // TODO: Test presence of more files and contents of files.
226 }
227
228 /// <summary>
229 /// Test saving a single inventory item to an IAR
230 /// (subject to change since there is no fixed format yet).
231 /// </summary>
232 [Test]
233 public void TestSaveItemToIar()
234 {
235 TestHelpers.InMethod();
236// log4net.Config.XmlConfigurator.Configure();
237
238 // Create user
239 string userFirstName = "Jock";
240 string userLastName = "Stirrup";
241 string userPassword = "troll";
242 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
243 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
244
245 // Create asset
246 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
247 SceneObjectGroup object1 = SceneHelpers.CreateSceneObject(1, ownerId, "My Little Dog Object", 0x50);
248
249 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
250 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
251 m_scene.AssetService.Store(asset1);
252
253 // Create item
254 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
255 string item1Name = "My Little Dog";
256 InventoryItemBase item1 = new InventoryItemBase();
257 item1.Name = item1Name;
258 item1.AssetID = asset1.FullID;
259 item1.ID = item1Id;
260 InventoryFolderBase objsFolder
261 = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId, "Objects")[0];
262 item1.Folder = objsFolder.ID;
263 m_scene.AddInventoryItem(item1);
264
265 MemoryStream archiveWriteStream = new MemoryStream();
266 m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;
267
268 mre.Reset();
269 m_archiverModule.ArchiveInventory(
270 Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream);
271 mre.WaitOne(60000, false);
272
273 byte[] archive = archiveWriteStream.ToArray();
274 MemoryStream archiveReadStream = new MemoryStream(archive);
275 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
276
277 //bool gotControlFile = false;
278 bool gotObject1File = false;
279 //bool gotObject2File = false;
280 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
281 string expectedObject1FilePath = string.Format(
282 "{0}{1}",
283 ArchiveConstants.INVENTORY_PATH,
284 expectedObject1FileName);
285
286 string filePath;
287 TarArchiveReader.TarEntryType tarEntryType;
288
289// Console.WriteLine("Reading archive");
290
291 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
292 {
293 Console.WriteLine("Got {0}", filePath);
294
295// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
296// {
297// gotControlFile = true;
298// }
299
300 if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
301 {
302// string fileName = filePath.Remove(0, "Objects/".Length);
303//
304// if (fileName.StartsWith(part1.Name))
305// {
306 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
307 gotObject1File = true;
308// }
309// else if (fileName.StartsWith(part2.Name))
310// {
311// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
312// gotObject2File = true;
313// }
314 }
315 }
316
317// Assert.That(gotControlFile, Is.True, "No control file in archive");
318 Assert.That(gotObject1File, Is.True, "No item1 file in archive");
319// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
320
321 // TODO: Test presence of more files and contents of files.
322 }
323
324 /// <summary>
325 /// Test saving a single inventory item to an IAR without its asset
326 /// </summary>
327 [Test]
328 public void TestSaveItemToIarNoAssets()
329 {
330 TestHelpers.InMethod();
331// log4net.Config.XmlConfigurator.Configure();
332
333 // Create user
334 string userFirstName = "Jock";
335 string userLastName = "Stirrup";
336 string userPassword = "troll";
337 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
338 UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);
339
340 // Create asset
341 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
342 SceneObjectGroup object1 = SceneHelpers.CreateSceneObject(1, ownerId, "My Little Dog Object", 0x50);
343
344 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
345 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
346 m_scene.AssetService.Store(asset1);
347
348 // Create item
349 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
350 string item1Name = "My Little Dog";
351 InventoryItemBase item1 = new InventoryItemBase();
352 item1.Name = item1Name;
353 item1.AssetID = asset1.FullID;
354 item1.ID = item1Id;
355 InventoryFolderBase objsFolder
356 = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, userId, "Objects")[0];
357 item1.Folder = objsFolder.ID;
358 m_scene.AddInventoryItem(item1);
359
360 MemoryStream archiveWriteStream = new MemoryStream();
361
362 Dictionary<string, Object> options = new Dictionary<string, Object>();
363 options.Add("noassets", true);
364
365 // When we're not saving assets, archiving is being done synchronously.
366 m_archiverModule.ArchiveInventory(
367 Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream, options);
368
369 byte[] archive = archiveWriteStream.ToArray();
370 MemoryStream archiveReadStream = new MemoryStream(archive);
371 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
372
373 //bool gotControlFile = false;
374 bool gotObject1File = false;
375 //bool gotObject2File = false;
376 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
377 string expectedObject1FilePath = string.Format(
378 "{0}{1}",
379 ArchiveConstants.INVENTORY_PATH,
380 expectedObject1FileName);
381
382 string filePath;
383 TarArchiveReader.TarEntryType tarEntryType;
384
385// Console.WriteLine("Reading archive");
386
387 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
388 {
389 Console.WriteLine("Got {0}", filePath);
390
391// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
392// {
393// gotControlFile = true;
394// }
395
396 if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
397 {
398// string fileName = filePath.Remove(0, "Objects/".Length);
399//
400// if (fileName.StartsWith(part1.Name))
401// {
402 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
403 gotObject1File = true;
404// }
405// else if (fileName.StartsWith(part2.Name))
406// {
407// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
408// gotObject2File = true;
409// }
410 }
411 else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
412 {
413 Assert.Fail("Found asset path in TestSaveItemToIarNoAssets()");
414 }
415 }
416
417// Assert.That(gotControlFile, Is.True, "No control file in archive");
418 Assert.That(gotObject1File, Is.True, "No item1 file in archive");
419// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
420
421 // TODO: Test presence of more files and contents of files.
422 }
423 }
424} \ No newline at end of file