diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveLoadTests.cs | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveLoadTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveLoadTests.cs new file mode 100644 index 0000000..57b4f80 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveLoadTests.cs | |||
@@ -0,0 +1,192 @@ | |||
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.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; | ||
45 | |||
46 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | ||
47 | { | ||
48 | [TestFixture] | ||
49 | public class InventoryArchiveLoadTests : InventoryArchiveTestCase | ||
50 | { | ||
51 | protected TestScene m_scene; | ||
52 | protected InventoryArchiverModule m_archiverModule; | ||
53 | |||
54 | [SetUp] | ||
55 | public override void SetUp() | ||
56 | { | ||
57 | base.SetUp(); | ||
58 | |||
59 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
60 | m_archiverModule = new InventoryArchiverModule(); | ||
61 | |||
62 | m_scene = new SceneHelpers().SetupScene(); | ||
63 | SceneHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule); | ||
64 | } | ||
65 | |||
66 | [Test] | ||
67 | public void TestLoadCoalesecedItem() | ||
68 | { | ||
69 | TestHelpers.InMethod(); | ||
70 | // TestHelpers.EnableLogging(); | ||
71 | |||
72 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL1, "password"); | ||
73 | m_archiverModule.DearchiveInventory(UUID.Random(), m_uaLL1.FirstName, m_uaLL1.LastName, "/", "password", m_iarStream); | ||
74 | |||
75 | InventoryItemBase coaItem | ||
76 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaLL1.PrincipalID, m_coaItemName); | ||
77 | |||
78 | Assert.That(coaItem, Is.Not.Null, "Didn't find loaded item 1"); | ||
79 | |||
80 | string assetXml = AssetHelpers.ReadAssetAsString(m_scene.AssetService, coaItem.AssetID); | ||
81 | |||
82 | CoalescedSceneObjects coa; | ||
83 | bool readResult = CoalescedSceneObjectsSerializer.TryFromXml(assetXml, out coa); | ||
84 | |||
85 | Assert.That(readResult, Is.True); | ||
86 | Assert.That(coa.Count, Is.EqualTo(2)); | ||
87 | |||
88 | List<SceneObjectGroup> coaObjects = coa.Objects; | ||
89 | Assert.That(coaObjects[0].UUID, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000120"))); | ||
90 | Assert.That(coaObjects[0].AbsolutePosition, Is.EqualTo(new Vector3(15, 30, 45))); | ||
91 | |||
92 | Assert.That(coaObjects[1].UUID, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000140"))); | ||
93 | Assert.That(coaObjects[1].AbsolutePosition, Is.EqualTo(new Vector3(25, 50, 75))); | ||
94 | } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Test case where a creator account exists for the creator UUID embedded in item metadata and serialized | ||
98 | /// objects. | ||
99 | /// </summary> | ||
100 | [Test] | ||
101 | public void TestLoadIarCreatorAccountPresent() | ||
102 | { | ||
103 | TestHelpers.InMethod(); | ||
104 | // log4net.Config.XmlConfigurator.Configure(); | ||
105 | |||
106 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL1, "meowfood"); | ||
107 | |||
108 | m_archiverModule.DearchiveInventory(UUID.Random(), m_uaLL1.FirstName, m_uaLL1.LastName, "/", "meowfood", m_iarStream); | ||
109 | InventoryItemBase foundItem1 | ||
110 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaLL1.PrincipalID, m_item1Name); | ||
111 | |||
112 | Assert.That( | ||
113 | foundItem1.CreatorId, Is.EqualTo(m_uaLL1.PrincipalID.ToString()), | ||
114 | "Loaded item non-uuid creator doesn't match original"); | ||
115 | Assert.That( | ||
116 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL1.PrincipalID), | ||
117 | "Loaded item uuid creator doesn't match original"); | ||
118 | Assert.That(foundItem1.Owner, Is.EqualTo(m_uaLL1.PrincipalID), | ||
119 | "Loaded item owner doesn't match inventory reciever"); | ||
120 | |||
121 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
122 | string xmlData = Utils.BytesToString(asset1.Data); | ||
123 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
124 | |||
125 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL1.PrincipalID)); | ||
126 | } | ||
127 | |||
128 | // /// <summary> | ||
129 | // /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
130 | // /// an account exists with the same name as the creator, though not the same id. | ||
131 | // /// </summary> | ||
132 | // [Test] | ||
133 | // public void TestLoadIarV0_1SameNameCreator() | ||
134 | // { | ||
135 | // TestHelpers.InMethod(); | ||
136 | // TestHelpers.EnableLogging(); | ||
137 | // | ||
138 | // UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaMT, "meowfood"); | ||
139 | // UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaLL2, "hampshire"); | ||
140 | // | ||
141 | // m_archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream); | ||
142 | // InventoryItemBase foundItem1 | ||
143 | // = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); | ||
144 | // | ||
145 | // Assert.That( | ||
146 | // foundItem1.CreatorId, Is.EqualTo(m_uaLL2.PrincipalID.ToString()), | ||
147 | // "Loaded item non-uuid creator doesn't match original"); | ||
148 | // Assert.That( | ||
149 | // foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL2.PrincipalID), | ||
150 | // "Loaded item uuid creator doesn't match original"); | ||
151 | // Assert.That(foundItem1.Owner, Is.EqualTo(m_uaMT.PrincipalID), | ||
152 | // "Loaded item owner doesn't match inventory reciever"); | ||
153 | // | ||
154 | // AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
155 | // string xmlData = Utils.BytesToString(asset1.Data); | ||
156 | // SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
157 | // | ||
158 | // Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL2.PrincipalID)); | ||
159 | // } | ||
160 | |||
161 | /// <summary> | ||
162 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
163 | /// the creator or an account with the creator's name does not exist within the system. | ||
164 | /// </summary> | ||
165 | [Test] | ||
166 | public void TestLoadIarV0_1AbsentCreator() | ||
167 | { | ||
168 | TestHelpers.InMethod(); | ||
169 | // log4net.Config.XmlConfigurator.Configure(); | ||
170 | |||
171 | UserAccountHelpers.CreateUserWithInventory(m_scene, m_uaMT, "password"); | ||
172 | m_archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/", "password", m_iarStream); | ||
173 | |||
174 | InventoryItemBase foundItem1 | ||
175 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); | ||
176 | |||
177 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
178 | Assert.That( | ||
179 | foundItem1.CreatorId, Is.EqualTo(m_uaMT.PrincipalID.ToString()), | ||
180 | "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
181 | Assert.That( | ||
182 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaMT.PrincipalID), | ||
183 | "Loaded item uuid creator doesn't match that of the loading user"); | ||
184 | |||
185 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); | ||
186 | string xmlData = Utils.BytesToString(asset1.Data); | ||
187 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
188 | |||
189 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaMT.PrincipalID)); | ||
190 | } | ||
191 | } | ||
192 | } \ No newline at end of file | ||