aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMike Mazur2008-07-28 07:46:53 +0000
committerMike Mazur2008-07-28 07:46:53 +0000
commitf6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d (patch)
tree93ca486045152bb3d60903e395b84ab3fe51d701
parent-implement LSLString -> Quaternion explicit cast (diff)
downloadopensim-SC_OLD-f6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d.zip
opensim-SC_OLD-f6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d.tar.gz
opensim-SC_OLD-f6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d.tar.bz2
opensim-SC_OLD-f6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d.tar.xz
When casting strings to int, use double.Parse() as strings may be floats. With
this commit, issue 1822 should be fixed.
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs6
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs43
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs43
4 files changed, 92 insertions, 6 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 74c9935..d0a5079 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -1172,7 +1172,8 @@ namespace OpenSim.Region.ScriptEngine.Common
1172 1172
1173 public static explicit operator LSLInteger(LSLString s) 1173 public static explicit operator LSLInteger(LSLString s)
1174 { 1174 {
1175 return new LSLInteger(Convert.ToInt32(s.m_string)); 1175 // double.Parse() used because s could be "123.9" for example.
1176 return new LSLInteger(double.Parse(s.m_string));
1176 } 1177 }
1177 1178
1178 public static explicit operator LSLString(double d) 1179 public static explicit operator LSLString(double d)
@@ -1283,7 +1284,8 @@ namespace OpenSim.Region.ScriptEngine.Common
1283 1284
1284 static public explicit operator LSLInteger(string s) 1285 static public explicit operator LSLInteger(string s)
1285 { 1286 {
1286 return new LSLInteger(int.Parse(s)); 1287 // double.Parse() used because s could be "123.9" for example.
1288 return new LSLInteger(double.Parse(s));
1287 } 1289 }
1288 1290
1289 static public implicit operator LSLInteger(uint u) 1291 static public implicit operator LSLInteger(uint u)
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 57394d9..c42e3e6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1172,7 +1172,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
1172 1172
1173 public static explicit operator LSLInteger(LSLString s) 1173 public static explicit operator LSLInteger(LSLString s)
1174 { 1174 {
1175 return new LSLInteger(Convert.ToInt32(s.m_string)); 1175 // double.Parse() used because s could be "123.9" for example.
1176 return new LSLInteger(double.Parse(s.m_string));
1176 } 1177 }
1177 1178
1178 public static explicit operator LSLString(double d) 1179 public static explicit operator LSLString(double d)
@@ -1283,7 +1284,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
1283 1284
1284 static public explicit operator LSLInteger(string s) 1285 static public explicit operator LSLInteger(string s)
1285 { 1286 {
1286 return new LSLInteger(int.Parse(s)); 1287 // double.Parse() used because s could be "123.9" for example.
1288 return new LSLInteger(double.Parse(s));
1287 } 1289 }
1288 1290
1289 static public implicit operator LSLInteger(uint u) 1291 static public implicit operator LSLInteger(uint u)
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs
index 08f80d3..3f01d09 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs
@@ -36,6 +36,7 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
36 public class LSL_TypesTestLSLInteger 36 public class LSL_TypesTestLSLInteger
37 { 37 {
38 private Dictionary<double, int> m_doubleIntSet; 38 private Dictionary<double, int> m_doubleIntSet;
39 private Dictionary<string, int> m_stringIntSet;
39 40
40 /// <summary> 41 /// <summary>
41 /// Sets up dictionaries and arrays used in the tests. 42 /// Sets up dictionaries and arrays used in the tests.
@@ -51,10 +52,20 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
51 m_doubleIntSet.Add(-1.0, -1); 52 m_doubleIntSet.Add(-1.0, -1);
52 m_doubleIntSet.Add(999999999.0, 999999999); 53 m_doubleIntSet.Add(999999999.0, 999999999);
53 m_doubleIntSet.Add(-99999999.0, -99999999); 54 m_doubleIntSet.Add(-99999999.0, -99999999);
55
56 m_stringIntSet = new Dictionary<string, int>();
57 m_stringIntSet.Add("2", 2);
58 m_stringIntSet.Add("-2", -2);
59 m_stringIntSet.Add("0", 0);
60 m_stringIntSet.Add("1", 1);
61 m_stringIntSet.Add("-1", -1);
62 m_stringIntSet.Add("123.9", 123);
63 m_stringIntSet.Add("999999999", 999999999);
64 m_stringIntSet.Add("-99999999", -99999999);
54 } 65 }
55 66
56 /// <summary> 67 /// <summary>
57 /// Tests LSLInteger is correctly cast explicitly to LSLFloat. 68 /// Tests LSLFloat is correctly cast explicitly to LSLInteger.
58 /// </summary> 69 /// </summary>
59 [Test] 70 [Test]
60 public void TestExplicitCastLSLFloatToLSLInteger() 71 public void TestExplicitCastLSLFloatToLSLInteger()
@@ -67,5 +78,35 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
67 Assert.AreEqual(testInteger.value, number.Value); 78 Assert.AreEqual(testInteger.value, number.Value);
68 } 79 }
69 } 80 }
81
82 /// <summary>
83 /// Tests string is correctly cast explicitly to LSLInteger.
84 /// </summary>
85 [Test]
86 public void TestExplicitCastStringToLSLInteger()
87 {
88 LSL_Types.LSLInteger testInteger;
89
90 foreach (KeyValuePair<string, int> number in m_stringIntSet)
91 {
92 testInteger = (LSL_Types.LSLInteger) number.Key;
93 Assert.AreEqual(testInteger.value, number.Value);
94 }
95 }
96
97 /// <summary>
98 /// Tests LSLString is correctly cast explicitly to LSLInteger.
99 /// </summary>
100 [Test]
101 public void TestExplicitCastLSLStringToLSLInteger()
102 {
103 LSL_Types.LSLInteger testInteger;
104
105 foreach (KeyValuePair<string, int> number in m_stringIntSet)
106 {
107 testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key);
108 Assert.AreEqual(testInteger.value, number.Value);
109 }
110 }
70 } 111 }
71} 112}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs
index a4e7bbc..d158084 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs
@@ -36,6 +36,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
36 public class LSL_TypesTestLSLInteger 36 public class LSL_TypesTestLSLInteger
37 { 37 {
38 private Dictionary<double, int> m_doubleIntSet; 38 private Dictionary<double, int> m_doubleIntSet;
39 private Dictionary<string, int> m_stringIntSet;
39 40
40 /// <summary> 41 /// <summary>
41 /// Sets up dictionaries and arrays used in the tests. 42 /// Sets up dictionaries and arrays used in the tests.
@@ -51,10 +52,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
51 m_doubleIntSet.Add(-1.0, -1); 52 m_doubleIntSet.Add(-1.0, -1);
52 m_doubleIntSet.Add(999999999.0, 999999999); 53 m_doubleIntSet.Add(999999999.0, 999999999);
53 m_doubleIntSet.Add(-99999999.0, -99999999); 54 m_doubleIntSet.Add(-99999999.0, -99999999);
55
56 m_stringIntSet = new Dictionary<string, int>();
57 m_stringIntSet.Add("2", 2);
58 m_stringIntSet.Add("-2", -2);
59 m_stringIntSet.Add("0", 0);
60 m_stringIntSet.Add("1", 1);
61 m_stringIntSet.Add("-1", -1);
62 m_stringIntSet.Add("123.9", 123);
63 m_stringIntSet.Add("999999999", 999999999);
64 m_stringIntSet.Add("-99999999", -99999999);
54 } 65 }
55 66
56 /// <summary> 67 /// <summary>
57 /// Tests LSLInteger is correctly cast explicitly to LSLFloat. 68 /// Tests LSLFloat is correctly cast explicitly to LSLInteger.
58 /// </summary> 69 /// </summary>
59 [Test] 70 [Test]
60 public void TestExplicitCastLSLFloatToLSLInteger() 71 public void TestExplicitCastLSLFloatToLSLInteger()
@@ -67,5 +78,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
67 Assert.AreEqual(testInteger.value, number.Value); 78 Assert.AreEqual(testInteger.value, number.Value);
68 } 79 }
69 } 80 }
81
82 /// <summary>
83 /// Tests string is correctly cast explicitly to LSLInteger.
84 /// </summary>
85 [Test]
86 public void TestExplicitCastStringToLSLInteger()
87 {
88 LSL_Types.LSLInteger testInteger;
89
90 foreach (KeyValuePair<string, int> number in m_stringIntSet)
91 {
92 testInteger = (LSL_Types.LSLInteger) number.Key;
93 Assert.AreEqual(testInteger.value, number.Value);
94 }
95 }
96
97 /// <summary>
98 /// Tests LSLString is correctly cast explicitly to LSLInteger.
99 /// </summary>
100 [Test]
101 public void TestExplicitCastLSLStringToLSLInteger()
102 {
103 LSL_Types.LSLInteger testInteger;
104
105 foreach (KeyValuePair<string, int> number in m_stringIntSet)
106 {
107 testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key);
108 Assert.AreEqual(testInteger.value, number.Value);
109 }
110 }
70 } 111 }
71} 112}