1
0

LSL_ApiObjectTests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. using OpenSim.Tests.Common.Mock;
  48. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  49. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  50. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  51. {
  52. [TestFixture]
  53. public class LSL_ApiObjectTests : OpenSimTestCase
  54. {
  55. private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
  56. private const float FLOAT_ACCURACY = 0.00005f;
  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 config = initConfigSource.AddConfig("XEngine");
  65. config.Set("Enabled", "true");
  66. m_scene = new SceneHelpers().SetupScene();
  67. SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
  68. m_engine = new XEngine.XEngine();
  69. m_engine.Initialise(initConfigSource);
  70. m_engine.AddRegion(m_scene);
  71. }
  72. [Test]
  73. public void TestllGetLinkPrimitiveParams()
  74. {
  75. TestHelpers.InMethod();
  76. TestHelpers.EnableLogging();
  77. UUID ownerId = TestHelpers.ParseTail(0x1);
  78. SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
  79. grp1.AbsolutePosition = new Vector3(10, 11, 12);
  80. m_scene.AddSceneObject(grp1);
  81. LSL_Api apiGrp1 = new LSL_Api();
  82. apiGrp1.Initialize(m_engine, grp1.RootPart, null, null);
  83. // Check simple 1 prim case
  84. {
  85. LSL_List resList
  86. = apiGrp1.llGetLinkPrimitiveParams(1, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
  87. Assert.That(resList.Length, Is.EqualTo(1));
  88. }
  89. // Check 2 prim case
  90. {
  91. LSL_List resList
  92. = apiGrp1.llGetLinkPrimitiveParams(
  93. 1,
  94. new LSL_List(
  95. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
  96. new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
  97. new LSL_Integer(2),
  98. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
  99. Assert.That(resList.Length, Is.EqualTo(2));
  100. }
  101. // Check invalid parameters are ignored
  102. {
  103. LSL_List resList
  104. = apiGrp1.llGetLinkPrimitiveParams(3, new LSL_List(new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
  105. Assert.That(resList.Length, Is.EqualTo(0));
  106. }
  107. // Check all parameters are ignored if an initial bad link is given
  108. {
  109. LSL_List resList
  110. = apiGrp1.llGetLinkPrimitiveParams(
  111. 3,
  112. new LSL_List(
  113. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
  114. new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
  115. new LSL_Integer(1),
  116. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
  117. Assert.That(resList.Length, Is.EqualTo(0));
  118. }
  119. // Check only subsequent parameters are ignored when we hit the first bad link number
  120. {
  121. LSL_List resList
  122. = apiGrp1.llGetLinkPrimitiveParams(
  123. 1,
  124. new LSL_List(
  125. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION),
  126. new LSL_Integer(ScriptBaseClass.PRIM_LINK_TARGET),
  127. new LSL_Integer(3),
  128. new LSL_Integer(ScriptBaseClass.PRIM_ROTATION)));
  129. Assert.That(resList.Length, Is.EqualTo(1));
  130. }
  131. }
  132. [Test]
  133. // llSetPrimitiveParams and llGetPrimitiveParams test.
  134. public void TestllSetPrimitiveParams()
  135. {
  136. TestHelpers.InMethod();
  137. // Create Prim1.
  138. Scene scene = new SceneHelpers().SetupScene();
  139. string obj1Name = "Prim1";
  140. UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
  141. SceneObjectPart part1 =
  142. new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
  143. Vector3.Zero, Quaternion.Identity,
  144. Vector3.Zero) { Name = obj1Name, UUID = objUuid };
  145. Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
  146. LSL_Api apiGrp1 = new LSL_Api();
  147. apiGrp1.Initialize(m_engine, part1, null, null);
  148. // Note that prim hollow check is passed with the other prim params in order to allow the
  149. // specification of a different check value from the prim param. A cylinder, prism, sphere,
  150. // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
  151. // specifies a value of 95% and checks to see if 70% was properly returned.
  152. // Test a sphere.
  153. CheckllSetPrimitiveParams(
  154. apiGrp1,
  155. "test 1", // Prim test identification string
  156. new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
  157. ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
  158. ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
  159. new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
  160. 0.80f, // Prim hollow
  161. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
  162. new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
  163. 0.80f); // Prim hollow check
  164. // Test a prism.
  165. CheckllSetPrimitiveParams(
  166. apiGrp1,
  167. "test 2", // Prim test identification string
  168. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  169. ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
  170. ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
  171. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  172. 0.90f, // Prim hollow
  173. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
  174. new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
  175. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  176. 0.90f); // Prim hollow check
  177. // Test a box.
  178. CheckllSetPrimitiveParams(
  179. apiGrp1,
  180. "test 3", // Prim test identification string
  181. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  182. ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
  183. ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
  184. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  185. 0.95f, // Prim hollow
  186. new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
  187. new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
  188. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  189. 0.95f); // Prim hollow check
  190. // Test a tube.
  191. CheckllSetPrimitiveParams(
  192. apiGrp1,
  193. "test 4", // Prim test identification string
  194. new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
  195. ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
  196. ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
  197. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  198. 0.00f, // Prim hollow
  199. new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
  200. new LSL_Types.Vector3(1.0d, 0.05d, 0.0d), // Prim hole size
  201. // Expression for y selected to test precision problems during byte
  202. // cast in SetPrimitiveShapeParams.
  203. new LSL_Types.Vector3(0.0d, 0.35d + 0.1d, 0.0d), // Prim shear
  204. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
  205. // Expression for y selected to test precision problems during sbyte
  206. // cast in SetPrimitiveShapeParams.
  207. new LSL_Types.Vector3(-1.0d, 0.70d + 0.1d + 0.1d, 0.0d), // Prim taper
  208. 1.11f, // Prim revolutions
  209. 0.88f, // Prim radius
  210. 0.95f, // Prim skew
  211. 0.00f); // Prim hollow check
  212. // Test a prism.
  213. CheckllSetPrimitiveParams(
  214. apiGrp1,
  215. "test 5", // Prim test identification string
  216. new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
  217. ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
  218. ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
  219. new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
  220. 0.95f, // Prim hollow
  221. // Expression for x selected to test precision problems during sbyte
  222. // cast in SetPrimitiveShapeBlockParams.
  223. new LSL_Types.Vector3(0.7d + 0.2d, 0.0d, 0.0d), // Prim twist
  224. // Expression for y selected to test precision problems during sbyte
  225. // cast in SetPrimitiveShapeParams.
  226. new LSL_Types.Vector3(2.0d, (1.3d + 0.1d), 0.0d), // Prim taper
  227. new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
  228. 0.70f); // Prim hollow check
  229. // Test a sculpted prim.
  230. CheckllSetPrimitiveParams(
  231. apiGrp1,
  232. "test 6", // Prim test identification string
  233. new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
  234. ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
  235. "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
  236. ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
  237. }
  238. // Set prim params for a box, cylinder or prism and check results.
  239. public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
  240. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  241. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
  242. float primHollowCheck)
  243. {
  244. // Set the prim params.
  245. api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  246. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  247. primCut, primHollow, primTwist, primTaper, primShear));
  248. // Get params for prim to validate settings.
  249. LSL_Types.list primParams =
  250. api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  251. // Validate settings.
  252. CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
  253. Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
  254. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  255. Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
  256. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  257. CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
  258. Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
  259. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  260. CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
  261. CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 6), primTest + " prim taper");
  262. CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
  263. }
  264. // Set prim params for a sphere and check results.
  265. public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
  266. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  267. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
  268. {
  269. // Set the prim params.
  270. api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  271. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  272. primCut, primHollow, primTwist, primDimple));
  273. // Get params for prim to validate settings.
  274. LSL_Types.list primParams =
  275. api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  276. // Validate settings.
  277. CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
  278. Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
  279. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  280. Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
  281. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  282. CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
  283. Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
  284. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  285. CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
  286. CheckllSetPrimitiveParamsVector(primDimple, api.llList2Vector(primParams, 6), primTest + " prim dimple");
  287. }
  288. // Set prim params for a torus, tube or ring and check results.
  289. public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
  290. LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
  291. float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
  292. LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
  293. float primRev, float primRadius, float primSkew, float primHollowCheck)
  294. {
  295. // Set the prim params.
  296. api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  297. ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
  298. primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
  299. primTaper, primRev, primRadius, primSkew));
  300. // Get params for prim to validate settings.
  301. LSL_Types.list primParams =
  302. api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  303. // Valdate settings.
  304. CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
  305. Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
  306. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  307. Assert.AreEqual(primHoleType, api.llList2Integer(primParams, 2),
  308. "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
  309. CheckllSetPrimitiveParamsVector(primCut, api.llList2Vector(primParams, 3), primTest + " prim cut");
  310. Assert.AreEqual(primHollowCheck, api.llList2Float(primParams, 4), FLOAT_ACCURACY,
  311. "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
  312. CheckllSetPrimitiveParamsVector(primTwist, api.llList2Vector(primParams, 5), primTest + " prim twist");
  313. CheckllSetPrimitiveParamsVector(primHoleSize, api.llList2Vector(primParams, 6), primTest + " prim hole size");
  314. CheckllSetPrimitiveParamsVector(primShear, api.llList2Vector(primParams, 7), primTest + " prim shear");
  315. CheckllSetPrimitiveParamsVector(primProfCut, api.llList2Vector(primParams, 8), primTest + " prim profile cut");
  316. CheckllSetPrimitiveParamsVector(primTaper, api.llList2Vector(primParams, 9), primTest + " prim taper");
  317. Assert.AreEqual(primRev, api.llList2Float(primParams, 10), FLOAT_ACCURACY,
  318. "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
  319. Assert.AreEqual(primRadius, api.llList2Float(primParams, 11), FLOAT_ACCURACY,
  320. "TestllSetPrimitiveParams " + primTest + " prim radius fail");
  321. Assert.AreEqual(primSkew, api.llList2Float(primParams, 12), FLOAT_ACCURACY,
  322. "TestllSetPrimitiveParams " + primTest + " prim skew fail");
  323. }
  324. // Set prim params for a sculpted prim and check results.
  325. public void CheckllSetPrimitiveParams(LSL_Api api, string primTest,
  326. LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
  327. {
  328. // Set the prim params.
  329. api.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
  330. ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
  331. // Get params for prim to validate settings.
  332. LSL_Types.list primParams =
  333. api.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
  334. // Validate settings.
  335. CheckllSetPrimitiveParamsVector(primSize, api.llList2Vector(primParams, 0), primTest + " prim size");
  336. Assert.AreEqual(primType, api.llList2Integer(primParams, 1),
  337. "TestllSetPrimitiveParams " + primTest + " prim type check fail");
  338. Assert.AreEqual(primMap, (string)api.llList2String(primParams, 2),
  339. "TestllSetPrimitiveParams " + primTest + " prim map check fail");
  340. Assert.AreEqual(primSculptType, api.llList2Integer(primParams, 3),
  341. "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
  342. }
  343. public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
  344. {
  345. // Check each vector component against expected result.
  346. Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
  347. "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
  348. Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
  349. "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
  350. Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
  351. "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
  352. }
  353. }
  354. }