diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs new file mode 100644 index 0000000..c76a30a --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | |||
@@ -0,0 +1,220 @@ | |||
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 Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization; | ||
39 | using OpenSim.Framework.Serialization.External; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | ||
42 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | using OpenSim.Tests.Common.Setup; | ||
49 | |||
50 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | ||
51 | { | ||
52 | [TestFixture] | ||
53 | public class InventoryAccessModuleTests | ||
54 | { | ||
55 | protected TestScene m_scene; | ||
56 | protected BasicInventoryAccessModule m_iam; | ||
57 | protected UUID m_userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
58 | protected TestClient m_tc; | ||
59 | |||
60 | [SetUp] | ||
61 | public void SetUp() | ||
62 | { | ||
63 | m_iam = new BasicInventoryAccessModule(); | ||
64 | |||
65 | IConfigSource config = new IniConfigSource(); | ||
66 | config.AddConfig("Modules"); | ||
67 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
68 | |||
69 | m_scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
70 | SceneSetupHelpers.SetupSceneModules(m_scene, config, m_iam); | ||
71 | |||
72 | // Create user | ||
73 | string userFirstName = "Jock"; | ||
74 | string userLastName = "Stirrup"; | ||
75 | string userPassword = "troll"; | ||
76 | UserProfileTestUtils.CreateUserWithInventory(m_scene, userFirstName, userLastName, m_userId, userPassword); | ||
77 | |||
78 | AgentCircuitData acd = new AgentCircuitData(); | ||
79 | acd.AgentID = m_userId; | ||
80 | m_tc = new TestClient(acd, m_scene); | ||
81 | } | ||
82 | |||
83 | [Test] | ||
84 | public void TestRezCoalescedObject() | ||
85 | { | ||
86 | TestHelper.InMethod(); | ||
87 | // log4net.Config.XmlConfigurator.Configure(); | ||
88 | |||
89 | // Create asset | ||
90 | SceneObjectGroup object1; | ||
91 | { | ||
92 | string partName = "Object1"; | ||
93 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
94 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
95 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
96 | Quaternion rotationOffset = Quaternion.Identity; | ||
97 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
98 | |||
99 | SceneObjectPart part1 | ||
100 | = new SceneObjectPart( | ||
101 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
102 | part1.Scale = new Vector3(1, 1, 1); | ||
103 | part1.Name = partName; | ||
104 | |||
105 | object1 = new SceneObjectGroup(part1); | ||
106 | } | ||
107 | |||
108 | SceneObjectGroup object2; | ||
109 | { | ||
110 | string partName = "Object2"; | ||
111 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
112 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
113 | Vector3 groupPosition = new Vector3(20, 40, 60); | ||
114 | Quaternion rotationOffset = Quaternion.Identity; | ||
115 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
116 | |||
117 | SceneObjectPart part1 | ||
118 | = new SceneObjectPart( | ||
119 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
120 | part1.Scale = new Vector3(1, 1, 1); | ||
121 | part1.Name = partName; | ||
122 | |||
123 | object2 = new SceneObjectGroup(part1); | ||
124 | } | ||
125 | |||
126 | CoalescedSceneObjects coa = new CoalescedSceneObjects(m_userId, object1, object2); | ||
127 | |||
128 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
129 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, coa); | ||
130 | m_scene.AssetService.Store(asset1); | ||
131 | |||
132 | // Create item | ||
133 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
134 | string item1Name = "My Little Dog"; | ||
135 | InventoryItemBase item1 = new InventoryItemBase(); | ||
136 | item1.Name = item1Name; | ||
137 | item1.AssetID = asset1.FullID; | ||
138 | item1.ID = item1Id; | ||
139 | InventoryFolderBase objsFolder | ||
140 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; | ||
141 | item1.Folder = objsFolder.ID; | ||
142 | m_scene.AddInventoryItem(item1); | ||
143 | |||
144 | SceneObjectGroup so | ||
145 | = m_iam.RezObject( | ||
146 | m_tc, item1Id, new Vector3(100, 100, 100), Vector3.Zero, UUID.Zero, 1, false, false, false, UUID.Zero, false); | ||
147 | |||
148 | Assert.That(so, Is.Not.Null); | ||
149 | |||
150 | Assert.That(m_scene.SceneGraph.GetTotalObjectsCount(), Is.EqualTo(2)); | ||
151 | |||
152 | SceneObjectPart retrievedObj1Part = m_scene.GetSceneObjectPart(object1.Name); | ||
153 | Assert.That(retrievedObj1Part, Is.Null); | ||
154 | |||
155 | retrievedObj1Part = m_scene.GetSceneObjectPart(item1.Name); | ||
156 | Assert.That(retrievedObj1Part, Is.Not.Null); | ||
157 | Assert.That(retrievedObj1Part.Name, Is.EqualTo(item1.Name)); | ||
158 | |||
159 | // Bottom of coalescence is placed on ground, hence we end up with 100.5 rather than 85 since the bottom | ||
160 | // object is unit square. | ||
161 | Assert.That(retrievedObj1Part.AbsolutePosition, Is.EqualTo(new Vector3(95, 90, 100.5f))); | ||
162 | |||
163 | SceneObjectPart retrievedObj2Part = m_scene.GetSceneObjectPart(object2.Name); | ||
164 | Assert.That(retrievedObj2Part, Is.Not.Null); | ||
165 | Assert.That(retrievedObj2Part.Name, Is.EqualTo(object2.Name)); | ||
166 | Assert.That(retrievedObj2Part.AbsolutePosition, Is.EqualTo(new Vector3(105, 110, 130.5f))); | ||
167 | } | ||
168 | |||
169 | [Test] | ||
170 | public void TestRezObject() | ||
171 | { | ||
172 | TestHelper.InMethod(); | ||
173 | // log4net.Config.XmlConfigurator.Configure(); | ||
174 | |||
175 | // Create asset | ||
176 | SceneObjectGroup object1; | ||
177 | SceneObjectPart part1; | ||
178 | { | ||
179 | string partName = "My Little Dog Object"; | ||
180 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
181 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
182 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
183 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
184 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
185 | |||
186 | part1 | ||
187 | = new SceneObjectPart( | ||
188 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
189 | part1.Name = partName; | ||
190 | |||
191 | object1 = new SceneObjectGroup(part1); | ||
192 | } | ||
193 | |||
194 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
195 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
196 | m_scene.AssetService.Store(asset1); | ||
197 | |||
198 | // Create item | ||
199 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
200 | string item1Name = "My Little Dog"; | ||
201 | InventoryItemBase item1 = new InventoryItemBase(); | ||
202 | item1.Name = item1Name; | ||
203 | item1.AssetID = asset1.FullID; | ||
204 | item1.ID = item1Id; | ||
205 | InventoryFolderBase objsFolder | ||
206 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; | ||
207 | item1.Folder = objsFolder.ID; | ||
208 | m_scene.AddInventoryItem(item1); | ||
209 | |||
210 | SceneObjectGroup so | ||
211 | = m_iam.RezObject( | ||
212 | m_tc, item1Id, Vector3.Zero, Vector3.Zero, UUID.Zero, 1, false, false, false, UUID.Zero, false); | ||
213 | |||
214 | Assert.That(so, Is.Not.Null); | ||
215 | |||
216 | SceneObjectPart retrievedPart = m_scene.GetSceneObjectPart(so.UUID); | ||
217 | Assert.That(retrievedPart, Is.Not.Null); | ||
218 | } | ||
219 | } | ||
220 | } \ No newline at end of file | ||