LSL_TypesTestList.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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.Collections.Generic;
  28. using NUnit.Framework;
  29. using OpenSim.Tests.Common;
  30. using OpenSim.Region.ScriptEngine.Shared;
  31. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  32. {
  33. /// <summary>
  34. /// Tests the LSL_Types.list class.
  35. /// </summary>
  36. [TestFixture]
  37. public class LSL_TypesTestList : OpenSimTestCase
  38. {
  39. /// <summary>
  40. /// Tests concatenating a string to a list.
  41. /// </summary>
  42. [Test]
  43. public void TestConcatenateString()
  44. {
  45. TestHelpers.InMethod();
  46. LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test"));
  47. testList += new LSL_Types.LSLString("addition");
  48. Assert.AreEqual(4, testList.Length);
  49. Assert.AreEqual(new LSL_Types.LSLString("addition"), testList.Data[3]);
  50. Assert.AreEqual(typeof(LSL_Types.LSLString), testList.Data[3].GetType());
  51. LSL_Types.list secondTestList = testList + new LSL_Types.LSLString("more");
  52. Assert.AreEqual(5, secondTestList.Length);
  53. Assert.AreEqual(new LSL_Types.LSLString("more"), secondTestList.Data[4]);
  54. Assert.AreEqual(typeof(LSL_Types.LSLString), secondTestList.Data[4].GetType());
  55. }
  56. /// <summary>
  57. /// Tests concatenating an integer to a list.
  58. /// </summary>
  59. [Test]
  60. public void TestConcatenateInteger()
  61. {
  62. TestHelpers.InMethod();
  63. LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test"));
  64. testList += new LSL_Types.LSLInteger(20);
  65. Assert.AreEqual(4, testList.Length);
  66. Assert.AreEqual(new LSL_Types.LSLInteger(20), testList.Data[3]);
  67. Assert.AreEqual(typeof(LSL_Types.LSLInteger), testList.Data[3].GetType());
  68. LSL_Types.list secondTestList = testList + new LSL_Types.LSLInteger(2);
  69. Assert.AreEqual(5, secondTestList.Length);
  70. Assert.AreEqual(new LSL_Types.LSLInteger(2), secondTestList.Data[4]);
  71. Assert.AreEqual(typeof(LSL_Types.LSLInteger), secondTestList.Data[4].GetType());
  72. }
  73. /// <summary>
  74. /// Tests concatenating a float to a list.
  75. /// </summary>
  76. [Test]
  77. public void TestConcatenateDouble()
  78. {
  79. TestHelpers.InMethod();
  80. LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test"));
  81. testList += new LSL_Types.LSLFloat(2.0f);
  82. Assert.AreEqual(4, testList.Length);
  83. Assert.AreEqual(new LSL_Types.LSLFloat(2.0f), testList.Data[3]);
  84. Assert.AreEqual(typeof(LSL_Types.LSLFloat), testList.Data[3].GetType());
  85. LSL_Types.list secondTestList = testList + new LSL_Types.LSLFloat(0.04f);
  86. Assert.AreEqual(5, secondTestList.Length);
  87. Assert.AreEqual(new LSL_Types.LSLFloat(0.04f), secondTestList.Data[4]);
  88. Assert.AreEqual(typeof(LSL_Types.LSLFloat), secondTestList.Data[4].GetType());
  89. }
  90. /// <summary>
  91. /// Tests casting LSLInteger item to LSLInteger.
  92. /// </summary>
  93. [Test]
  94. public void TestCastLSLIntegerItemToLSLInteger()
  95. {
  96. TestHelpers.InMethod();
  97. LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123);
  98. LSL_Types.list testList = new LSL_Types.list(testValue);
  99. Assert.AreEqual(testValue, (LSL_Types.LSLInteger)testList.Data[0]);
  100. }
  101. /// <summary>
  102. /// Tests casting LSLFloat item to LSLFloat.
  103. /// </summary>
  104. [Test]
  105. public void TestCastLSLFloatItemToLSLFloat()
  106. {
  107. TestHelpers.InMethod();
  108. LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987);
  109. LSL_Types.list testList = new LSL_Types.list(testValue);
  110. Assert.AreEqual(testValue, (LSL_Types.LSLFloat)testList.Data[0]);
  111. }
  112. /// <summary>
  113. /// Tests casting LSLString item to LSLString.
  114. /// </summary>
  115. [Test]
  116. public void TestCastLSLStringItemToLSLString()
  117. {
  118. TestHelpers.InMethod();
  119. LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there");
  120. LSL_Types.list testList = new LSL_Types.list(testValue);
  121. Assert.AreEqual(testValue, (LSL_Types.LSLString)testList.Data[0]);
  122. }
  123. /// <summary>
  124. /// Tests casting Vector3 item to Vector3.
  125. /// </summary>
  126. [Test]
  127. public void TestCastVector3ItemToVector3()
  128. {
  129. TestHelpers.InMethod();
  130. LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987);
  131. LSL_Types.list testList = new LSL_Types.list(testValue);
  132. Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]);
  133. }
  134. /// <summary>
  135. /// Tests casting Quaternion item to Quaternion.
  136. /// </summary>
  137. [Test]
  138. public void TestCastQuaternionItemToQuaternion()
  139. {
  140. TestHelpers.InMethod();
  141. LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987);
  142. LSL_Types.list testList = new LSL_Types.list(testValue);
  143. Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]);
  144. }
  145. //====================================================================================
  146. /// <summary>
  147. /// Tests GetLSLIntegerItem for LSLInteger item.
  148. /// </summary>
  149. [Test]
  150. public void TestGetLSLIntegerItemForLSLIntegerItem()
  151. {
  152. TestHelpers.InMethod();
  153. LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911);
  154. LSL_Types.list testList = new LSL_Types.list(testValue);
  155. Assert.AreEqual(testValue, testList.GetLSLIntegerItem(0));
  156. }
  157. /// <summary>
  158. /// Tests GetLSLFloatItem for LSLFloat item.
  159. /// </summary>
  160. [Test]
  161. public void TestGetLSLFloatItemForLSLFloatItem()
  162. {
  163. TestHelpers.InMethod();
  164. LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876);
  165. LSL_Types.list testList = new LSL_Types.list(testValue);
  166. Assert.AreEqual(testValue, testList.GetLSLFloatItem(0));
  167. }
  168. /// <summary>
  169. /// Tests GetLSLFloatItem for LSLInteger item.
  170. /// </summary>
  171. [Test]
  172. public void TestGetLSLFloatItemForLSLIntegerItem()
  173. {
  174. TestHelpers.InMethod();
  175. LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987);
  176. LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue);
  177. LSL_Types.list testList = new LSL_Types.list(testValue);
  178. Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0));
  179. }
  180. /// <summary>
  181. /// Tests GetLSLStringItem for LSLString item.
  182. /// </summary>
  183. [Test]
  184. public void TestGetLSLStringItemForLSLStringItem()
  185. {
  186. TestHelpers.InMethod();
  187. LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all");
  188. LSL_Types.list testList = new LSL_Types.list(testValue);
  189. Assert.AreEqual(testValue, testList.GetLSLStringItem(0));
  190. }
  191. /// <summary>
  192. /// Tests GetLSLStringItem for key item.
  193. /// </summary>
  194. [Test]
  195. public void TestGetLSLStringItemForKeyItem()
  196. {
  197. TestHelpers.InMethod();
  198. LSL_Types.key testValue
  199. = new LSL_Types.key("98000000-0000-2222-3333-100000001000");
  200. LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue);
  201. LSL_Types.list testList = new LSL_Types.list(testValue);
  202. Assert.AreEqual(testStringValue, testList.GetLSLStringItem(0));
  203. }
  204. /// <summary>
  205. /// Tests GetVector3Item for Vector3 item.
  206. /// </summary>
  207. [Test]
  208. public void TestGetVector3ItemForVector3Item()
  209. {
  210. TestHelpers.InMethod();
  211. LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987);
  212. LSL_Types.list testList = new LSL_Types.list(testValue);
  213. Assert.AreEqual(testValue, testList.GetVector3Item(0));
  214. }
  215. /// <summary>
  216. /// Tests GetQuaternionItem for Quaternion item.
  217. /// </summary>
  218. [Test]
  219. public void TestGetQuaternionItemForQuaternionItem()
  220. {
  221. TestHelpers.InMethod();
  222. LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987);
  223. // make that nonsense a quaternion
  224. testValue.Normalize();
  225. LSL_Types.list testList = new LSL_Types.list(testValue);
  226. Assert.AreEqual(testValue, testList.GetQuaternionItem(0));
  227. }
  228. /// <summary>
  229. /// Tests GetKeyItem for key item.
  230. /// </summary>
  231. [Test]
  232. public void TestGetKeyItemForKeyItem()
  233. {
  234. TestHelpers.InMethod();
  235. LSL_Types.key testValue
  236. = new LSL_Types.key("00000000-0000-2222-3333-100000001012");
  237. LSL_Types.list testList = new LSL_Types.list(testValue);
  238. Assert.AreEqual(testValue, testList.GetKeyItem(0));
  239. }
  240. }
  241. }