From f6fa4ada4ea8680e49a47e2b9a5741c8d33ef74d Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 28 Jul 2008 07:46:53 +0000 Subject: When casting strings to int, use double.Parse() as strings may be floats. With this commit, issue 1822 should be fixed. --- .../ScriptEngine/Common/LSL_TypesTestLSLInteger.cs | 43 +++++++++++++++++++++- .../ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs | 43 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) (limited to 'OpenSim/Tests') 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 public class LSL_TypesTestLSLInteger { private Dictionary m_doubleIntSet; + private Dictionary m_stringIntSet; /// /// Sets up dictionaries and arrays used in the tests. @@ -51,10 +52,20 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests m_doubleIntSet.Add(-1.0, -1); m_doubleIntSet.Add(999999999.0, 999999999); m_doubleIntSet.Add(-99999999.0, -99999999); + + m_stringIntSet = new Dictionary(); + m_stringIntSet.Add("2", 2); + m_stringIntSet.Add("-2", -2); + m_stringIntSet.Add("0", 0); + m_stringIntSet.Add("1", 1); + m_stringIntSet.Add("-1", -1); + m_stringIntSet.Add("123.9", 123); + m_stringIntSet.Add("999999999", 999999999); + m_stringIntSet.Add("-99999999", -99999999); } /// - /// Tests LSLInteger is correctly cast explicitly to LSLFloat. + /// Tests LSLFloat is correctly cast explicitly to LSLInteger. /// [Test] public void TestExplicitCastLSLFloatToLSLInteger() @@ -67,5 +78,35 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests Assert.AreEqual(testInteger.value, number.Value); } } + + /// + /// Tests string is correctly cast explicitly to LSLInteger. + /// + [Test] + public void TestExplicitCastStringToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + foreach (KeyValuePair number in m_stringIntSet) + { + testInteger = (LSL_Types.LSLInteger) number.Key; + Assert.AreEqual(testInteger.value, number.Value); + } + } + + /// + /// Tests LSLString is correctly cast explicitly to LSLInteger. + /// + [Test] + public void TestExplicitCastLSLStringToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + foreach (KeyValuePair number in m_stringIntSet) + { + testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key); + Assert.AreEqual(testInteger.value, number.Value); + } + } } } 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 public class LSL_TypesTestLSLInteger { private Dictionary m_doubleIntSet; + private Dictionary m_stringIntSet; /// /// Sets up dictionaries and arrays used in the tests. @@ -51,10 +52,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests m_doubleIntSet.Add(-1.0, -1); m_doubleIntSet.Add(999999999.0, 999999999); m_doubleIntSet.Add(-99999999.0, -99999999); + + m_stringIntSet = new Dictionary(); + m_stringIntSet.Add("2", 2); + m_stringIntSet.Add("-2", -2); + m_stringIntSet.Add("0", 0); + m_stringIntSet.Add("1", 1); + m_stringIntSet.Add("-1", -1); + m_stringIntSet.Add("123.9", 123); + m_stringIntSet.Add("999999999", 999999999); + m_stringIntSet.Add("-99999999", -99999999); } /// - /// Tests LSLInteger is correctly cast explicitly to LSLFloat. + /// Tests LSLFloat is correctly cast explicitly to LSLInteger. /// [Test] public void TestExplicitCastLSLFloatToLSLInteger() @@ -67,5 +78,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.AreEqual(testInteger.value, number.Value); } } + + /// + /// Tests string is correctly cast explicitly to LSLInteger. + /// + [Test] + public void TestExplicitCastStringToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + foreach (KeyValuePair number in m_stringIntSet) + { + testInteger = (LSL_Types.LSLInteger) number.Key; + Assert.AreEqual(testInteger.value, number.Value); + } + } + + /// + /// Tests LSLString is correctly cast explicitly to LSLInteger. + /// + [Test] + public void TestExplicitCastLSLStringToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + foreach (KeyValuePair number in m_stringIntSet) + { + testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key); + Assert.AreEqual(testInteger.value, number.Value); + } + } } } -- cgit v1.1