aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMike Mazur2008-07-28 02:36:26 +0000
committerMike Mazur2008-07-28 02:36:26 +0000
commitd959c65b91a9acc3b29478907a66afc16f01b047 (patch)
tree34e8caf993bf9ad13ec6f0c45ca1feab59aae163
parentAdding explicit cast from LSLFloat to LSLInteger. Work on issue 1822. (diff)
downloadopensim-SC_OLD-d959c65b91a9acc3b29478907a66afc16f01b047.zip
opensim-SC_OLD-d959c65b91a9acc3b29478907a66afc16f01b047.tar.gz
opensim-SC_OLD-d959c65b91a9acc3b29478907a66afc16f01b047.tar.bz2
opensim-SC_OLD-d959c65b91a9acc3b29478907a66afc16f01b047.tar.xz
-implement LSLString -> Quaternion explicit cast
-sync Shared/LSL_Types.cs with Common/LSL_Types.cs -get the test script in issue 1822 to compile
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs10
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs17
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs71
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs17
5 files changed, 120 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index d0871bc..74c9935 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -1190,6 +1190,11 @@ namespace OpenSim.Region.ScriptEngine.Common
1190 return new Vector3(s.m_string); 1190 return new Vector3(s.m_string);
1191 } 1191 }
1192 1192
1193 public static implicit operator Quaternion(LSLString s)
1194 {
1195 return new Quaternion(s.m_string);
1196 }
1197
1193 public static implicit operator LSLFloat(LSLString s) 1198 public static implicit operator LSLFloat(LSLString s)
1194 { 1199 {
1195 return new LSLFloat(Convert.ToDouble(s.m_string)); 1200 return new LSLFloat(Convert.ToDouble(s.m_string));
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 89722da..57394d9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1190,6 +1190,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
1190 return new Vector3(s.m_string); 1190 return new Vector3(s.m_string);
1191 } 1191 }
1192 1192
1193 public static implicit operator Quaternion(LSLString s)
1194 {
1195 return new Quaternion(s.m_string);
1196 }
1197
1193 public static implicit operator LSLFloat(LSLString s) 1198 public static implicit operator LSLFloat(LSLString s)
1194 { 1199 {
1195 return new LSLFloat(Convert.ToDouble(s.m_string)); 1200 return new LSLFloat(Convert.ToDouble(s.m_string));
@@ -1291,6 +1296,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
1291 return new LSLInteger(d); 1296 return new LSLInteger(d);
1292 } 1297 }
1293 1298
1299 static public explicit operator LSLInteger(LSLFloat f)
1300 {
1301 return new LSLInteger(f.value);
1302 }
1303
1294 static public bool operator ==(LSLInteger i1, LSLInteger i2) 1304 static public bool operator ==(LSLInteger i1, LSLInteger i2)
1295 { 1305 {
1296 bool ret = i1.value == i2.value; 1306 bool ret = i1.value == i2.value;
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs
index c855f34..5d4424b 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs
@@ -94,5 +94,22 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
94 Assert.AreEqual(number.Value, testString.m_string); 94 Assert.AreEqual(number.Value, testString.m_string);
95 } 95 }
96 } 96 }
97
98 /// <summary>
99 /// Test constructing a Quaternion from a string.
100 /// </summary>
101 [Test]
102 public void TestExplicitCastLSLStringToQuaternion()
103 {
104 string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
105 LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
106
107 LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
108 LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
109 LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
110
111 Assert.AreEqual(expectedQuaternion, stringQuaternion);
112 Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
113 }
97 } 114 }
98} 115}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs
new file mode 100644
index 0000000..a4e7bbc
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs
@@ -0,0 +1,71 @@
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
28using System.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Shared.Tests
34{
35 [TestFixture]
36 public class LSL_TypesTestLSLInteger
37 {
38 private Dictionary<double, int> m_doubleIntSet;
39
40 /// <summary>
41 /// Sets up dictionaries and arrays used in the tests.
42 /// </summary>
43 [TestFixtureSetUp]
44 public void SetUpDataSets()
45 {
46 m_doubleIntSet = new Dictionary<double, int>();
47 m_doubleIntSet.Add(2.0, 2);
48 m_doubleIntSet.Add(-2.0, -2);
49 m_doubleIntSet.Add(0.0, 0);
50 m_doubleIntSet.Add(1.0, 1);
51 m_doubleIntSet.Add(-1.0, -1);
52 m_doubleIntSet.Add(999999999.0, 999999999);
53 m_doubleIntSet.Add(-99999999.0, -99999999);
54 }
55
56 /// <summary>
57 /// Tests LSLInteger is correctly cast explicitly to LSLFloat.
58 /// </summary>
59 [Test]
60 public void TestExplicitCastLSLFloatToLSLInteger()
61 {
62 LSL_Types.LSLInteger testInteger;
63
64 foreach (KeyValuePair<double, int> number in m_doubleIntSet)
65 {
66 testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key);
67 Assert.AreEqual(testInteger.value, number.Value);
68 }
69 }
70 }
71}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs
index ceab376..8fcb385 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs
@@ -94,5 +94,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
94 Assert.AreEqual(number.Value, testString.m_string); 94 Assert.AreEqual(number.Value, testString.m_string);
95 } 95 }
96 } 96 }
97
98 /// <summary>
99 /// Test constructing a Quaternion from a string.
100 /// </summary>
101 [Test]
102 public void TestExplicitCastLSLStringToQuaternion()
103 {
104 string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
105 LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
106
107 LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
108 LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
109 LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
110
111 Assert.AreEqual(expectedQuaternion, stringQuaternion);
112 Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
113 }
97 } 114 }
98} 115}