LSL_ApiLinkingTests.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.AvatarFactory;
  39. using OpenSim.Region.OptionalModules.World.NPC;
  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.Region.ScriptEngine.Shared.ScriptBase;
  45. using OpenSim.Services.Interfaces;
  46. using OpenSim.Tests.Common;
  47. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  48. {
  49. /// <summary>
  50. /// Tests for linking functions in LSL
  51. /// </summary>
  52. /// <remarks>
  53. /// This relates to LSL. Actual linking functionality should be tested in the main
  54. /// OpenSim.Region.Framework.Scenes.Tests.SceneObjectLinkingTests.
  55. /// </remarks>
  56. [TestFixture]
  57. public class LSL_ApiLinkingTests : OpenSimTestCase
  58. {
  59. protected Scene m_scene;
  60. protected XEngine.XEngine m_engine;
  61. [SetUp]
  62. public override void SetUp()
  63. {
  64. base.SetUp();
  65. IConfigSource initConfigSource = new IniConfigSource();
  66. IConfig config = initConfigSource.AddConfig("XEngine");
  67. config.Set("Enabled", "true");
  68. config = initConfigSource.AddConfig("OSSL");
  69. config.Set("DebuggerSafe", false);
  70. config.Set("AllowOSFunctions", "true");
  71. config.Set("OSFunctionThreatLevel", "Severe");
  72. m_scene = new SceneHelpers().SetupScene();
  73. SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
  74. m_engine = new XEngine.XEngine();
  75. m_engine.Initialise(initConfigSource);
  76. m_engine.AddRegion(m_scene);
  77. }
  78. [Test]
  79. public void TestllCreateLink()
  80. {
  81. TestHelpers.InMethod();
  82. UUID ownerId = TestHelpers.ParseTail(0x1);
  83. SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
  84. grp1.AbsolutePosition = new Vector3(10, 10, 10);
  85. m_scene.AddSceneObject(grp1);
  86. // FIXME: This should really be a script item (with accompanying script)
  87. TaskInventoryItem grp1Item
  88. = TaskInventoryHelpers.AddNotecard(
  89. m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
  90. grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  91. SceneObjectGroup grp2 = SceneHelpers.CreateSceneObject(2, ownerId, "grp2-", 0x20);
  92. grp2.AbsolutePosition = new Vector3(20, 20, 20);
  93. // <180,0,0>
  94. grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
  95. m_scene.AddSceneObject(grp2);
  96. LSL_Api apiGrp1 = new LSL_Api();
  97. apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
  98. apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
  99. Assert.That(grp1.Parts.Length, Is.EqualTo(4));
  100. Assert.That(grp2.IsDeleted, Is.True);
  101. }
  102. [Test]
  103. public void TestllBreakLink()
  104. {
  105. TestHelpers.InMethod();
  106. UUID ownerId = TestHelpers.ParseTail(0x1);
  107. SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
  108. grp1.AbsolutePosition = new Vector3(10, 10, 10);
  109. m_scene.AddSceneObject(grp1);
  110. // FIXME: This should really be a script item (with accompanying script)
  111. TaskInventoryItem grp1Item
  112. = TaskInventoryHelpers.AddNotecard(
  113. m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
  114. grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  115. LSL_Api apiGrp1 = new LSL_Api();
  116. apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
  117. apiGrp1.llBreakLink(2);
  118. Assert.That(grp1.Parts.Length, Is.EqualTo(1));
  119. SceneObjectGroup grp2 = m_scene.GetSceneObjectGroup("grp1-Part1");
  120. Assert.That(grp2, Is.Not.Null);
  121. }
  122. [Test]
  123. public void TestllBreakAllLinks()
  124. {
  125. TestHelpers.InMethod();
  126. UUID ownerId = TestHelpers.ParseTail(0x1);
  127. SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(3, ownerId, "grp1-", 0x10);
  128. grp1.AbsolutePosition = new Vector3(10, 10, 10);
  129. m_scene.AddSceneObject(grp1);
  130. // FIXME: This should really be a script item (with accompanying script)
  131. TaskInventoryItem grp1Item
  132. = TaskInventoryHelpers.AddNotecard(
  133. m_scene.AssetService, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900), "Hello World!");
  134. grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  135. LSL_Api apiGrp1 = new LSL_Api();
  136. apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
  137. apiGrp1.llBreakAllLinks();
  138. {
  139. SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part1");
  140. Assert.That(nowGrp, Is.Not.Null);
  141. Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
  142. }
  143. {
  144. SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part2");
  145. Assert.That(nowGrp, Is.Not.Null);
  146. Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
  147. }
  148. {
  149. SceneObjectGroup nowGrp = m_scene.GetSceneObjectGroup("grp1-Part3");
  150. Assert.That(nowGrp, Is.Not.Null);
  151. Assert.That(nowGrp.Parts.Length, Is.EqualTo(1));
  152. }
  153. }
  154. }
  155. }