LSL_TypesTestLSLString.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. [TestFixture]
  34. public class LSL_TypesTestLSLString : OpenSimTestCase
  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. TestHelpers.InMethod();
  71. LSL_Types.LSLString testString;
  72. foreach (KeyValuePair<double, string> number in m_doubleStringSet)
  73. {
  74. testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
  75. Assert.AreEqual(number.Value, testString.m_string);
  76. }
  77. }
  78. /// <summary>
  79. /// Tests constructing a LSLString from an LSLFloat.
  80. /// </summary>
  81. [Test]
  82. public void TestExplicitCastLSLFloatToLSLString()
  83. {
  84. TestHelpers.InMethod();
  85. LSL_Types.LSLString testString;
  86. foreach (KeyValuePair<double, string> number in m_doubleStringSet)
  87. {
  88. testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
  89. Assert.AreEqual(number.Value, testString.m_string);
  90. }
  91. }
  92. /// <summary>
  93. /// Test constructing a Quaternion from a string.
  94. /// </summary>
  95. [Test]
  96. public void TestExplicitCastLSLStringToQuaternion()
  97. {
  98. TestHelpers.InMethod();
  99. string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
  100. LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
  101. LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
  102. LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
  103. LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
  104. Assert.AreEqual(expectedQuaternion, stringQuaternion);
  105. Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
  106. }
  107. /// <summary>
  108. /// Tests boolean correctly cast explicitly to LSLString.
  109. /// </summary>
  110. [Test]
  111. public void TestImplicitCastBooleanToLSLFloat()
  112. {
  113. TestHelpers.InMethod();
  114. LSL_Types.LSLString testString;
  115. testString = (LSL_Types.LSLString) (1 == 0);
  116. Assert.AreEqual("0", testString.m_string);
  117. testString = (LSL_Types.LSLString) (1 == 1);
  118. Assert.AreEqual("1", testString.m_string);
  119. testString = (LSL_Types.LSLString) false;
  120. Assert.AreEqual("0", testString.m_string);
  121. testString = (LSL_Types.LSLString) true;
  122. Assert.AreEqual("1", testString.m_string);
  123. }
  124. }
  125. }