1
0

LSL_ApiAvatarTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.ScriptBase;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Tests.Common;
  46. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  47. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  48. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  49. {
  50. /// <summary>
  51. /// Tests relating directly to avatars
  52. /// </summary>
  53. [TestFixture]
  54. public class LSL_ApiAvatarTests : OpenSimTestCase
  55. {
  56. /*
  57. protected Scene m_scene;
  58. [SetUp]
  59. public override void SetUp()
  60. {
  61. base.SetUp();
  62. IConfigSource initConfigSource = new IniConfigSource();
  63. IConfig config = initConfigSource.AddConfig("XEngine");
  64. config.Set("Enabled", "true");
  65. config = initConfigSource.AddConfig("OSSL");
  66. config.Set("DebuggerSafe", false);
  67. config.Set("AllowOSFunctions", "true");
  68. config.Set("OSFunctionThreatLevel", "Severe");
  69. m_scene = new SceneHelpers().SetupScene();
  70. SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
  71. m_engine = new YEngine.XEngine();
  72. m_engine.Initialise(initConfigSource);
  73. m_engine.AddRegion(m_scene);
  74. }
  75. /// <summary>
  76. /// Test llSetLinkPrimtiveParams for agents.
  77. /// </summary>
  78. /// <remarks>
  79. /// Also testing entity updates here as well. Possibly that's putting 2 different concerns into one test and
  80. /// this should be separated.
  81. /// </remarks>
  82. [Test]
  83. public void TestllSetLinkPrimitiveParamsForAgent()
  84. {
  85. /* siting avatars position changed
  86. TestHelpers.InMethod();
  87. // TestHelpers.EnableLogging();
  88. UUID userId = TestHelpers.ParseTail(0x1);
  89. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  90. part.RotationOffset = new Quaternion(0.7071068f, 0, 0, 0.7071068f);
  91. LSL_Api apiGrp1 = new LSL_Api();
  92. apiGrp1.Initialize(m_engine, part, null);
  93. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  94. // sp has to be less than 10 meters away from 0, 0, 0 (default part position)
  95. Vector3 startPos = new Vector3(3, 2, 1);
  96. sp.AbsolutePosition = startPos;
  97. sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero);
  98. int entityUpdates = 0;
  99. ((TestClient)sp.ControllingClient).OnReceivedEntityUpdate += (entity, flags) => { if (entity is ScenePresence) { entityUpdates++; }};
  100. // Test position
  101. {
  102. Vector3 newPos = new Vector3(1, 2, 3);
  103. apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
  104. Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
  105. m_scene.Update(1);
  106. Assert.That(entityUpdates, Is.EqualTo(1));
  107. }
  108. // Test small reposition
  109. {
  110. Vector3 newPos = new Vector3(1.001f, 2, 3);
  111. apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
  112. Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
  113. m_scene.Update(1);
  114. Assert.That(entityUpdates, Is.EqualTo(2));
  115. }
  116. // Test world rotation
  117. {
  118. Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
  119. apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROTATION, newRot));
  120. Assert.That(
  121. sp.Rotation, new QuaternionToleranceConstraint(part.GetWorldRotation() * newRot, 0.000001));
  122. m_scene.Update(1);
  123. Assert.That(entityUpdates, Is.EqualTo(3));
  124. }
  125. // Test local rotation
  126. {
  127. Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
  128. apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROT_LOCAL, newRot));
  129. Assert.That(
  130. sp.Rotation, new QuaternionToleranceConstraint(newRot, 0.000001));
  131. m_scene.Update(1);
  132. Assert.That(entityUpdates, Is.EqualTo(4));
  133. }
  134. }
  135. */
  136. }
  137. }