From 6447d7132f0f443205e719a00e595f79444eea25 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 8 Sep 2008 19:29:16 +0000 Subject: Adapt the unit tests to the new list rules, change some casts to new method for testing --- .../Shared/Api/Implementation/LSL_Api.cs | 13 ++++--- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 7 +++- .../ScriptEngine/Shared/LSL_TypesTestList.cs | 44 +++++++++++----------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index bc58a8a..4b92739 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5614,12 +5614,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (remain < 6) return; - face = Convert.ToInt32(rules.Data[idx++].ToString()); // holeshape - v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // cut - hollow = (float)Convert.ToDouble(rules.Data[idx++].ToString()); - twist = new LSL_Types.Vector3(rules.Data[idx++].ToString()); - taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString()); - topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString()); + face = (int)rules.GetLSLIntegerItem(idx++); + v = rules.GetVector3Item(idx++); // cut + hollow = (float)rules.GetLSLFloatItem(idx++); + twist = rules.GetVector3Item(idx++); + taper_b = rules.GetVector3Item(idx++); + topshear = rules.GetVector3Item(idx++); + part.Shape.PathCurve = (byte)Extrusion.Straight; SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 1); break; diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 4554b0c..f149f60 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -454,7 +454,12 @@ namespace OpenSim.Region.ScriptEngine.Shared public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex) { - return (LSL_Types.LSLInteger)m_data[itemIndex]; + if (m_data[itemIndex] is LSL_Types.LSLInteger) + return (LSL_Types.LSLInteger)m_data[itemIndex]; + else if (m_data[itemIndex] is Int32) + return new LSLInteger((int)m_data[itemIndex]); + else + throw new InvalidCastException(); } public LSL_Types.Vector3 GetVector3Item(int itemIndex) diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs index ca59c97..7da28dd 100644 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs @@ -44,18 +44,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateString() { - LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); - testList += "addition"; + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); + testList += new LSL_Types.LSLString("addition"); Assert.AreEqual(4, testList.Length); - Assert.AreEqual("addition", testList.Data[3]); - Assert.AreEqual(typeof(System.String), testList.Data[3].GetType()); + Assert.AreEqual(new LSL_Types.LSLString("addition"), testList.Data[3]); + Assert.AreEqual(typeof(LSL_Types.LSLString), testList.Data[3].GetType()); - LSL_Types.list secondTestList = testList + "more"; + LSL_Types.list secondTestList = testList + new LSL_Types.LSLString("more"); Assert.AreEqual(5, secondTestList.Length); - Assert.AreEqual("more", secondTestList.Data[4]); - Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType()); + Assert.AreEqual(new LSL_Types.LSLString("more"), secondTestList.Data[4]); + Assert.AreEqual(typeof(LSL_Types.LSLString), secondTestList.Data[4].GetType()); } /// @@ -64,38 +64,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateInteger() { - LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); - testList += 20; + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); + testList += new LSL_Types.LSLInteger(20); Assert.AreEqual(4, testList.Length); - Assert.AreEqual(20, testList.Data[3]); - Assert.AreEqual(typeof(int), testList.Data[3].GetType()); + Assert.AreEqual(new LSL_Types.LSLInteger(20), testList.Data[3]); + Assert.AreEqual(typeof(LSL_Types.LSLInteger), testList.Data[3].GetType()); - LSL_Types.list secondTestList = testList + 2; + LSL_Types.list secondTestList = testList + new LSL_Types.LSLInteger(2); Assert.AreEqual(5, secondTestList.Length); - Assert.AreEqual(2, secondTestList.Data[4]); - Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType()); + Assert.AreEqual(new LSL_Types.LSLInteger(2), secondTestList.Data[4]); + Assert.AreEqual(typeof(LSL_Types.LSLInteger), secondTestList.Data[4].GetType()); } /// - /// Tests concatenating a double to a list. + /// Tests concatenating a float to a list. /// [Test] public void TestConcatenateDouble() { - LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); - testList += 2.0; + LSL_Types.list testList = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger('a'), new LSL_Types.LSLString("test")); + testList += new LSL_Types.LSLFloat(2.0f); Assert.AreEqual(4, testList.Length); - Assert.AreEqual(2.0, testList.Data[3]); - Assert.AreEqual(typeof(double), testList.Data[3].GetType()); + Assert.AreEqual(new LSL_Types.LSLFloat(2.0f), testList.Data[3]); + Assert.AreEqual(typeof(LSL_Types.LSLFloat), testList.Data[3].GetType()); - LSL_Types.list secondTestList = testList + 0.04; + LSL_Types.list secondTestList = testList + new LSL_Types.LSLFloat(0.04f); Assert.AreEqual(5, secondTestList.Length); - Assert.AreEqual(0.04, secondTestList.Data[4]); - Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); + Assert.AreEqual(new LSL_Types.LSLFloat(0.04f), secondTestList.Data[4]); + Assert.AreEqual(typeof(LSL_Types.LSLFloat), secondTestList.Data[4].GetType()); } /// -- cgit v1.1