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