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