diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs new file mode 100644 index 0000000..855b589 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs | |||
@@ -0,0 +1,173 @@ | |||
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 System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Tests.Common; | ||
45 | using OpenSim.Tests.Common.Mock; | ||
46 | using OpenSim.Tests.Common.Setup; | ||
47 | |||
48 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// Attachment tests | ||
52 | /// </summary> | ||
53 | [TestFixture] | ||
54 | public class AttachmentTests | ||
55 | { | ||
56 | public Scene scene, scene2; | ||
57 | public UUID agent1; | ||
58 | public static Random random; | ||
59 | public ulong region1, region2; | ||
60 | public AgentCircuitData acd1; | ||
61 | public SceneObjectGroup sog1, sog2, sog3; | ||
62 | |||
63 | [TestFixtureSetUp] | ||
64 | public void Init() | ||
65 | { | ||
66 | TestHelper.InMethod(); | ||
67 | |||
68 | scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000); | ||
69 | scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000); | ||
70 | |||
71 | ISharedRegionModule interregionComms = new LocalSimulationConnectorModule(); | ||
72 | interregionComms.Initialise(new IniConfigSource()); | ||
73 | interregionComms.PostInitialise(); | ||
74 | SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms); | ||
75 | SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms); | ||
76 | |||
77 | agent1 = UUID.Random(); | ||
78 | random = new Random(); | ||
79 | sog1 = NewSOG(UUID.Random(), scene, agent1); | ||
80 | sog2 = NewSOG(UUID.Random(), scene, agent1); | ||
81 | sog3 = NewSOG(UUID.Random(), scene, agent1); | ||
82 | |||
83 | //ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize)); | ||
84 | region1 = scene.RegionInfo.RegionHandle; | ||
85 | region2 = scene2.RegionInfo.RegionHandle; | ||
86 | |||
87 | SceneSetupHelpers.AddRootAgent(scene, agent1); | ||
88 | } | ||
89 | |||
90 | [Test] | ||
91 | public void T030_TestAddAttachments() | ||
92 | { | ||
93 | TestHelper.InMethod(); | ||
94 | |||
95 | ScenePresence presence = scene.GetScenePresence(agent1); | ||
96 | |||
97 | presence.AddAttachment(sog1); | ||
98 | presence.AddAttachment(sog2); | ||
99 | presence.AddAttachment(sog3); | ||
100 | |||
101 | Assert.That(presence.HasAttachments(), Is.True); | ||
102 | Assert.That(presence.ValidateAttachments(), Is.True); | ||
103 | } | ||
104 | |||
105 | [Test] | ||
106 | public void T031_RemoveAttachments() | ||
107 | { | ||
108 | TestHelper.InMethod(); | ||
109 | |||
110 | ScenePresence presence = scene.GetScenePresence(agent1); | ||
111 | presence.RemoveAttachment(sog1); | ||
112 | presence.RemoveAttachment(sog2); | ||
113 | presence.RemoveAttachment(sog3); | ||
114 | Assert.That(presence.HasAttachments(), Is.False); | ||
115 | } | ||
116 | |||
117 | // I'm commenting this test because scene setup NEEDS InventoryService to | ||
118 | // be non-null | ||
119 | //[Test] | ||
120 | public void T032_CrossAttachments() | ||
121 | { | ||
122 | TestHelper.InMethod(); | ||
123 | |||
124 | ScenePresence presence = scene.GetScenePresence(agent1); | ||
125 | ScenePresence presence2 = scene2.GetScenePresence(agent1); | ||
126 | presence2.AddAttachment(sog1); | ||
127 | presence2.AddAttachment(sog2); | ||
128 | |||
129 | ISharedRegionModule serialiser = new SerialiserModule(); | ||
130 | SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser); | ||
131 | SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser); | ||
132 | |||
133 | Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross"); | ||
134 | |||
135 | //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); | ||
136 | Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); | ||
137 | Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); | ||
138 | } | ||
139 | |||
140 | private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent) | ||
141 | { | ||
142 | SceneObjectPart sop = new SceneObjectPart(); | ||
143 | sop.Name = RandomName(); | ||
144 | sop.Description = RandomName(); | ||
145 | sop.Text = RandomName(); | ||
146 | sop.SitName = RandomName(); | ||
147 | sop.TouchName = RandomName(); | ||
148 | sop.UUID = uuid; | ||
149 | sop.Shape = PrimitiveBaseShape.Default; | ||
150 | sop.Shape.State = 1; | ||
151 | sop.OwnerID = agent; | ||
152 | |||
153 | SceneObjectGroup sog = new SceneObjectGroup(sop); | ||
154 | sog.SetScene(scene); | ||
155 | |||
156 | return sog; | ||
157 | } | ||
158 | |||
159 | private static string RandomName() | ||
160 | { | ||
161 | StringBuilder name = new StringBuilder(); | ||
162 | int size = random.Next(5,12); | ||
163 | char ch; | ||
164 | for (int i = 0; i < size; i++) | ||
165 | { | ||
166 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
167 | name.Append(ch); | ||
168 | } | ||
169 | |||
170 | return name.ToString(); | ||
171 | } | ||
172 | } | ||
173 | } \ No newline at end of file | ||