LSL_TypesTestList.cs 10 KB

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