OSSL_ApiAttachmentTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 log4net;
  32. using Nini.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Assets;
  36. using OpenMetaverse.StructuredData;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.CoreModules.Avatar.Attachments;
  39. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.ScriptEngine.Shared;
  42. using OpenSim.Region.ScriptEngine.Shared.Api;
  43. using OpenSim.Region.ScriptEngine.Shared.Instance;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Tests.Common;
  46. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  47. {
  48. /// <summary>
  49. /// Tests for OSSL attachment functions
  50. /// </summary>
  51. /// <remarks>
  52. /// TODO: Add tests for all functions
  53. /// </remarks>
  54. [TestFixture]
  55. public class OSSL_ApiAttachmentTests : OpenSimTestCase
  56. {
  57. protected Scene m_scene;
  58. protected XEngine.XEngine m_engine;
  59. [SetUp]
  60. public override void SetUp()
  61. {
  62. base.SetUp();
  63. IConfigSource initConfigSource = new IniConfigSource();
  64. IConfig xengineConfig = initConfigSource.AddConfig("XEngine");
  65. xengineConfig.Set("Enabled", "true");
  66. IConfig oconfig = initConfigSource.AddConfig("OSSL");
  67. oconfig.Set("DebuggerSafe", false);
  68. oconfig.Set("AllowOSFunctions", "true");
  69. oconfig.Set("OSFunctionThreatLevel", "Severe");
  70. IConfig modulesConfig = initConfigSource.AddConfig("Modules");
  71. modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
  72. m_scene = new SceneHelpers().SetupScene();
  73. SceneHelpers.SetupSceneModules(
  74. m_scene, initConfigSource, new AttachmentsModule(), new BasicInventoryAccessModule());
  75. m_engine = new XEngine.XEngine();
  76. m_engine.Initialise(initConfigSource);
  77. m_engine.AddRegion(m_scene);
  78. }
  79. [Test]
  80. public void TestOsForceAttachToAvatarFromInventory()
  81. {
  82. TestHelpers.InMethod();
  83. // TestHelpers.EnableLogging();
  84. string taskInvObjItemName = "sphere";
  85. UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
  86. AttachmentPoint attachPoint = AttachmentPoint.Chin;
  87. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
  88. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
  89. SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
  90. TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene.AssetService, inWorldObj.RootPart);
  91. new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  92. OSSL_Api osslApi = new OSSL_Api();
  93. osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  94. // SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID);
  95. // Create an object embedded inside the first
  96. TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
  97. osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
  98. // Check scene presence status
  99. Assert.That(sp.HasAttachments(), Is.True);
  100. List<SceneObjectGroup> attachments = sp.GetAttachments();
  101. Assert.That(attachments.Count, Is.EqualTo(1));
  102. SceneObjectGroup attSo = attachments[0];
  103. Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
  104. Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
  105. Assert.That(attSo.IsAttachment);
  106. Assert.That(attSo.UsesPhysics, Is.False);
  107. Assert.That(attSo.IsTemporary, Is.False);
  108. // Check appearance status
  109. List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
  110. Assert.That(attachmentsInAppearance.Count, Is.EqualTo(1));
  111. Assert.That(sp.Appearance.GetAttachpoint(attachmentsInAppearance[0].ItemID), Is.EqualTo((uint)attachPoint));
  112. }
  113. /// <summary>
  114. /// Make sure we can't force attach anything other than objects.
  115. /// </summary>
  116. [Test]
  117. public void TestOsForceAttachToAvatarFromInventoryNotObject()
  118. {
  119. TestHelpers.InMethod();
  120. // TestHelpers.EnableLogging();
  121. string taskInvObjItemName = "sphere";
  122. UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
  123. AttachmentPoint attachPoint = AttachmentPoint.Chin;
  124. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
  125. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
  126. SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
  127. TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene.AssetService, inWorldObj.RootPart);
  128. new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  129. OSSL_Api osslApi = new OSSL_Api();
  130. osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  131. // Create an object embedded inside the first
  132. TaskInventoryHelpers.AddNotecard(
  133. m_scene.AssetService, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, TestHelpers.ParseTail(0x900), "Hello World!");
  134. bool exceptionCaught = false;
  135. try
  136. {
  137. osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
  138. }
  139. catch (Exception)
  140. {
  141. exceptionCaught = true;
  142. }
  143. Assert.That(exceptionCaught, Is.True);
  144. // Check scene presence status
  145. Assert.That(sp.HasAttachments(), Is.False);
  146. List<SceneObjectGroup> attachments = sp.GetAttachments();
  147. Assert.That(attachments.Count, Is.EqualTo(0));
  148. // Check appearance status
  149. List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
  150. Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
  151. }
  152. [Test]
  153. public void TestOsForceAttachToOtherAvatarFromInventory()
  154. {
  155. TestHelpers.InMethod();
  156. // TestHelpers.EnableLogging();
  157. string taskInvObjItemName = "sphere";
  158. UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
  159. AttachmentPoint attachPoint = AttachmentPoint.Chin;
  160. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "one", 0x1, "pass");
  161. UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "two", 0x2, "pass");
  162. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);
  163. SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
  164. TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene.AssetService, inWorldObj.RootPart);
  165. new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  166. OSSL_Api osslApi = new OSSL_Api();
  167. osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
  168. // Create an object embedded inside the first
  169. TaskInventoryHelpers.AddSceneObject(
  170. m_scene.AssetService, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
  171. ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2);
  172. osslApi.osForceAttachToOtherAvatarFromInventory(sp2.UUID.ToString(), taskInvObjItemName, (int)attachPoint);
  173. // Check scene presence status
  174. Assert.That(sp.HasAttachments(), Is.False);
  175. List<SceneObjectGroup> attachments = sp.GetAttachments();
  176. Assert.That(attachments.Count, Is.EqualTo(0));
  177. Assert.That(sp2.HasAttachments(), Is.True);
  178. List<SceneObjectGroup> attachments2 = sp2.GetAttachments();
  179. Assert.That(attachments2.Count, Is.EqualTo(1));
  180. SceneObjectGroup attSo = attachments2[0];
  181. Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
  182. Assert.That(attSo.OwnerID, Is.EqualTo(ua2.PrincipalID));
  183. Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
  184. Assert.That(attSo.IsAttachment);
  185. Assert.That(attSo.UsesPhysics, Is.False);
  186. Assert.That(attSo.IsTemporary, Is.False);
  187. // Check appearance status
  188. List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
  189. Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
  190. List<AvatarAttachment> attachmentsInAppearance2 = sp2.Appearance.GetAttachments();
  191. Assert.That(attachmentsInAppearance2.Count, Is.EqualTo(1));
  192. Assert.That(sp2.Appearance.GetAttachpoint(attachmentsInAppearance2[0].ItemID), Is.EqualTo((uint)attachPoint));
  193. }
  194. }
  195. }