OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LSL_TypesTestLSLString.cs
Go to the documentation of this file.
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 
28 using System.Collections.Generic;
29 using NUnit.Framework;
30 using OpenSim.Tests.Common;
31 using OpenSim.Region.ScriptEngine.Shared;
32 
33 namespace OpenSim.Region.ScriptEngine.Shared.Tests
34 {
35  [TestFixture]
37  {
38  private Dictionary<double, string> m_doubleStringSet;
39 
43  [TestFixtureSetUp]
44  public void SetUpDataSets()
45  {
46  m_doubleStringSet = new Dictionary<double, string>();
47  m_doubleStringSet.Add(2, "2.000000");
48  m_doubleStringSet.Add(-2, "-2.000000");
49  m_doubleStringSet.Add(0, "0.000000");
50  m_doubleStringSet.Add(1, "1.000000");
51  m_doubleStringSet.Add(-1, "-1.000000");
52  m_doubleStringSet.Add(999999999, "999999999.000000");
53  m_doubleStringSet.Add(-99999999, "-99999999.000000");
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(-0.5, "-0.500000");
58  m_doubleStringSet.Add(-0.0005, "-0.000500");
59  m_doubleStringSet.Add(-0.6805, "-0.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  m_doubleStringSet.Add(-548.5, "-548.500000");
64  m_doubleStringSet.Add(-2.0005, "-2.000500");
65  m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
66  }
67 
71  [Test]
73  {
74  TestHelpers.InMethod();
75 
76  LSL_Types.LSLString testString;
77 
78  foreach (KeyValuePair<double, string> number in m_doubleStringSet)
79  {
80  testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
81  Assert.AreEqual(number.Value, testString.m_string);
82  }
83  }
84 
88  [Test]
90  {
91  TestHelpers.InMethod();
92 
93  LSL_Types.LSLString testString;
94 
95  foreach (KeyValuePair<double, string> number in m_doubleStringSet)
96  {
97  testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
98  Assert.AreEqual(number.Value, testString.m_string);
99  }
100  }
101 
105  [Test]
107  {
108  TestHelpers.InMethod();
109 
110  string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
111  LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
112 
113  LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
114  LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
115  LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
116 
117  Assert.AreEqual(expectedQuaternion, stringQuaternion);
118  Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
119  }
120 
124  [Test]
126  {
127  TestHelpers.InMethod();
128 
129  LSL_Types.LSLString testString;
130 
131  testString = (LSL_Types.LSLString) (1 == 0);
132  Assert.AreEqual("0", testString.m_string);
133 
134  testString = (LSL_Types.LSLString) (1 == 1);
135  Assert.AreEqual("1", testString.m_string);
136 
137  testString = (LSL_Types.LSLString) false;
138  Assert.AreEqual("0", testString.m_string);
139 
140  testString = (LSL_Types.LSLString) true;
141  Assert.AreEqual("1", testString.m_string);
142  }
143  }
144 }
void TestExplicitCastLSLStringToQuaternion()
Test constructing a Quaternion from a string.
void TestExplicitCastLSLFloatToLSLString()
Tests constructing a LSLString from an LSLFloat.
void TestConstructFromLSLFloat()
Tests constructing a LSLString from an LSLFloat.
void TestImplicitCastBooleanToLSLFloat()
Tests boolean correctly cast explicitly to LSLString.
void SetUpDataSets()
Sets up dictionaries and arrays used in the tests.