aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs159
1 files changed, 159 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
new file mode 100644
index 0000000..bc5e564
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -0,0 +1,159 @@
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 OpenSim 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.Text;
30using NUnit.Framework;
31using OpenMetaverse;
32using OpenSim.Data;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Tests.Common.Setup;
39
40namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
41{
42 [TestFixture]
43 public class InventoryArchiverTests
44 {
45 /// <summary>
46 /// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet).
47 /// </summary>
48 [Test]
49 public void TestSaveIarV0p1()
50 {
51 //log4net.Config.XmlConfigurator.Configure();
52
53 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
54
55 Scene scene = SceneSetupHelpers.SetupScene();
56 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
57 CommunicationsManager cm = scene.CommsManager;
58
59 // Create user
60 string userFirstName = "Jock";
61 string userLastName = "Stirrup";
62 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
63 cm.UserAdminService.AddUser(userFirstName, userLastName, string.Empty, string.Empty, 1000, 1000, userId);
64 CachedUserInfo userInfo = cm.UserProfileCacheService.GetUserDetails(userId);
65 userInfo.FetchInventory();
66
67 // Create asset
68 SceneObjectGroup object1;
69 SceneObjectPart part1;
70 {
71 string partName = "My Little Dog Object";
72 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
73 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
74 Vector3 groupPosition = new Vector3(10, 20, 30);
75 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
76 Vector3 offsetPosition = new Vector3(5, 10, 15);
77
78 part1
79 = new SceneObjectPart(
80 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
81 part1.Name = partName;
82
83 object1 = new SceneObjectGroup(part1);
84 }
85
86 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
87 AssetBase asset1 = new AssetBase();
88 asset1.FullID = asset1Id;
89 asset1.Data = Encoding.ASCII.GetBytes(object1.ToXmlString2());
90 cm.AssetCache.AddAsset(asset1);
91
92 // Create item
93 InventoryItemBase item1 = new InventoryItemBase();
94 item1.Name = "My Little Dog";
95 item1.AssetID = asset1.FullID;
96 item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
97 scene.AddInventoryItem(userId, item1);
98
99 /*
100
101 MemoryStream archiveWriteStream = new MemoryStream();
102
103 scene.EventManager.OnOarFileSaved += SaveCompleted;
104 archiverModule.ArchiveRegion(archiveWriteStream);
105 m_waitHandle.WaitOne(60000, true);
106
107 byte[] archive = archiveWriteStream.ToArray();
108 MemoryStream archiveReadStream = new MemoryStream(archive);
109 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
110
111 bool gotControlFile = false;
112 bool gotObject1File = false;
113 bool gotObject2File = false;
114 string expectedObject1FileName = string.Format(
115 "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
116 part1.Name,
117 Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z),
118 part1.UUID);
119 string expectedObject2FileName = string.Format(
120 "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
121 part2.Name,
122 Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z),
123 part2.UUID);
124
125 string filePath;
126 TarArchiveReader.TarEntryType tarEntryType;
127
128 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
129 {
130 if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
131 {
132 gotControlFile = true;
133 }
134 else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
135 {
136 string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length);
137
138 if (fileName.StartsWith(part1.Name))
139 {
140 Assert.That(fileName, Is.EqualTo(expectedObject1FileName));
141 gotObject1File = true;
142 }
143 else if (fileName.StartsWith(part2.Name))
144 {
145 Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
146 gotObject2File = true;
147 }
148 }
149 }
150
151 Assert.That(gotControlFile, Is.True, "No control file in archive");
152 Assert.That(gotObject1File, Is.True, "No object1 file in archive");
153 Assert.That(gotObject2File, Is.True, "No object2 file in archive");
154
155 // TODO: Test presence of more files and contents of files.
156 */
157 }
158 }
159} \ No newline at end of file