LSL_TypesTestLSLString.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. [TestFixture]
  34. public class LSL_TypesTestLSLString
  35. {
  36. private Dictionary<double, string> m_doubleStringSet;
  37. /// <summary>
  38. /// Sets up dictionaries and arrays used in the tests.
  39. /// </summary>
  40. [TestFixtureSetUp]
  41. public void SetUpDataSets()
  42. {
  43. m_doubleStringSet = new Dictionary<double, string>();
  44. m_doubleStringSet.Add(2, "2.000000");
  45. m_doubleStringSet.Add(-2, "-2.000000");
  46. m_doubleStringSet.Add(0, "0.000000");
  47. m_doubleStringSet.Add(1, "1.000000");
  48. m_doubleStringSet.Add(-1, "-1.000000");
  49. m_doubleStringSet.Add(999999999, "999999999.000000");
  50. m_doubleStringSet.Add(-99999999, "-99999999.000000");
  51. m_doubleStringSet.Add(0.5, "0.500000");
  52. m_doubleStringSet.Add(0.0005, "0.000500");
  53. m_doubleStringSet.Add(0.6805, "0.680500");
  54. m_doubleStringSet.Add(-0.5, "-0.500000");
  55. m_doubleStringSet.Add(-0.0005, "-0.000500");
  56. m_doubleStringSet.Add(-0.6805, "-0.680500");
  57. m_doubleStringSet.Add(548.5, "548.500000");
  58. m_doubleStringSet.Add(2.0005, "2.000500");
  59. m_doubleStringSet.Add(349485435.6805, "349485435.680500");
  60. m_doubleStringSet.Add(-548.5, "-548.500000");
  61. m_doubleStringSet.Add(-2.0005, "-2.000500");
  62. m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
  63. }
  64. /// <summary>
  65. /// Tests constructing a LSLString from an LSLFloat.
  66. /// </summary>
  67. [Test]
  68. public void TestConstructFromLSLFloat()
  69. {
  70. LSL_Types.LSLString testString;
  71. foreach (KeyValuePair<double, string> number in m_doubleStringSet)
  72. {
  73. testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
  74. Assert.AreEqual(number.Value, testString.m_string);
  75. }
  76. }
  77. /// <summary>
  78. /// Tests constructing a LSLString from an LSLFloat.
  79. /// </summary>
  80. [Test]
  81. public void TestExplicitCastLSLFloatToLSLString()
  82. {
  83. LSL_Types.LSLString testString;
  84. foreach (KeyValuePair<double, string> number in m_doubleStringSet)
  85. {
  86. testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
  87. Assert.AreEqual(number.Value, testString.m_string);
  88. }
  89. }
  90. /// <summary>
  91. /// Test constructing a Quaternion from a string.
  92. /// </summary>
  93. [Test]
  94. public void TestExplicitCastLSLStringToQuaternion()
  95. {
  96. string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
  97. LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
  98. LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
  99. LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
  100. LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
  101. Assert.AreEqual(expectedQuaternion, stringQuaternion);
  102. Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
  103. }
  104. /// <summary>
  105. /// Tests boolean correctly cast explicitly to LSLString.
  106. /// </summary>
  107. [Test]
  108. public void TestImplicitCastBooleanToLSLFloat()
  109. {
  110. LSL_Types.LSLString testString;
  111. testString = (LSL_Types.LSLString) (1 == 0);
  112. Assert.AreEqual("0", testString.m_string);
  113. testString = (LSL_Types.LSLString) (1 == 1);
  114. Assert.AreEqual("1", testString.m_string);
  115. testString = (LSL_Types.LSLString) false;
  116. Assert.AreEqual("0", testString.m_string);
  117. testString = (LSL_Types.LSLString) true;
  118. Assert.AreEqual("1", testString.m_string);
  119. }
  120. }
  121. }