diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs new file mode 100644 index 0000000..5bac4c6 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -0,0 +1,200 @@ | |||
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.CoreModules.Avatar.Attachments; | ||
41 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Region.Framework.Scenes; | ||
45 | using OpenSim.Region.Framework.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// Attachment tests | ||
53 | /// </summary> | ||
54 | [TestFixture] | ||
55 | public class AttachmentsModuleTests | ||
56 | { | ||
57 | public Scene scene; | ||
58 | public UUID agent1; | ||
59 | public static Random random; | ||
60 | public AgentCircuitData acd1; | ||
61 | public SceneObjectGroup sog1, sog2; | ||
62 | |||
63 | [SetUp] | ||
64 | public void Init() | ||
65 | { | ||
66 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
67 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
68 | |||
69 | IConfigSource config = new IniConfigSource(); | ||
70 | config.AddConfig("Modules"); | ||
71 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
72 | |||
73 | scene = SceneHelpers.SetupScene(); | ||
74 | SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule()); | ||
75 | |||
76 | agent1 = UUID.Random(); | ||
77 | random = new Random(); | ||
78 | sog1 = NewSOG(UUID.Random(), scene, agent1); | ||
79 | sog2 = NewSOG(UUID.Random(), scene, agent1); | ||
80 | } | ||
81 | |||
82 | [TearDown] | ||
83 | public void TearDown() | ||
84 | { | ||
85 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
86 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
87 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
88 | } | ||
89 | |||
90 | [Test] | ||
91 | public void TestAddAttachments() | ||
92 | { | ||
93 | TestHelpers.InMethod(); | ||
94 | |||
95 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | ||
96 | presence.AddAttachment(sog1); | ||
97 | presence.AddAttachment(sog2); | ||
98 | |||
99 | Assert.That(presence.HasAttachments(), Is.True); | ||
100 | Assert.That(presence.ValidateAttachments(), Is.True); | ||
101 | } | ||
102 | |||
103 | [Test] | ||
104 | public void TestRemoveAttachments() | ||
105 | { | ||
106 | TestHelpers.InMethod(); | ||
107 | |||
108 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | ||
109 | presence.AddAttachment(sog1); | ||
110 | presence.AddAttachment(sog2); | ||
111 | presence.RemoveAttachment(sog1); | ||
112 | presence.RemoveAttachment(sog2); | ||
113 | Assert.That(presence.HasAttachments(), Is.False); | ||
114 | } | ||
115 | |||
116 | [Test] | ||
117 | public void TestRezAttachmentsOnAvatarEntrance() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // log4net.Config.XmlConfigurator.Configure(); | ||
121 | |||
122 | UUID userId = TestHelpers.ParseTail(0x1); | ||
123 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
124 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
125 | string attName = "att"; | ||
126 | |||
127 | UserAccountHelpers.CreateUserWithInventory(scene, userId); | ||
128 | InventoryItemBase attItem | ||
129 | = UserInventoryHelpers.CreateInventoryItem( | ||
130 | scene, attName, attItemId, attAssetId, userId, InventoryType.Object); | ||
131 | |||
132 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
133 | acd.Appearance = new AvatarAppearance(); | ||
134 | acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID); | ||
135 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd); | ||
136 | |||
137 | Assert.That(presence.HasAttachments(), Is.True); | ||
138 | List<SceneObjectGroup> attachments = presence.Attachments; | ||
139 | |||
140 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
141 | Assert.That(attachments[0].Name, Is.EqualTo(attName)); | ||
142 | } | ||
143 | |||
144 | // I'm commenting this test because scene setup NEEDS InventoryService to | ||
145 | // be non-null | ||
146 | //[Test] | ||
147 | // public void T032_CrossAttachments() | ||
148 | // { | ||
149 | // TestHelpers.InMethod(); | ||
150 | // | ||
151 | // ScenePresence presence = scene.GetScenePresence(agent1); | ||
152 | // ScenePresence presence2 = scene2.GetScenePresence(agent1); | ||
153 | // presence2.AddAttachment(sog1); | ||
154 | // presence2.AddAttachment(sog2); | ||
155 | // | ||
156 | // ISharedRegionModule serialiser = new SerialiserModule(); | ||
157 | // SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser); | ||
158 | // SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser); | ||
159 | // | ||
160 | // Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross"); | ||
161 | // | ||
162 | // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); | ||
163 | // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); | ||
164 | // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); | ||
165 | // } | ||
166 | |||
167 | private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent) | ||
168 | { | ||
169 | SceneObjectPart sop = new SceneObjectPart(); | ||
170 | sop.Name = RandomName(); | ||
171 | sop.Description = RandomName(); | ||
172 | sop.Text = RandomName(); | ||
173 | sop.SitName = RandomName(); | ||
174 | sop.TouchName = RandomName(); | ||
175 | sop.UUID = uuid; | ||
176 | sop.Shape = PrimitiveBaseShape.Default; | ||
177 | sop.Shape.State = 1; | ||
178 | sop.OwnerID = agent; | ||
179 | |||
180 | SceneObjectGroup sog = new SceneObjectGroup(sop); | ||
181 | sog.SetScene(scene); | ||
182 | |||
183 | return sog; | ||
184 | } | ||
185 | |||
186 | private static string RandomName() | ||
187 | { | ||
188 | StringBuilder name = new StringBuilder(); | ||
189 | int size = random.Next(5,12); | ||
190 | char ch; | ||
191 | for (int i = 0; i < size; i++) | ||
192 | { | ||
193 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
194 | name.Append(ch); | ||
195 | } | ||
196 | |||
197 | return name.ToString(); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||