AttachmentsModuleTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using Timer=System.Timers.Timer;
  34. using Nini.Config;
  35. using NUnit.Framework;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications;
  39. using OpenSim.Region.CoreModules.Avatar.Attachments;
  40. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  41. using OpenSim.Region.CoreModules.World.Serialiser;
  42. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  43. using OpenSim.Region.Framework.Scenes;
  44. using OpenSim.Region.Framework.Interfaces;
  45. using OpenSim.Tests.Common;
  46. using OpenSim.Tests.Common.Mock;
  47. namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
  48. {
  49. /// <summary>
  50. /// Attachment tests
  51. /// </summary>
  52. [TestFixture]
  53. public class AttachmentsModuleTests
  54. {
  55. private Scene scene;
  56. private AttachmentsModule m_attMod;
  57. private ScenePresence m_presence;
  58. [SetUp]
  59. public void Init()
  60. {
  61. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  62. Util.FireAndForgetMethod = FireAndForgetMethod.None;
  63. IConfigSource config = new IniConfigSource();
  64. config.AddConfig("Modules");
  65. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  66. scene = SceneHelpers.SetupScene();
  67. m_attMod = new AttachmentsModule();
  68. SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule());
  69. }
  70. [TearDown]
  71. public void TearDown()
  72. {
  73. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  74. // threads. Possibly, later tests should be rewritten not to worry about such things.
  75. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  76. }
  77. /// <summary>
  78. /// Add the standard presence for a test.
  79. /// </summary>
  80. private void AddPresence()
  81. {
  82. UUID userId = TestHelpers.ParseTail(0x1);
  83. UserAccountHelpers.CreateUserWithInventory(scene, userId);
  84. m_presence = SceneHelpers.AddScenePresence(scene, userId);
  85. }
  86. [Test]
  87. public void TestAddAttachmentFromGround()
  88. {
  89. TestHelpers.InMethod();
  90. // log4net.Config.XmlConfigurator.Configure();
  91. AddPresence();
  92. string attName = "att";
  93. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup;
  94. m_attMod.AttachObject(m_presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false);
  95. // Check status on scene presence
  96. Assert.That(m_presence.HasAttachments(), Is.True);
  97. List<SceneObjectGroup> attachments = m_presence.Attachments;
  98. Assert.That(attachments.Count, Is.EqualTo(1));
  99. SceneObjectGroup attSo = attachments[0];
  100. Assert.That(attSo.Name, Is.EqualTo(attName));
  101. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  102. Assert.That(attSo.IsAttachment);
  103. Assert.That(attSo.UsesPhysics, Is.False);
  104. Assert.That(attSo.IsTemporary, Is.False);
  105. // Check item status
  106. Assert.That(m_presence.Appearance.GetAttachpoint(
  107. attSo.GetFromItemID()), Is.EqualTo((int)AttachmentPoint.Chest));
  108. }
  109. [Test]
  110. public void TestAddAttachmentFromInventory()
  111. {
  112. TestHelpers.InMethod();
  113. // log4net.Config.XmlConfigurator.Configure();
  114. AddPresence();
  115. UUID attItemId = TestHelpers.ParseTail(0x2);
  116. UUID attAssetId = TestHelpers.ParseTail(0x3);
  117. string attName = "att";
  118. UserInventoryHelpers.CreateInventoryItem(
  119. scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
  120. m_attMod.RezSingleAttachmentFromInventory(
  121. m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest);
  122. // Check status on scene presence
  123. Assert.That(m_presence.HasAttachments(), Is.True);
  124. List<SceneObjectGroup> attachments = m_presence.Attachments;
  125. Assert.That(attachments.Count, Is.EqualTo(1));
  126. SceneObjectGroup attSo = attachments[0];
  127. Assert.That(attSo.Name, Is.EqualTo(attName));
  128. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  129. Assert.That(attSo.IsAttachment);
  130. Assert.That(attSo.UsesPhysics, Is.False);
  131. Assert.That(attSo.IsTemporary, Is.False);
  132. // Check item status
  133. Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest));
  134. }
  135. [Test]
  136. public void TestDetachAttachmentToScene()
  137. {
  138. TestHelpers.InMethod();
  139. // log4net.Config.XmlConfigurator.Configure();
  140. AddPresence();
  141. UUID attItemId = TestHelpers.ParseTail(0x2);
  142. UUID attAssetId = TestHelpers.ParseTail(0x3);
  143. string attName = "att";
  144. UserInventoryHelpers.CreateInventoryItem(
  145. scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
  146. UUID attSoId = m_attMod.RezSingleAttachmentFromInventory(
  147. m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest);
  148. m_attMod.DetachSingleAttachmentToGround(attSoId, m_presence.ControllingClient);
  149. // Check status on scene presence
  150. Assert.That(m_presence.HasAttachments(), Is.False);
  151. List<SceneObjectGroup> attachments = m_presence.Attachments;
  152. Assert.That(attachments.Count, Is.EqualTo(0));
  153. // Check item status
  154. Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null);
  155. // Check object in scene
  156. Assert.That(scene.GetSceneObjectGroup("att"), Is.Not.Null);
  157. }
  158. [Test]
  159. public void TestDetachAttachmentToInventory()
  160. {
  161. TestHelpers.InMethod();
  162. // log4net.Config.XmlConfigurator.Configure();
  163. AddPresence();
  164. UUID attItemId = TestHelpers.ParseTail(0x2);
  165. UUID attAssetId = TestHelpers.ParseTail(0x3);
  166. string attName = "att";
  167. UserInventoryHelpers.CreateInventoryItem(
  168. scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
  169. m_attMod.RezSingleAttachmentFromInventory(
  170. m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest);
  171. m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient);
  172. // Check status on scene presence
  173. Assert.That(m_presence.HasAttachments(), Is.False);
  174. List<SceneObjectGroup> attachments = m_presence.Attachments;
  175. Assert.That(attachments.Count, Is.EqualTo(0));
  176. // Check item status
  177. Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo(0));
  178. }
  179. [Test]
  180. public void TestRezAttachmentsOnAvatarEntrance()
  181. {
  182. TestHelpers.InMethod();
  183. // log4net.Config.XmlConfigurator.Configure();
  184. UUID userId = TestHelpers.ParseTail(0x1);
  185. UUID attItemId = TestHelpers.ParseTail(0x2);
  186. UUID attAssetId = TestHelpers.ParseTail(0x3);
  187. string attName = "att";
  188. UserAccountHelpers.CreateUserWithInventory(scene, userId);
  189. InventoryItemBase attItem
  190. = UserInventoryHelpers.CreateInventoryItem(
  191. scene, attName, attItemId, attAssetId, userId, InventoryType.Object);
  192. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  193. acd.Appearance = new AvatarAppearance();
  194. acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
  195. ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
  196. Assert.That(presence.HasAttachments(), Is.True);
  197. List<SceneObjectGroup> attachments = presence.Attachments;
  198. Assert.That(attachments.Count, Is.EqualTo(1));
  199. SceneObjectGroup attSo = attachments[0];
  200. Assert.That(attSo.Name, Is.EqualTo(attName));
  201. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  202. Assert.That(attSo.IsAttachment);
  203. Assert.That(attSo.UsesPhysics, Is.False);
  204. Assert.That(attSo.IsTemporary, Is.False);
  205. }
  206. // I'm commenting this test because scene setup NEEDS InventoryService to
  207. // be non-null
  208. //[Test]
  209. // public void T032_CrossAttachments()
  210. // {
  211. // TestHelpers.InMethod();
  212. //
  213. // ScenePresence presence = scene.GetScenePresence(agent1);
  214. // ScenePresence presence2 = scene2.GetScenePresence(agent1);
  215. // presence2.AddAttachment(sog1);
  216. // presence2.AddAttachment(sog2);
  217. //
  218. // ISharedRegionModule serialiser = new SerialiserModule();
  219. // SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser);
  220. // SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser);
  221. //
  222. // Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
  223. //
  224. // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful");
  225. // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted");
  226. // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects");
  227. // }
  228. }
  229. }