diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 194 |
1 files changed, 134 insertions, 60 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index 5bac4c6..b7d21fd 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -54,11 +54,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
54 | [TestFixture] | 54 | [TestFixture] |
55 | public class AttachmentsModuleTests | 55 | public class AttachmentsModuleTests |
56 | { | 56 | { |
57 | public Scene scene; | 57 | private Scene scene; |
58 | public UUID agent1; | 58 | private AttachmentsModule m_attMod; |
59 | public static Random random; | 59 | private ScenePresence m_presence; |
60 | public AgentCircuitData acd1; | ||
61 | public SceneObjectGroup sog1, sog2; | ||
62 | 60 | ||
63 | [SetUp] | 61 | [SetUp] |
64 | public void Init() | 62 | public void Init() |
@@ -71,12 +69,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
71 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | 69 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); |
72 | 70 | ||
73 | scene = SceneHelpers.SetupScene(); | 71 | scene = SceneHelpers.SetupScene(); |
74 | SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule()); | 72 | m_attMod = new AttachmentsModule(); |
75 | 73 | SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule()); | |
76 | agent1 = UUID.Random(); | ||
77 | random = new Random(); | ||
78 | sog1 = NewSOG(UUID.Random(), scene, agent1); | ||
79 | sog2 = NewSOG(UUID.Random(), scene, agent1); | ||
80 | } | 74 | } |
81 | 75 | ||
82 | [TearDown] | 76 | [TearDown] |
@@ -86,31 +80,139 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
86 | // threads. Possibly, later tests should be rewritten not to worry about such things. | 80 | // threads. Possibly, later tests should be rewritten not to worry about such things. |
87 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | 81 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
88 | } | 82 | } |
89 | 83 | ||
84 | /// <summary> | ||
85 | /// Add the standard presence for a test. | ||
86 | /// </summary> | ||
87 | private void AddPresence() | ||
88 | { | ||
89 | UUID userId = TestHelpers.ParseTail(0x1); | ||
90 | UserAccountHelpers.CreateUserWithInventory(scene, userId); | ||
91 | m_presence = SceneHelpers.AddScenePresence(scene, userId); | ||
92 | } | ||
93 | |||
90 | [Test] | 94 | [Test] |
91 | public void TestAddAttachments() | 95 | public void TestAddAttachmentFromGround() |
92 | { | 96 | { |
93 | TestHelpers.InMethod(); | 97 | TestHelpers.InMethod(); |
98 | // log4net.Config.XmlConfigurator.Configure(); | ||
94 | 99 | ||
95 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | 100 | AddPresence(); |
96 | presence.AddAttachment(sog1); | 101 | string attName = "att"; |
97 | presence.AddAttachment(sog2); | ||
98 | 102 | ||
99 | Assert.That(presence.HasAttachments(), Is.True); | 103 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; |
100 | Assert.That(presence.ValidateAttachments(), Is.True); | 104 | |
105 | m_attMod.AttachObject(m_presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false); | ||
106 | |||
107 | // Check status on scene presence | ||
108 | Assert.That(m_presence.HasAttachments(), Is.True); | ||
109 | List<SceneObjectGroup> attachments = m_presence.Attachments; | ||
110 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
111 | SceneObjectGroup attSo = attachments[0]; | ||
112 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
113 | Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
114 | Assert.That(attSo.IsAttachment); | ||
115 | Assert.That(attSo.UsesPhysics, Is.False); | ||
116 | Assert.That(attSo.IsTemporary, Is.False); | ||
117 | |||
118 | // Check item status | ||
119 | Assert.That(m_presence.Appearance.GetAttachpoint( | ||
120 | attSo.GetFromItemID()), Is.EqualTo((int)AttachmentPoint.Chest)); | ||
101 | } | 121 | } |
102 | 122 | ||
103 | [Test] | 123 | [Test] |
104 | public void TestRemoveAttachments() | 124 | public void TestAddAttachmentFromInventory() |
105 | { | 125 | { |
106 | TestHelpers.InMethod(); | 126 | TestHelpers.InMethod(); |
127 | // log4net.Config.XmlConfigurator.Configure(); | ||
128 | |||
129 | AddPresence(); | ||
107 | 130 | ||
108 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | 131 | UUID attItemId = TestHelpers.ParseTail(0x2); |
109 | presence.AddAttachment(sog1); | 132 | UUID attAssetId = TestHelpers.ParseTail(0x3); |
110 | presence.AddAttachment(sog2); | 133 | string attName = "att"; |
111 | presence.RemoveAttachment(sog1); | 134 | |
112 | presence.RemoveAttachment(sog2); | 135 | InventoryItemBase attItem |
113 | Assert.That(presence.HasAttachments(), Is.False); | 136 | = UserInventoryHelpers.CreateInventoryItem( |
137 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
138 | |||
139 | m_attMod.RezSingleAttachmentFromInventory( | ||
140 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
141 | |||
142 | // Check status on scene presence | ||
143 | Assert.That(m_presence.HasAttachments(), Is.True); | ||
144 | List<SceneObjectGroup> attachments = m_presence.Attachments; | ||
145 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
146 | SceneObjectGroup attSo = attachments[0]; | ||
147 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
148 | Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
149 | Assert.That(attSo.IsAttachment); | ||
150 | Assert.That(attSo.UsesPhysics, Is.False); | ||
151 | Assert.That(attSo.IsTemporary, Is.False); | ||
152 | |||
153 | // Check item status | ||
154 | Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); | ||
155 | } | ||
156 | |||
157 | [Test] | ||
158 | public void TestDetachAttachmentToScene() | ||
159 | { | ||
160 | TestHelpers.InMethod(); | ||
161 | // log4net.Config.XmlConfigurator.Configure(); | ||
162 | |||
163 | AddPresence(); | ||
164 | |||
165 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
166 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
167 | string attName = "att"; | ||
168 | |||
169 | InventoryItemBase attItem | ||
170 | = UserInventoryHelpers.CreateInventoryItem( | ||
171 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
172 | |||
173 | UUID attSoId = m_attMod.RezSingleAttachmentFromInventory( | ||
174 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
175 | m_attMod.DetachSingleAttachmentToGround(attSoId, m_presence.ControllingClient); | ||
176 | |||
177 | // Check status on scene presence | ||
178 | Assert.That(m_presence.HasAttachments(), Is.False); | ||
179 | List<SceneObjectGroup> attachments = m_presence.Attachments; | ||
180 | Assert.That(attachments.Count, Is.EqualTo(0)); | ||
181 | |||
182 | // Check item status | ||
183 | Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null); | ||
184 | |||
185 | // Check object in scene | ||
186 | Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null); | ||
187 | } | ||
188 | |||
189 | [Test] | ||
190 | public void TestDetachAttachmentToInventory() | ||
191 | { | ||
192 | TestHelpers.InMethod(); | ||
193 | // log4net.Config.XmlConfigurator.Configure(); | ||
194 | |||
195 | AddPresence(); | ||
196 | |||
197 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
198 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
199 | string attName = "att"; | ||
200 | |||
201 | InventoryItemBase attItem | ||
202 | = UserInventoryHelpers.CreateInventoryItem( | ||
203 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | ||
204 | |||
205 | m_attMod.RezSingleAttachmentFromInventory( | ||
206 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
207 | m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient); | ||
208 | |||
209 | // Check status on scene presence | ||
210 | Assert.That(m_presence.HasAttachments(), Is.False); | ||
211 | List<SceneObjectGroup> attachments = m_presence.Attachments; | ||
212 | Assert.That(attachments.Count, Is.EqualTo(0)); | ||
213 | |||
214 | // Check item status | ||
215 | Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo(0)); | ||
114 | } | 216 | } |
115 | 217 | ||
116 | [Test] | 218 | [Test] |
@@ -138,7 +240,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
138 | List<SceneObjectGroup> attachments = presence.Attachments; | 240 | List<SceneObjectGroup> attachments = presence.Attachments; |
139 | 241 | ||
140 | Assert.That(attachments.Count, Is.EqualTo(1)); | 242 | Assert.That(attachments.Count, Is.EqualTo(1)); |
141 | Assert.That(attachments[0].Name, Is.EqualTo(attName)); | 243 | SceneObjectGroup attSo = attachments[0]; |
244 | Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
245 | Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); | ||
246 | Assert.That(attSo.IsAttachment); | ||
247 | Assert.That(attSo.UsesPhysics, Is.False); | ||
248 | Assert.That(attSo.IsTemporary, Is.False); | ||
142 | } | 249 | } |
143 | 250 | ||
144 | // I'm commenting this test because scene setup NEEDS InventoryService to | 251 | // I'm commenting this test because scene setup NEEDS InventoryService to |
@@ -162,39 +269,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
162 | // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); | 269 | // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); |
163 | // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); | 270 | // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); |
164 | // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); | 271 | // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); |
165 | // } | 272 | // } |
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 | } | 273 | } |
200 | } \ No newline at end of file | 274 | } \ No newline at end of file |