opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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.Reflection; |
||
31 | using System.Text; |
||
32 | using log4net; |
||
33 | using Nini.Config; |
||
34 | using NUnit.Framework; |
||
35 | using OpenMetaverse; |
||
36 | using OpenMetaverse.Assets; |
||
37 | using OpenMetaverse.StructuredData; |
||
38 | using OpenSim.Framework; |
||
39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
||
40 | using OpenSim.Region.OptionalModules.World.NPC; |
||
41 | using OpenSim.Region.Framework.Scenes; |
||
42 | using OpenSim.Region.ScriptEngine.Shared; |
||
43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
||
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; |
||
45 | using OpenSim.Services.Interfaces; |
||
46 | using OpenSim.Tests.Common; |
||
47 | using OpenSim.Tests.Common.Mock; |
||
48 | |||
49 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
||
50 | { |
||
51 | /// <summary> |
||
52 | /// Tests for inventory functions in LSL |
||
53 | /// </summary> |
||
54 | [TestFixture] |
||
55 | public class LSL_ApiInventoryTests : OpenSimTestCase |
||
56 | { |
||
57 | protected Scene m_scene; |
||
58 | protected XEngine.XEngine m_engine; |
||
59 | |||
60 | [SetUp] |
||
61 | public override void SetUp() |
||
62 | { |
||
63 | base.SetUp(); |
||
64 | |||
65 | IConfigSource initConfigSource = new IniConfigSource(); |
||
66 | IConfig config = initConfigSource.AddConfig("XEngine"); |
||
67 | config.Set("Enabled", "true"); |
||
68 | |||
69 | m_scene = new SceneHelpers().SetupScene(); |
||
70 | SceneHelpers.SetupSceneModules(m_scene, initConfigSource); |
||
71 | |||
72 | m_engine = new XEngine.XEngine(); |
||
73 | m_engine.Initialise(initConfigSource); |
||
74 | m_engine.AddRegion(m_scene); |
||
75 | } |
||
76 | |||
77 | /// <summary> |
||
78 | /// Test giving inventory from an object to an object where both are owned by the same user. |
||
79 | /// </summary> |
||
80 | [Test] |
||
81 | public void TestLlGiveInventoryO2OSameOwner() |
||
82 | { |
||
83 | TestHelpers.InMethod(); |
||
84 | // log4net.Config.XmlConfigurator.Configure(); |
||
85 | |||
86 | UUID userId = TestHelpers.ParseTail(0x1); |
||
87 | string inventoryItemName = "item1"; |
||
88 | |||
89 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId, "so1", 0x10); |
||
90 | m_scene.AddSceneObject(so1); |
||
91 | |||
92 | // Create an object embedded inside the first |
||
93 | UUID itemId = TestHelpers.ParseTail(0x20); |
||
94 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); |
||
95 | |||
96 | LSL_Api api = new LSL_Api(); |
||
97 | api.Initialize(m_engine, so1.RootPart, null, null); |
||
98 | |||
99 | // Create a second object |
||
100 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); |
||
101 | m_scene.AddSceneObject(so2); |
||
102 | |||
103 | api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); |
||
104 | |||
105 | // Item has copy permissions so original should stay intact. |
||
106 | List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems(); |
||
107 | Assert.That(originalItems.Count, Is.EqualTo(1)); |
||
108 | |||
109 | List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); |
||
110 | Assert.That(copiedItems.Count, Is.EqualTo(1)); |
||
111 | Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); |
||
112 | } |
||
113 | |||
114 | /// <summary> |
||
115 | /// Test giving inventory from an object to an object where they have different owners |
||
116 | /// </summary> |
||
117 | [Test] |
||
118 | public void TestLlGiveInventoryO2ODifferentOwners() |
||
119 | { |
||
120 | TestHelpers.InMethod(); |
||
121 | // log4net.Config.XmlConfigurator.Configure(); |
||
122 | |||
123 | UUID user1Id = TestHelpers.ParseTail(0x1); |
||
124 | UUID user2Id = TestHelpers.ParseTail(0x2); |
||
125 | string inventoryItemName = "item1"; |
||
126 | |||
127 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); |
||
128 | m_scene.AddSceneObject(so1); |
||
129 | LSL_Api api = new LSL_Api(); |
||
130 | api.Initialize(m_engine, so1.RootPart, null, null); |
||
131 | |||
132 | // Create an object embedded inside the first |
||
133 | UUID itemId = TestHelpers.ParseTail(0x20); |
||
134 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, user1Id); |
||
135 | |||
136 | // Create a second object |
||
137 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); |
||
138 | m_scene.AddSceneObject(so2); |
||
139 | LSL_Api api2 = new LSL_Api(); |
||
140 | api2.Initialize(m_engine, so2.RootPart, null, null); |
||
141 | |||
142 | // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** |
||
143 | api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); |
||
144 | |||
145 | { |
||
146 | // Item has copy permissions so original should stay intact. |
||
147 | List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems(); |
||
148 | Assert.That(originalItems.Count, Is.EqualTo(1)); |
||
149 | |||
150 | // Should have not copied |
||
151 | List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); |
||
152 | Assert.That(copiedItems.Count, Is.EqualTo(0)); |
||
153 | } |
||
154 | |||
155 | // *** Secondly, we turn on allow inventory drop in the target and retest. *** |
||
156 | api2.llAllowInventoryDrop(1); |
||
157 | api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); |
||
158 | |||
159 | { |
||
160 | // Item has copy permissions so original should stay intact. |
||
161 | List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems(); |
||
162 | Assert.That(originalItems.Count, Is.EqualTo(1)); |
||
163 | |||
164 | // Should now have copied. |
||
165 | List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName); |
||
166 | Assert.That(copiedItems.Count, Is.EqualTo(1)); |
||
167 | Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | } |