From ce0a8d7beffccbaeb6b603a96b7729278c4c9e75 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Mon, 8 Sep 2008 20:34:45 +0000
Subject: changes to Test directory structure per opensim-dev conversation
---
.../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 1605 ++++++++++++++++++++
.../Shared/CodeTools/Tests/CompilerTest.cs | 153 ++
.../Shared/Tests/LSL_TypesTestLSLFloat.cs | 603 ++++++++
.../Shared/Tests/LSL_TypesTestLSLInteger.cs | 133 ++
.../Shared/Tests/LSL_TypesTestLSLString.cs | 136 ++
.../ScriptEngine/Shared/Tests/LSL_TypesTestList.cs | 261 ++++
.../Shared/Tests/LSL_TypesTestVector3.cs | 62 +
7 files changed, 2953 insertions(+)
create mode 100644 OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs
create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs
(limited to 'OpenSim/Region/ScriptEngine/Shared')
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
new file mode 100644
index 0000000..fefcada
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
@@ -0,0 +1,1605 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using NUnit.Framework;
+using OpenSim.Region.ScriptEngine.Shared.CodeTools;
+
+namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
+{
+ ///
+ /// Tests the LSL compiler, both the code generation and transformation.
+ /// Each test has some LSL code as input and C# code as expected output.
+ /// The generated C# code is compared against the expected C# code.
+ ///
+ [TestFixture]
+ public class CSCodeGeneratorTest
+ {
+ [Test]
+ public void TestDefaultState()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ }
+}
+";
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestCustomState()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ }
+}
+
+state another_state
+{
+ no_sensor()
+ {
+ }
+}
+";
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n }" +
+ "\n public void another_state_event_no_sensor()" +
+ "\n {" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestEventWithArguments()
+ {
+ string input = @"default
+{
+ at_rot_target(integer tnum, rotation targetrot, rotation ourrot)
+ {
+ }
+}
+";
+ string expected =
+ "\n public void default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)" +
+ "\n {" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIntegerDeclaration()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ integer x;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = 0;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestAssignments()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ string y;
+ integer x = 14;
+ y = ""Hello"";
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLString y = \"\";" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14);" +
+ "\n y = new LSL_Types.LSLString(\"Hello\");" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestAdditionSubtractionOperator()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ integer y = -3;
+ integer x = 14 + 6;
+ y = 12 +45+20+x + 23 + 1 + x + y;
+ y = 12 + -45 + - 20 + x + 23 + -1 + x + y;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)\n" +
+ " {\n" +
+ " LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);\n" +
+ " LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);\n" +
+ " y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1) + x + y;\n" +
+ " y = new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + -new LSL_Types.LSLInteger(1) + x + y;\n" +
+ " }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestStrings()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ llOwnerSay(""Testing, 1, 2, 3"");
+ llSay(0, ""I can hear you!"");
+ some_custom_function(1, 2, 3 +x, 4, ""five"", ""arguments"");
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"Testing, 1, 2, 3\"));" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I can hear you!\"));" +
+ "\n some_custom_function(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3) + x, new LSL_Types.LSLInteger(4), new LSL_Types.LSLString(\"five\"), new LSL_Types.LSLString(\"arguments\"));" +
+ "\n }" +
+ "\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestBinaryExpression()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ integer y;
+ integer x = 14 + 6;
+ y = 12 - 3;
+ y = 12 * 3;
+ y = 12 / 3;
+ y = 12 | 3;
+ y = 12 & 3;
+ y = 12 % 3;
+ y = 12 + 45 - 20 * x / 23 | 1 & x + y;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger y = 0;" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
+ "\n y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) / new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) | new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) & new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) % new LSL_Types.LSLInteger(3);" +
+ "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) - new LSL_Types.LSLInteger(20) * x / new LSL_Types.LSLInteger(23) | new LSL_Types.LSLInteger(1) & x + y;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestFloatConstants()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ float y = 1.1;
+ y = 1.123E3;
+ y = 1.123e3;
+ y = 1.123E+3;
+ y = 1.123e+3;
+ y = 1.123E-3;
+ y = 1.123e-3;
+ y = .4;
+ y = -1.123E3;
+ y = -1.123e3;
+ y = -1.123E+3;
+ y = -1.123e+3;
+ y = -1.123E-3;
+ y = -1.123e-3;
+ y = -.4;
+ y = 12.3 + -1.45E3 - 1.20e-2;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.1);" +
+ "\n y = new LSL_Types.LSLFloat(1.123E3);" +
+ "\n y = new LSL_Types.LSLFloat(1.123e3);" +
+ "\n y = new LSL_Types.LSLFloat(1.123E+3);" +
+ "\n y = new LSL_Types.LSLFloat(1.123e+3);" +
+ "\n y = new LSL_Types.LSLFloat(1.123E-3);" +
+ "\n y = new LSL_Types.LSLFloat(1.123e-3);" +
+ "\n y = new LSL_Types.LSLFloat(.4);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123E3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123e3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123E+3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123e+3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123E-3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.123e-3);" +
+ "\n y = -new LSL_Types.LSLFloat(.4);" +
+ "\n y = new LSL_Types.LSLFloat(12.3) + -new LSL_Types.LSLFloat(1.45E3) - new LSL_Types.LSLFloat(1.20e-2);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestComments()
+ {
+ string input = @"// this test tests comments
+default
+{
+ touch_start(integer num_detected) // this should be stripped
+ {
+ // fill in code here...
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestStringsWithEscapedQuotesAndComments()
+ {
+ string input = @"// this test tests strings, with escaped quotes and comments in strings
+default
+{
+ touch_start(integer num_detected)
+ {
+ string s1 = ""this is a string."";
+ string s2 = ""this is a string ""+""with an escaped \"" inside it."";
+ s1 = s2+"" and this ""+""is a string with // comments."";
+
+ string onemore = ""[\^@]"";
+
+ string multiline = ""Good evening Sir,
+ my name is Steve.
+ I come from a rough area.
+ I used to be addicted to crack
+ but now I am off it and trying to stay clean.
+ That is why I am selling magazine subscriptions.""; // http://www.imdb.com/title/tt0151804/quotes
+ }
+}
+";
+
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLString s1 = new LSL_Types.LSLString(\"this is a string.\");" +
+ "\n LSL_Types.LSLString s2 = new LSL_Types.LSLString(\"this is a string \") + new LSL_Types.LSLString(\"with an escaped \\\" inside it.\");" +
+ "\n s1 = s2 + new LSL_Types.LSLString(\" and this \") + new LSL_Types.LSLString(\"is a string with // comments.\");" +
+ "\n LSL_Types.LSLString onemore = new LSL_Types.LSLString(\"[\\^@]\");" +
+ "\n LSL_Types.LSLString multiline = new LSL_Types.LSLString(\"Good evening Sir,\\n my name is Steve.\\n I come from a rough area.\\n I used to be addicted to crack\\n but now I am off it and trying to stay clean.\\n That is why I am selling magazine subscriptions.\");" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestGlobalDefinedFunctions()
+ {
+ string input = @"// this test tests custom defined functions
+
+string onefunc()
+{
+ return ""Hi from onefunc()!"";
+}
+
+twofunc(string s)
+{
+ llSay(1000, s);
+}
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ llSay(2000, onefunc());
+ twofunc();
+ }
+}
+";
+ string expected =
+ "\n LSL_Types.LSLString onefunc()" +
+ "\n {" +
+ "\n return new LSL_Types.LSLString(\"Hi from onefunc()!\");" +
+ "\n }" +
+ "\n void twofunc(LSL_Types.LSLString s)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(1000), s);" +
+ "\n }" +
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
+ "\n twofunc();" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestGlobalDeclaredVariables()
+ {
+ string input = @"// this test tests custom defined functions and global variables
+
+string globalString;
+integer globalInt = 14;
+integer anotherGlobal = 20 * globalInt;
+
+string onefunc()
+{
+ globalString = "" ...and the global!"";
+ return ""Hi "" +
+ ""from "" +
+ ""onefunc()!"" + globalString;
+}
+
+twofunc(string s)
+{
+ llSay(1000, s);
+}
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ llSay(2000, onefunc());
+ twofunc();
+ }
+}
+";
+ string expected =
+ "\n LSL_Types.LSLString globalString = \"\";" +
+ "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" +
+ "\n LSL_Types.LSLInteger anotherGlobal = new LSL_Types.LSLInteger(20) * globalInt;" +
+ "\n LSL_Types.LSLString onefunc()" +
+ "\n {" +
+ "\n globalString = new LSL_Types.LSLString(\" ...and the global!\");" +
+ "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()!\") + globalString;" +
+ "\n }" +
+ "\n void twofunc(LSL_Types.LSLString s)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(1000), s);" +
+ "\n }" +
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
+ "\n twofunc();" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestMoreAssignments()
+ {
+ string input = @"// this test tests +=, -=, *=, /=, %=
+
+string globalString;
+integer globalInt = 14;
+
+string onefunc(string addition)
+{
+ globalInt -= 2;
+
+ globalString += addition;
+ return ""Hi "" +
+ ""from "" +
+ ""onefunc()! "" + globalString;
+}
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ llSay(2000, onefunc());
+
+ integer x = 2;
+ x *= 3;
+ x /= 14 + -2;
+ x %= 10;
+ }
+}
+";
+ string expected =
+ "\n LSL_Types.LSLString globalString = \"\";" +
+ "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" +
+ "\n LSL_Types.LSLString onefunc(LSL_Types.LSLString addition)" +
+ "\n {" +
+ "\n globalInt -= new LSL_Types.LSLInteger(2);" +
+ "\n globalString += addition;" +
+ "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()! \") + globalString;" +
+ "\n }" +
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" +
+ "\n x *= new LSL_Types.LSLInteger(3);" +
+ "\n x /= new LSL_Types.LSLInteger(14) + -new LSL_Types.LSLInteger(2);" +
+ "\n x %= new LSL_Types.LSLInteger(10);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestVectorConstantNotation()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ vector y = <1.2, llGetMeAFloat(), 4.4>;
+ rotation x = <0.1, 0.1, one + 2, 0.9>;
+
+ y = <0.1, 0.1, 1.1 - three - two+eight*8>;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" +
+ "\n LSL_Types.Quaternion x = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), one + new LSL_Types.LSLInteger(2), new LSL_Types.LSLFloat(0.9));" +
+ "\n y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(1.1) - three - two + eight * new LSL_Types.LSLInteger(8));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestVectorMemberAccess()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ vector y = <1.2, llGetMeAFloat(), 4.4>;
+ x = y.x + 1.1;
+ y.x = 1.1;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" +
+ "\n x = y.x + new LSL_Types.LSLFloat(1.1);" +
+ "\n y.x = new LSL_Types.LSLFloat(1.1);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestExpressionInParentheses()
+ {
+ string input = @"default
+{
+ touch_start(integer num_detected)
+ {
+ integer y = -3;
+ integer x = 14 + 6;
+ y = 12 +45+20+x + (23 + 1) + x + y;
+ y = (12 + -45 + -20 + x + 23 )+ -1 + x + y;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
+ "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + x + y;" +
+ "\n y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x + y;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIncrementDecrementOperator()
+ {
+ string input = @"// here we'll test the ++ and -- operators
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer y = -3;
+ integer x = 14 + 6;
+ y = 12 +45+20+x++ + (23 + 1) + ++x + -- y;
+ y = (12 + -45 + -20 + x-- + 23 )+ -1 + x -- + ++y;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
+ "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x++ + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + ++x + --y;" +
+ "\n y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x-- + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x-- + ++y;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestLists()
+ {
+ string input = @"// testing lists
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ list l = [];
+ list m = [1, two, ""three"", <4.0, 4.0, 4.0>, 5 + 5];
+ llCallSomeFunc(1, llAnotherFunc(), [1, 2, 3]);
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.list l = new LSL_Types.list();" +
+ "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), two, new LSL_Types.LSLString(\"three\"), new LSL_Types.Vector3(new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0)), new LSL_Types.LSLInteger(5) + new LSL_Types.LSLInteger(5));" +
+ "\n llCallSomeFunc(new LSL_Types.LSLInteger(1), llAnotherFunc(), new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3)));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIfStatement()
+ {
+ string input = @"// let's test if statements
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 1;
+
+ if (x) llSay(0, ""Hello"");
+ if (1)
+ {
+ llSay(0, ""Hi"");
+ integer r = 3;
+ return;
+ }
+
+ if (f(x)) llSay(0, ""f(x) is true"");
+ else llSay(0, ""f(x) is false"");
+
+ if (x + y) llSay(0, ""x + y is true"");
+ else if (y - x) llSay(0, ""y - x is true"");
+ else llSay(0, ""Who needs x and y anyway?"");
+
+ if (x * y) llSay(0, ""x * y is true"");
+ else if (y / x)
+ {
+ llSay(0, ""uh-oh, y / x is true, exiting"");
+ return;
+ }
+ else llSay(0, ""Who needs x and y anyway?"");
+
+ // and now for my last trick
+ if (x % y) llSay(0, ""x is true"");
+ else if (y & x) llSay(0, ""y is true"");
+ else if (z | x) llSay(0, ""z is true"");
+ else if (a * (b + x)) llSay(0, ""a is true"");
+ else if (b) llSay(0, ""b is true"");
+ else if (v) llSay(0, ""v is true"");
+ else llSay(0, ""Everything is lies!"");
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n if (x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" +
+ "\n if (new LSL_Types.LSLInteger(1))" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" +
+ "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" +
+ "\n return ;" +
+ "\n }" +
+ "\n if (f(x))" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is false\"));" +
+ "\n if (x + y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x + y is true\"));" +
+ "\n else" +
+ "\n if (y - x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y - x is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
+ "\n if (x * y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x * y is true\"));" +
+ "\n else" +
+ "\n if (y / x)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y / x is true, exiting\"));" +
+ "\n return ;" +
+ "\n }" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
+ "\n if (x % y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
+ "\n else" +
+ "\n if (y & x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
+ "\n else" +
+ "\n if (z | x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" +
+ "\n else" +
+ "\n if (a * (b + x))" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" +
+ "\n else" +
+ "\n if (b)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" +
+ "\n else" +
+ "\n if (v)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIfElseStatement()
+ {
+ string input = @"// let's test complex logical expressions
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 1;
+ integer y = 0;
+
+ if (x && y) llSay(0, ""Hello"");
+ if (x || y)
+ {
+ llSay(0, ""Hi"");
+ integer r = 3;
+ return;
+ }
+
+ if (x && y || z) llSay(0, ""x is true"");
+ else llSay(0, ""x is false"");
+
+ if (x == y) llSay(0, ""x is true"");
+ else if (y < x) llSay(0, ""y is true"");
+ else llSay(0, ""Who needs x and y anyway?"");
+
+ if (x > y) llSay(0, ""x is true"");
+ else if (y <= x)
+ {
+ llSay(0, ""uh-oh, y is true, exiting"");
+ return;
+ }
+ else llSay(0, ""Who needs x and y anyway?"");
+
+ // and now for my last trick
+ if (x >= y) llSay(0, ""x is true"");
+ else if (y != x) llSay(0, ""y is true"");
+ else if (!z) llSay(0, ""z is true"");
+ else if (!(a && b)) llSay(0, ""a is true"");
+ else if (b) llSay(0, ""b is true"");
+ else if (v) llSay(0, ""v is true"");
+ else llSay(0, ""Everything is lies!"");
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
+ "\n if (x && y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" +
+ "\n if (x || y)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" +
+ "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" +
+ "\n return ;" +
+ "\n }" +
+ "\n if (x && y || z)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is false\"));" +
+ "\n if (x == y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
+ "\n else" +
+ "\n if (y < x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
+ "\n if (x > y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
+ "\n else" +
+ "\n if (y <= x)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y is true, exiting\"));" +
+ "\n return ;" +
+ "\n }" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
+ "\n if (x >= y)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
+ "\n else" +
+ "\n if (y != x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
+ "\n else" +
+ "\n if (!z)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" +
+ "\n else" +
+ "\n if (!(a && b))" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" +
+ "\n else" +
+ "\n if (b)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" +
+ "\n else" +
+ "\n if (v)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" +
+ "\n else" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestWhileLoop()
+ {
+ string input = @"// let's test while loops
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 1;
+ integer y = 0;
+
+ while (x) llSay(0, ""To infinity, and beyond!"");
+ while (0 || (x && 0))
+ {
+ llSay(0, ""Never say never."");
+ return;
+ }
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
+ "\n while (x)" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"To infinity, and beyond!\"));" +
+ "\n while (new LSL_Types.LSLInteger(0) || (x && new LSL_Types.LSLInteger(0)))" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Never say never.\"));" +
+ "\n return ;" +
+ "\n }" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestDoWhileLoop()
+ {
+ string input = @"// let's test do-while loops
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 1;
+ integer y = 0;
+
+ do llSay(0, ""And we're doing..."");
+ while (x);
+
+ do
+ {
+ llSay(0, ""I like it here. I wish we could stay here forever."");
+ y--;
+ } while (y);
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
+ "\n do" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"And we're doing...\"));" +
+ "\n while (x);" +
+ "\n do" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I like it here. I wish we could stay here forever.\"));" +
+ "\n y--;" +
+ "\n }" +
+ "\n while (y);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestForLoop()
+ {
+ string input = @"// let's test for loops
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 1;
+ integer y = 0;
+
+ for (x = 10; x >= 0; x--)
+ {
+ llOwnerSay(""Launch in T minus "" + x);
+ IncreaseRocketPower();
+ }
+
+ for (x = 0, y = 6; y > 0 && x != y; x++, y--) llOwnerSay(""Hi "" + x + "", "" + y);
+ for (x = 0, y = 6; ! y; x++,y--) llOwnerSay(""Hi "" + x + "", "" + y);
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
+ "\n for (x = new LSL_Types.LSLInteger(10); x >= new LSL_Types.LSLInteger(0); x--)" +
+ "\n {" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"Launch in T minus \") + x);" +
+ "\n IncreaseRocketPower();" +
+ "\n }" +
+ "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); y > new LSL_Types.LSLInteger(0) && x != y; x++, y--)" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" +
+ "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); !y; x++, y--)" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestFloatsWithTrailingDecimal()
+ {
+ string input = @"// a curious feature of LSL that allows floats to be defined with a trailing dot
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ float y = 1.;
+ y = 1.E3;
+ y = 1.e3;
+ y = 1.E+3;
+ y = 1.e+3;
+ y = 1.E-3;
+ y = 1.e-3;
+ y = -1.E3;
+ y = -1.e3;
+ y = -1.E+3;
+ y = -1.e+3;
+ y = -1.E-3;
+ y = -1.e-3;
+ y = 12. + -1.E3 - 1.e-2;
+ vector v = <0.,0.,0.>;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.0);" +
+ "\n y = new LSL_Types.LSLFloat(1.0E3);" +
+ "\n y = new LSL_Types.LSLFloat(1.0e3);" +
+ "\n y = new LSL_Types.LSLFloat(1.0E+3);" +
+ "\n y = new LSL_Types.LSLFloat(1.0e+3);" +
+ "\n y = new LSL_Types.LSLFloat(1.0E-3);" +
+ "\n y = new LSL_Types.LSLFloat(1.0e-3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0E3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0e3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0E+3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0e+3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0E-3);" +
+ "\n y = -new LSL_Types.LSLFloat(1.0e-3);" +
+ "\n y = new LSL_Types.LSLFloat(12.0) + -new LSL_Types.LSLFloat(1.0E3) - new LSL_Types.LSLFloat(1.0e-2);" +
+ "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestUnaryAndBinaryOperators()
+ {
+ string input = @"// let's test a few more operators
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 2;
+ integer y = 1;
+ integer z = x ^ y;
+ x = ~ z;
+ x = ~(y && z);
+ y = x >> z;
+ z = y << x;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" +
+ "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(1);" +
+ "\n LSL_Types.LSLInteger z = x ^ y;" +
+ "\n x = ~z;" +
+ "\n x = ~(y && z);" +
+ "\n y = x >> z;" +
+ "\n z = y << x;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestTypecasts()
+ {
+ string input = @"// let's test typecasts
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ string s = """";
+ integer x = 1;
+
+ s = (string) x++;
+ s = (string) x;
+ s = (string) <0., 0., 0.>;
+ s = (string) <1., 1., 1., 1.>;
+ s = (integer) ""1"";
+ s = (string) llSomethingThatReturnsInteger();
+ s = (string) 134;
+ s = (string) (x ^ y | (z && l)) + (string) (x + y - 13);
+ llOwnerSay(""s is: "" + s);
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLString s = new LSL_Types.LSLString(\"\");" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
+ "\n s = (LSL_Types.LSLString) (x++);" +
+ "\n s = (LSL_Types.LSLString) (x);" +
+ "\n s = (LSL_Types.LSLString) (new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0)));" +
+ "\n s = (LSL_Types.LSLString) (new LSL_Types.Quaternion(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0)));" +
+ "\n s = (LSL_Types.LSLInteger) (new LSL_Types.LSLString(\"1\"));" +
+ "\n s = (LSL_Types.LSLString) (llSomethingThatReturnsInteger());" +
+ "\n s = (LSL_Types.LSLString) (new LSL_Types.LSLInteger(134));" +
+ "\n s = (LSL_Types.LSLString) (x ^ y | (z && l)) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13));" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"s is: \") + s);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestStates()
+ {
+ string input = @"// let's test states
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ llSay(0, ""Going to state 'statetwo'"");
+ state statetwo;
+ }
+}
+
+state statetwo
+{
+ state_entry()
+ {
+ llSay(0, ""Going to the default state"");
+ state default;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to state 'statetwo'\"));" +
+ "\n state(\"statetwo\");" +
+ "\n }" +
+ "\n public void statetwo_event_state_entry()" +
+ "\n {" +
+ "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to the default state\"));" +
+ "\n state(\"default\");" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestHexIntegerConstants()
+ {
+ string input = @"// let's test hex integers
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x = 0x23;
+ integer x = 0x2f34B;
+ integer x = 0x2F34b;
+ integer x = 0x2F34B;
+ integer x = 0x2f34b;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x23);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34B);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34b);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34B);" +
+ "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34b);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestJumps()
+ {
+ string input = @"// let's test jumps
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ jump here;
+ llOwnerSay(""Uh oh, the jump didn't work"");
+ @here;
+ llOwnerSay(""After the jump"");
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n goto here;" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"Uh oh, the jump didn't work\"));" +
+ "\n here:" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"After the jump\"));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestImplicitVariableInitialization()
+ {
+ string input = @"// let's test implicitly initializing variables
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer i; integer j = 14;
+ float f; float g = 14.0;
+ string s; string t = ""Hi there"";
+ list l; list m = [1, 2, 3];
+ vector v; vector w = <1.0, 0.1, 0.5>;
+ rotation r; rotation u = <0.8, 0.7, 0.6, llSomeFunc()>;
+ key k; key n = ""ping"";
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger i = 0;" +
+ "\n LSL_Types.LSLInteger j = new LSL_Types.LSLInteger(14);" +
+ "\n LSL_Types.LSLFloat f = 0.0;" +
+ "\n LSL_Types.LSLFloat g = new LSL_Types.LSLFloat(14.0);" +
+ "\n LSL_Types.LSLString s = \"\";" +
+ "\n LSL_Types.LSLString t = new LSL_Types.LSLString(\"Hi there\");" +
+ "\n LSL_Types.list l = new LSL_Types.list();" +
+ "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" +
+ "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0);" +
+ "\n LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5));" +
+ "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(0.0, 0.0, 0.0, 0.0);" +
+ "\n LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc());" +
+ "\n LSL_Types.LSLString k = \"\";" +
+ "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestMultipleEqualsExpression()
+ {
+ string input = @"// let's test x = y = 5 type expressions
+
+default
+{
+ touch_start(integer num_detected)
+ {
+ integer x;
+ integer y;
+ x = y = 5;
+ x += y -= 5;
+ llOwnerSay(""x is: "" + (string) x + "", y is: "" + (string) y);
+ }
+}
+";
+ string expected =
+ "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = 0;" +
+ "\n LSL_Types.LSLInteger y = 0;" +
+ "\n x = y = new LSL_Types.LSLInteger(5);" +
+ "\n x += y -= new LSL_Types.LSLInteger(5);" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x) + new LSL_Types.LSLString(\", y is: \") + (LSL_Types.LSLString) (y));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestUnaryExpressionLastInVectorConstant()
+ {
+ string input = @"// let's test unary expressions some more
+
+default
+{
+ state_entry()
+ {
+ vector v = ;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(x, y, -new LSL_Types.LSLFloat(0.5));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestVectorMemberPlusEquals()
+ {
+ string input = @"// let's test unary expressions some more
+
+default
+{
+ state_entry()
+ {
+ vector v = llGetPos();
+ v.z += 4;
+ v.z -= 4;
+ v.z *= 4;
+ v.z /= 4;
+ v.z %= 4;
+ }
+}
+";
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n LSL_Types.Vector3 v = llGetPos();" +
+ "\n v.z += new LSL_Types.LSLInteger(4);" +
+ "\n v.z -= new LSL_Types.LSLInteger(4);" +
+ "\n v.z *= new LSL_Types.LSLInteger(4);" +
+ "\n v.z /= new LSL_Types.LSLInteger(4);" +
+ "\n v.z %= new LSL_Types.LSLInteger(4);" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestWhileLoopWithNoBody()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ while (1<0);
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
+ "\n ;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestDoWhileLoopWithNoBody()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ do;
+ while (1<0);
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n do" +
+ "\n ;" +
+ "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIfWithNoBody()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ if (1<0);
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
+ "\n ;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestIfElseWithNoBody()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ if (1<0);
+ else;
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
+ "\n ;" +
+ "\n else" +
+ "\n ;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestForLoopWithNoBody()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ for (x = 4; 1<0; x += 2);
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n for (x = new LSL_Types.LSLInteger(4); new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
+ "\n ;" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestAssignmentInIfWhileDoWhile()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ integer x;
+
+ while (x = 14) llOwnerSay(""x is: "" + (string) x);
+
+ if (x = 24) llOwnerSay(""x is: "" + (string) x);
+
+ do
+ llOwnerSay(""x is: "" + (string) x);
+ while (x = 44);
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n LSL_Types.LSLInteger x = 0;" +
+ "\n while (x = new LSL_Types.LSLInteger(14))" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
+ "\n if (x = new LSL_Types.LSLInteger(24))" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
+ "\n do" +
+ "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
+ "\n while (x = new LSL_Types.LSLInteger(44));" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ public void TestLSLListHack()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ list l = [""hello""];
+ l = (l=[]) + l + ""world"";
+ }
+}";
+
+ string expected =
+ "\n public void default_event_state_entry()" +
+ "\n {" +
+ "\n LSL_Types.list l = new LSL_Types.list(new LSL_Types.LSLString(\"hello\"));" +
+ "\n l = (l = new LSL_Types.list()) + l + new LSL_Types.LSLString(\"world\");" +
+ "\n }\n";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = cg.Convert(input);
+ Assert.AreEqual(expected, output);
+ }
+
+ [Test]
+ [ExpectedException(typeof(Tools.CSToolsException))]
+ public void TestSyntaxError()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ integer y
+ }
+}
+";
+ try
+ {
+ CSCodeGenerator cg = new CSCodeGenerator();
+ cg.Convert(input);
+ }
+ catch (Tools.CSToolsException e)
+ {
+ // The syntax error is on line 6, char 5 (expected ';', found
+ // '}').
+ Regex r = new Regex("Line ([0-9]+), char ([0-9]+)");
+ Match m = r.Match(e.Message);
+ Assert.AreEqual("6", m.Groups[1].Value);
+ Assert.AreEqual("5", m.Groups[2].Value);
+
+ throw;
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(Tools.CSToolsException))]
+ public void TestSyntaxErrorDeclaringVariableInForLoop()
+ {
+ string input = @"default
+{
+ state_entry()
+ {
+ for (integer x = 0; x < 10; x++) llOwnerSay(""x is: "" + (string) x);
+ }
+}
+";
+ try
+ {
+ CSCodeGenerator cg = new CSCodeGenerator();
+ cg.Convert(input);
+ }
+ catch (Tools.CSToolsException e)
+ {
+ // The syntax error is on line 5, char 14 (Syntax error)
+ Regex r = new Regex("Line ([0-9]+), char ([0-9]+)");
+ Match m = r.Match(e.Message);
+ Assert.AreEqual("5", m.Groups[1].Value);
+ Assert.AreEqual("14", m.Groups[2].Value);
+
+ throw;
+ }
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
new file mode 100644
index 0000000..7725d8d
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.IO;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using Microsoft.CSharp;
+using NUnit.Framework;
+using OpenSim.Region.ScriptEngine.Shared.CodeTools;
+
+namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
+{
+ ///
+ /// Tests the LSL compiler. Among other things, test that error messages
+ /// generated by the C# compiler can be mapped to prper lines/columns in
+ /// the LSL source.
+ ///
+ [TestFixture]
+ public class CompilerTest
+ {
+ private string m_testDir;
+ private CSharpCodeProvider m_CSCodeProvider;
+ private CompilerParameters m_compilerParameters;
+ private CompilerResults m_compilerResults;
+
+ ///
+ /// Creates a temporary directory where build artifacts are stored.
+ ///
+ [TestFixtureSetUp]
+ public void Init()
+ {
+ m_testDir = Path.Combine(Path.GetTempPath(), "opensim_compilerTest_" + Path.GetRandomFileName());
+
+ if (!Directory.Exists(m_testDir))
+ {
+ // Create the temporary directory for housing build artifacts.
+ Directory.CreateDirectory(m_testDir);
+ }
+
+ // Create a CSCodeProvider and CompilerParameters.
+ m_CSCodeProvider = new CSharpCodeProvider();
+ m_compilerParameters = new CompilerParameters();
+
+ string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin");
+ m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
+ m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
+ m_compilerParameters.GenerateExecutable = false;
+ }
+
+ ///
+ /// Removes the temporary build directory and any build artifacts
+ /// inside it.
+ ///
+ [TestFixtureTearDown]
+ public void CleanUp()
+ {
+ if (Directory.Exists(m_testDir))
+ {
+ // Blow away the temporary directory with artifacts.
+ Directory.Delete(m_testDir, true);
+ }
+ }
+
+ ///
+ /// Test the C# compiler error message can be mapped to the correct
+ /// line/column in the LSL source when an undeclared variable is used.
+ ///
+ //[Test]
+ public void TestUseUndeclaredVariable()
+ {
+ m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");
+
+ string input = @"default
+{
+ state_entry()
+ {
+ integer y = x + 3;
+ }
+}";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" +
+ "namespace SecondLife { " +
+ "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" +
+ "public Script() { } " +
+ cg.Convert(input) +
+ "} }\n";
+ Dictionary, KeyValuePair> positionMap = cg.PositionMap;
+
+ m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
+
+ Assert.AreEqual(new KeyValuePair(5, 21),
+ positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
+ }
+
+ ///
+ /// Test that a string can be cast to string and another string
+ /// concatenated.
+ ///
+ //[Test]
+ public void TestCastAndConcatString()
+ {
+ m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");
+
+ string input = @"string s = "" a string"";
+
+default
+{
+ state_entry()
+ {
+ key gAvatarKey = llDetectedKey(0);
+ string tmp = (string) gAvatarKey + s;
+ llSay(0, tmp);
+ }
+}";
+
+ CSCodeGenerator cg = new CSCodeGenerator();
+ string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" +
+ "namespace SecondLife { " +
+ "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" +
+ "public Script() { } " +
+ cg.Convert(input) +
+ "} }\n";
+ m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
+
+ Assert.AreEqual(0, m_compilerResults.Errors.Count);
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs
new file mode 100644
index 0000000..272d06c
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs
@@ -0,0 +1,603 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using OpenSim.Tests.Common;
+using OpenSim.Region.ScriptEngine.Shared;
+
+namespace OpenSim.Region.ScriptEngine.Shared.Tests
+{
+ [TestFixture]
+ public class LSL_TypesTestLSLFloat
+ {
+ // Used for testing equality of two floats.
+ private double _lowPrecisionTolerance = 0.000001;
+
+ private Dictionary m_intDoubleSet;
+ private Dictionary m_doubleDoubleSet;
+ private Dictionary m_doubleIntSet;
+ private Dictionary m_doubleUintSet;
+ private Dictionary m_stringDoubleSet;
+ private Dictionary m_doubleStringSet;
+ private List m_intList;
+ private List m_doubleList;
+
+ ///
+ /// Sets up dictionaries and arrays used in the tests.
+ ///
+ [TestFixtureSetUp]
+ public void SetUpDataSets()
+ {
+ m_intDoubleSet = new Dictionary();
+ m_intDoubleSet.Add(2, 2.0);
+ m_intDoubleSet.Add(-2, -2.0);
+ m_intDoubleSet.Add(0, 0.0);
+ m_intDoubleSet.Add(1, 1.0);
+ m_intDoubleSet.Add(-1, -1.0);
+ m_intDoubleSet.Add(999999999, 999999999.0);
+ m_intDoubleSet.Add(-99999999, -99999999.0);
+
+ m_doubleDoubleSet = new Dictionary();
+ m_doubleDoubleSet.Add(2.0, 2.0);
+ m_doubleDoubleSet.Add(-2.0, -2.0);
+ m_doubleDoubleSet.Add(0.0, 0.0);
+ m_doubleDoubleSet.Add(1.0, 1.0);
+ m_doubleDoubleSet.Add(-1.0, -1.0);
+ m_doubleDoubleSet.Add(999999999.0, 999999999.0);
+ m_doubleDoubleSet.Add(-99999999.0, -99999999.0);
+ m_doubleDoubleSet.Add(0.5, 0.5);
+ m_doubleDoubleSet.Add(0.0005, 0.0005);
+ m_doubleDoubleSet.Add(0.6805, 0.6805);
+ m_doubleDoubleSet.Add(-0.5, -0.5);
+ m_doubleDoubleSet.Add(-0.0005, -0.0005);
+ m_doubleDoubleSet.Add(-0.6805, -0.6805);
+ m_doubleDoubleSet.Add(548.5, 548.5);
+ m_doubleDoubleSet.Add(2.0005, 2.0005);
+ m_doubleDoubleSet.Add(349485435.6805, 349485435.6805);
+ m_doubleDoubleSet.Add(-548.5, -548.5);
+ m_doubleDoubleSet.Add(-2.0005, -2.0005);
+ m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805);
+
+ m_doubleIntSet = new Dictionary();
+ m_doubleIntSet.Add(2.0, 2);
+ m_doubleIntSet.Add(-2.0, -2);
+ m_doubleIntSet.Add(0.0, 0);
+ m_doubleIntSet.Add(1.0, 1);
+ m_doubleIntSet.Add(-1.0, -1);
+ m_doubleIntSet.Add(999999999.0, 999999999);
+ m_doubleIntSet.Add(-99999999.0, -99999999);
+ m_doubleIntSet.Add(0.5, 0);
+ m_doubleIntSet.Add(0.0005, 0);
+ m_doubleIntSet.Add(0.6805, 0);
+ m_doubleIntSet.Add(-0.5, 0);
+ m_doubleIntSet.Add(-0.0005, 0);
+ m_doubleIntSet.Add(-0.6805, 0);
+ m_doubleIntSet.Add(548.5, 548);
+ m_doubleIntSet.Add(2.0005, 2);
+ m_doubleIntSet.Add(349485435.6805, 349485435);
+ m_doubleIntSet.Add(-548.5, -548);
+ m_doubleIntSet.Add(-2.0005, -2);
+ m_doubleIntSet.Add(-349485435.6805, -349485435);
+
+ m_doubleUintSet = new Dictionary();
+ m_doubleUintSet.Add(2.0, 2);
+ m_doubleUintSet.Add(-2.0, 2);
+ m_doubleUintSet.Add(0.0, 0);
+ m_doubleUintSet.Add(1.0, 1);
+ m_doubleUintSet.Add(-1.0, 1);
+ m_doubleUintSet.Add(999999999.0, 999999999);
+ m_doubleUintSet.Add(-99999999.0, 99999999);
+ m_doubleUintSet.Add(0.5, 0);
+ m_doubleUintSet.Add(0.0005, 0);
+ m_doubleUintSet.Add(0.6805, 0);
+ m_doubleUintSet.Add(-0.5, 0);
+ m_doubleUintSet.Add(-0.0005, 0);
+ m_doubleUintSet.Add(-0.6805, 0);
+ m_doubleUintSet.Add(548.5, 548);
+ m_doubleUintSet.Add(2.0005, 2);
+ m_doubleUintSet.Add(349485435.6805, 349485435);
+ m_doubleUintSet.Add(-548.5, 548);
+ m_doubleUintSet.Add(-2.0005, 2);
+ m_doubleUintSet.Add(-349485435.6805, 349485435);
+
+ m_stringDoubleSet = new Dictionary();
+ m_stringDoubleSet.Add("2", 2.0);
+ m_stringDoubleSet.Add("-2", -2.0);
+ m_stringDoubleSet.Add("1", 1.0);
+ m_stringDoubleSet.Add("-1", -1.0);
+ m_stringDoubleSet.Add("0", 0.0);
+ m_stringDoubleSet.Add("999999999.0", 999999999.0);
+ m_stringDoubleSet.Add("-99999999.0", -99999999.0);
+ m_stringDoubleSet.Add("0.5", 0.5);
+ m_stringDoubleSet.Add("0.0005", 0.0005);
+ m_stringDoubleSet.Add("0.6805", 0.6805);
+ m_stringDoubleSet.Add("-0.5", -0.5);
+ m_stringDoubleSet.Add("-0.0005", -0.0005);
+ m_stringDoubleSet.Add("-0.6805", -0.6805);
+ m_stringDoubleSet.Add("548.5", 548.5);
+ m_stringDoubleSet.Add("2.0005", 2.0005);
+ m_stringDoubleSet.Add("349485435.6805", 349485435.6805);
+ m_stringDoubleSet.Add("-548.5", -548.5);
+ m_stringDoubleSet.Add("-2.0005", -2.0005);
+ m_stringDoubleSet.Add("-349485435.6805", -349485435.6805);
+
+ m_doubleStringSet = new Dictionary();
+ m_doubleStringSet.Add(2.0, "2.000000");
+ m_doubleStringSet.Add(-2.0, "-2.000000");
+ m_doubleStringSet.Add(1.0, "1.000000");
+ m_doubleStringSet.Add(-1.0, "-1.000000");
+ m_doubleStringSet.Add(0.0, "0.000000");
+ m_doubleStringSet.Add(999999999.0, "999999999.000000");
+ m_doubleStringSet.Add(-99999999.0, "-99999999.000000");
+ m_doubleStringSet.Add(0.5, "0.500000");
+ m_doubleStringSet.Add(0.0005, "0.000500");
+ m_doubleStringSet.Add(0.6805, "0.680500");
+ m_doubleStringSet.Add(-0.5, "-0.500000");
+ m_doubleStringSet.Add(-0.0005, "-0.000500");
+ m_doubleStringSet.Add(-0.6805, "-0.680500");
+ m_doubleStringSet.Add(548.5, "548.500000");
+ m_doubleStringSet.Add(2.0005, "2.000500");
+ m_doubleStringSet.Add(349485435.6805, "349485435.680500");
+ m_doubleStringSet.Add(-548.5, "-548.500000");
+ m_doubleStringSet.Add(-2.0005, "-2.000500");
+ m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
+
+ m_doubleList = new List();
+ m_doubleList.Add(2.0);
+ m_doubleList.Add(-2.0);
+ m_doubleList.Add(1.0);
+ m_doubleList.Add(-1.0);
+ m_doubleList.Add(999999999.0);
+ m_doubleList.Add(-99999999.0);
+ m_doubleList.Add(0.5);
+ m_doubleList.Add(0.0005);
+ m_doubleList.Add(0.6805);
+ m_doubleList.Add(-0.5);
+ m_doubleList.Add(-0.0005);
+ m_doubleList.Add(-0.6805);
+ m_doubleList.Add(548.5);
+ m_doubleList.Add(2.0005);
+ m_doubleList.Add(349485435.6805);
+ m_doubleList.Add(-548.5);
+ m_doubleList.Add(-2.0005);
+ m_doubleList.Add(-349485435.6805);
+
+ m_intList = new List();
+ m_intList.Add(2);
+ m_intList.Add(-2);
+ m_intList.Add(0);
+ m_intList.Add(1);
+ m_intList.Add(-1);
+ m_intList.Add(999999999);
+ m_intList.Add(-99999999);
+ }
+
+ ///
+ /// Tests constructing a LSLFloat from an integer.
+ ///
+ [Test]
+ public void TestConstructFromInt()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (KeyValuePair number in m_intDoubleSet)
+ {
+ testFloat = new LSL_Types.LSLFloat(number.Key);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests constructing a LSLFloat from a double.
+ ///
+ [Test]
+ public void TestConstructFromDouble()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (KeyValuePair number in m_doubleDoubleSet)
+ {
+ testFloat = new LSL_Types.LSLFloat(number.Key);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast explicitly to integer.
+ ///
+ [Test]
+ public void TestExplicitCastLSLFloatToInt()
+ {
+ int testNumber;
+
+ foreach (KeyValuePair number in m_doubleIntSet)
+ {
+ testNumber = (int) new LSL_Types.LSLFloat(number.Key);
+ Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value);
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast explicitly to unsigned integer.
+ ///
+ [Test]
+ public void TestExplicitCastLSLFloatToUint()
+ {
+ uint testNumber;
+
+ foreach (KeyValuePair number in m_doubleUintSet)
+ {
+ testNumber = (uint) new LSL_Types.LSLFloat(number.Key);
+ Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value);
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero.
+ ///
+ [Test]
+ public void TestImplicitCastLSLFloatToBooleanTrue()
+ {
+ LSL_Types.LSLFloat testFloat;
+ bool testBool;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloat = new LSL_Types.LSLFloat(number);
+ testBool = testFloat;
+
+ Assert.IsTrue(testBool);
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast implicitly to Boolean if zero.
+ ///
+ [Test]
+ public void TestImplicitCastLSLFloatToBooleanFalse()
+ {
+ LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0);
+ bool testBool = testFloat;
+
+ Assert.IsFalse(testBool);
+ }
+
+ ///
+ /// Tests integer is correctly cast implicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestImplicitCastIntToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (int number in m_intList)
+ {
+ testFloat = number;
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLInteger is correctly cast implicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestImplicitCastLSLIntegerToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (int number in m_intList)
+ {
+ testFloat = new LSL_Types.LSLInteger(number);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLInteger is correctly cast explicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestExplicitCastLSLIntegerToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (int number in m_intList)
+ {
+ testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests string is correctly cast explicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestExplicitCastStringToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (KeyValuePair number in m_stringDoubleSet)
+ {
+ testFloat = (LSL_Types.LSLFloat) number.Key;
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLString is correctly cast implicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestExplicitCastLSLStringToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (KeyValuePair number in m_stringDoubleSet)
+ {
+ testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests double is correctly cast implicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestImplicitCastDoubleToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloat = number;
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast implicitly to double.
+ ///
+ [Test]
+ public void TestImplicitCastLSLFloatToDouble()
+ {
+ double testNumber;
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloat = new LSL_Types.LSLFloat(number);
+ testNumber = testFloat;
+
+ Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLFloat is correctly cast explicitly to float
+ ///
+ [Test]
+ public void TestExplicitCastLSLFloatToFloat()
+ {
+ float testFloat;
+ float numberAsFloat;
+ LSL_Types.LSLFloat testLSLFloat;
+ foreach (double number in m_doubleList)
+ {
+ testLSLFloat = new LSL_Types.LSLFloat(number);
+ numberAsFloat = (float)number;
+ testFloat = (float)testLSLFloat;
+
+ Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance));
+ }
+ }
+
+
+ ///
+ /// Tests the equality (==) operator.
+ ///
+ [Test]
+ public void TestEqualsOperator()
+ {
+ LSL_Types.LSLFloat testFloatA, testFloatB;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloatA = new LSL_Types.LSLFloat(number);
+ testFloatB = new LSL_Types.LSLFloat(number);
+ Assert.IsTrue(testFloatA == testFloatB);
+
+ testFloatB = new LSL_Types.LSLFloat(number + 1.0);
+ Assert.IsFalse(testFloatA == testFloatB);
+ }
+ }
+
+ ///
+ /// Tests the inequality (!=) operator.
+ ///
+ [Test]
+ public void TestNotEqualOperator()
+ {
+ LSL_Types.LSLFloat testFloatA, testFloatB;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloatA = new LSL_Types.LSLFloat(number);
+ testFloatB = new LSL_Types.LSLFloat(number + 1.0);
+ Assert.IsTrue(testFloatA != testFloatB);
+
+ testFloatB = new LSL_Types.LSLFloat(number);
+ Assert.IsFalse(testFloatA != testFloatB);
+ }
+ }
+
+ ///
+ /// Tests the increment operator.
+ ///
+ [Test]
+ public void TestIncrementOperator()
+ {
+ LSL_Types.LSLFloat testFloat;
+ double testNumber;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloat = new LSL_Types.LSLFloat(number);
+
+ testNumber = testFloat++;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+
+ testNumber = testFloat;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance));
+
+ testNumber = ++testFloat;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests the decrement operator.
+ ///
+ [Test]
+ public void TestDecrementOperator()
+ {
+ LSL_Types.LSLFloat testFloat;
+ double testNumber;
+
+ foreach (double number in m_doubleList)
+ {
+ testFloat = new LSL_Types.LSLFloat(number);
+
+ testNumber = testFloat--;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
+
+ testNumber = testFloat;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance));
+
+ testNumber = --testFloat;
+ Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests LSLFloat.ToString().
+ ///
+ [Test]
+ public void TestToString()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ foreach (KeyValuePair number in m_doubleStringSet)
+ {
+ testFloat = new LSL_Types.LSLFloat(number.Key);
+ Assert.AreEqual(number.Value, testFloat.ToString());
+ }
+ }
+
+ ///
+ /// Tests addition of two LSLFloats.
+ ///
+ [Test]
+ public void TestAddTwoLSLFloats()
+ {
+ LSL_Types.LSLFloat testResult;
+
+ foreach (KeyValuePair number in m_doubleDoubleSet)
+ {
+ testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value);
+ Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests subtraction of two LSLFloats.
+ ///
+ [Test]
+ public void TestSubtractTwoLSLFloats()
+ {
+ LSL_Types.LSLFloat testResult;
+
+ foreach (KeyValuePair number in m_doubleDoubleSet)
+ {
+ testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value);
+ Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests multiplication of two LSLFloats.
+ ///
+ [Test]
+ public void TestMultiplyTwoLSLFloats()
+ {
+ LSL_Types.LSLFloat testResult;
+
+ foreach (KeyValuePair number in m_doubleDoubleSet)
+ {
+ testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value);
+ Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance));
+ }
+ }
+
+ ///
+ /// Tests division of two LSLFloats.
+ ///
+ [Test]
+ public void TestDivideTwoLSLFloats()
+ {
+ LSL_Types.LSLFloat testResult;
+
+ foreach (KeyValuePair number in m_doubleDoubleSet)
+ {
+ if (number.Value != 0.0) // Let's avoid divide by zero.
+ {
+ testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value);
+ Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance));
+ }
+ }
+ }
+
+ ///
+ /// Tests boolean correctly cast implicitly to LSLFloat.
+ ///
+ [Test]
+ public void TestImplicitCastBooleanToLSLFloat()
+ {
+ LSL_Types.LSLFloat testFloat;
+
+ testFloat = (1 == 0);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance));
+
+ testFloat = (1 == 1);
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance));
+
+ testFloat = false;
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance));
+
+ testFloat = true;
+ Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance));
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
new file mode 100644
index 0000000..f826c00
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using OpenSim.Tests.Common;
+using OpenSim.Region.ScriptEngine.Shared;
+
+namespace OpenSim.Region.ScriptEngine.Shared.Tests
+{
+ [TestFixture]
+ public class LSL_TypesTestLSLInteger
+ {
+ private Dictionary m_doubleIntSet;
+ private Dictionary m_stringIntSet;
+
+ ///
+ /// Sets up dictionaries and arrays used in the tests.
+ ///
+ [TestFixtureSetUp]
+ public void SetUpDataSets()
+ {
+ m_doubleIntSet = new Dictionary();
+ m_doubleIntSet.Add(2.0, 2);
+ m_doubleIntSet.Add(-2.0, -2);
+ m_doubleIntSet.Add(0.0, 0);
+ m_doubleIntSet.Add(1.0, 1);
+ 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 LSLFloat is correctly cast explicitly to LSLInteger.
+ ///
+ [Test]
+ public void TestExplicitCastLSLFloatToLSLInteger()
+ {
+ LSL_Types.LSLInteger testInteger;
+
+ foreach (KeyValuePair number in m_doubleIntSet)
+ {
+ testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key);
+ 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);
+ }
+ }
+
+ ///
+ /// Tests boolean correctly cast implicitly to LSLInteger.
+ ///
+ [Test]
+ public void TestImplicitCastBooleanToLSLInteger()
+ {
+ LSL_Types.LSLInteger testInteger;
+
+ testInteger = (1 == 0);
+ Assert.AreEqual(0, testInteger.value);
+
+ testInteger = (1 == 1);
+ Assert.AreEqual(1, testInteger.value);
+
+ testInteger = false;
+ Assert.AreEqual(0, testInteger.value);
+
+ testInteger = true;
+ Assert.AreEqual(1, testInteger.value);
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs
new file mode 100644
index 0000000..49e5023
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLString.cs
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using OpenSim.Tests.Common;
+using OpenSim.Region.ScriptEngine.Shared;
+
+namespace OpenSim.Region.ScriptEngine.Shared.Tests
+{
+ [TestFixture]
+ public class LSL_TypesTestLSLString
+ {
+ private Dictionary m_doubleStringSet;
+
+ ///
+ /// Sets up dictionaries and arrays used in the tests.
+ ///
+ [TestFixtureSetUp]
+ public void SetUpDataSets()
+ {
+ m_doubleStringSet = new Dictionary();
+ m_doubleStringSet.Add(2, "2.000000");
+ m_doubleStringSet.Add(-2, "-2.000000");
+ m_doubleStringSet.Add(0, "0.000000");
+ m_doubleStringSet.Add(1, "1.000000");
+ m_doubleStringSet.Add(-1, "-1.000000");
+ m_doubleStringSet.Add(999999999, "999999999.000000");
+ m_doubleStringSet.Add(-99999999, "-99999999.000000");
+ m_doubleStringSet.Add(0.5, "0.500000");
+ m_doubleStringSet.Add(0.0005, "0.000500");
+ m_doubleStringSet.Add(0.6805, "0.680500");
+ m_doubleStringSet.Add(-0.5, "-0.500000");
+ m_doubleStringSet.Add(-0.0005, "-0.000500");
+ m_doubleStringSet.Add(-0.6805, "-0.680500");
+ m_doubleStringSet.Add(548.5, "548.500000");
+ m_doubleStringSet.Add(2.0005, "2.000500");
+ m_doubleStringSet.Add(349485435.6805, "349485435.680500");
+ m_doubleStringSet.Add(-548.5, "-548.500000");
+ m_doubleStringSet.Add(-2.0005, "-2.000500");
+ m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
+ }
+
+ ///
+ /// Tests constructing a LSLString from an LSLFloat.
+ ///
+ [Test]
+ public void TestConstructFromLSLFloat()
+ {
+ LSL_Types.LSLString testString;
+
+ foreach (KeyValuePair number in m_doubleStringSet)
+ {
+ testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
+ Assert.AreEqual(number.Value, testString.m_string);
+ }
+ }
+
+ ///
+ /// Tests constructing a LSLString from an LSLFloat.
+ ///
+ [Test]
+ public void TestExplicitCastLSLFloatToLSLString()
+ {
+ LSL_Types.LSLString testString;
+
+ foreach (KeyValuePair number in m_doubleStringSet)
+ {
+ testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
+ Assert.AreEqual(number.Value, testString.m_string);
+ }
+ }
+
+ ///
+ /// Test constructing a Quaternion from a string.
+ ///
+ [Test]
+ public void TestExplicitCastLSLStringToQuaternion()
+ {
+ string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
+ LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);
+
+ LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
+ LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
+ LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;
+
+ Assert.AreEqual(expectedQuaternion, stringQuaternion);
+ Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
+ }
+
+ ///
+ /// Tests boolean correctly cast explicitly to LSLString.
+ ///
+ [Test]
+ public void TestImplicitCastBooleanToLSLFloat()
+ {
+ LSL_Types.LSLString testString;
+
+ testString = (LSL_Types.LSLString) (1 == 0);
+ Assert.AreEqual("0", testString.m_string);
+
+ testString = (LSL_Types.LSLString) (1 == 1);
+ Assert.AreEqual("1", testString.m_string);
+
+ testString = (LSL_Types.LSLString) false;
+ Assert.AreEqual("0", testString.m_string);
+
+ testString = (LSL_Types.LSLString) true;
+ Assert.AreEqual("1", testString.m_string);
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs
new file mode 100644
index 0000000..7da28dd
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestList.cs
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using OpenSim.Tests.Common;
+using OpenSim.Region.ScriptEngine.Shared;
+
+namespace OpenSim.Region.ScriptEngine.Shared.Tests
+{
+ ///
+ /// Tests the LSL_Types.list class.
+ ///
+ [TestFixture]
+ public class LSL_TypesTestList
+ {
+ ///
+ /// Tests concatenating a string to a list.
+ ///
+ [Test]
+ public void TestConcatenateString()
+ {
+ 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(new LSL_Types.LSLString("addition"), testList.Data[3]);
+ Assert.AreEqual(typeof(LSL_Types.LSLString), testList.Data[3].GetType());
+
+ LSL_Types.list secondTestList = testList + new LSL_Types.LSLString("more");
+
+ Assert.AreEqual(5, secondTestList.Length);
+ Assert.AreEqual(new LSL_Types.LSLString("more"), secondTestList.Data[4]);
+ Assert.AreEqual(typeof(LSL_Types.LSLString), secondTestList.Data[4].GetType());
+ }
+
+ ///
+ /// Tests concatenating an integer to a list.
+ ///
+ [Test]
+ public void TestConcatenateInteger()
+ {
+ 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(new LSL_Types.LSLInteger(20), testList.Data[3]);
+ Assert.AreEqual(typeof(LSL_Types.LSLInteger), testList.Data[3].GetType());
+
+ LSL_Types.list secondTestList = testList + new LSL_Types.LSLInteger(2);
+
+ Assert.AreEqual(5, secondTestList.Length);
+ Assert.AreEqual(new LSL_Types.LSLInteger(2), secondTestList.Data[4]);
+ Assert.AreEqual(typeof(LSL_Types.LSLInteger), secondTestList.Data[4].GetType());
+ }
+
+ ///
+ /// Tests concatenating a float to a list.
+ ///
+ [Test]
+ public void TestConcatenateDouble()
+ {
+ 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(new LSL_Types.LSLFloat(2.0f), testList.Data[3]);
+ Assert.AreEqual(typeof(LSL_Types.LSLFloat), testList.Data[3].GetType());
+
+ LSL_Types.list secondTestList = testList + new LSL_Types.LSLFloat(0.04f);
+
+ Assert.AreEqual(5, secondTestList.Length);
+ Assert.AreEqual(new LSL_Types.LSLFloat(0.04f), secondTestList.Data[4]);
+ Assert.AreEqual(typeof(LSL_Types.LSLFloat), secondTestList.Data[4].GetType());
+ }
+
+ ///
+ /// Tests casting LSLInteger item to LSLInteger.
+ ///
+ [Test]
+ public void TestCastLSLIntegerItemToLSLInteger()
+ {
+ LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, (LSL_Types.LSLInteger)testList.Data[0]);
+ }
+
+ ///
+ /// Tests casting LSLFloat item to LSLFloat.
+ ///
+ [Test]
+ public void TestCastLSLFloatItemToLSLFloat()
+ {
+ LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, (LSL_Types.LSLFloat)testList.Data[0]);
+ }
+
+ ///
+ /// Tests casting LSLString item to LSLString.
+ ///
+ [Test]
+ public void TestCastLSLStringItemToLSLString()
+ {
+ LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there");
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, (LSL_Types.LSLString)testList.Data[0]);
+ }
+
+ ///
+ /// Tests casting Vector3 item to Vector3.
+ ///
+ [Test]
+ public void TestCastVector3ItemToVector3()
+ {
+ LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]);
+ }
+ ///
+ /// Tests casting Quaternion item to Quaternion.
+ ///
+ [Test]
+ public void TestCastQuaternionItemToQuaternion()
+ {
+ LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]);
+ }
+
+//====================================================================================
+
+ ///
+ /// Tests GetLSLIntegerItem for LSLInteger item.
+ ///
+ [Test]
+ public void TestGetLSLIntegerItemForLSLIntegerItem()
+ {
+ LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetLSLIntegerItem(0));
+ }
+
+ ///
+ /// Tests GetLSLFloatItem for LSLFloat item.
+ ///
+ [Test]
+ public void TestGetLSLFloatItemForLSLFloatItem()
+ {
+ LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetLSLFloatItem(0));
+ }
+
+ ///
+ /// Tests GetLSLFloatItem for LSLInteger item.
+ ///
+ [Test]
+ public void TestGetLSLFloatItemForLSLIntegerItem()
+ {
+ LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987);
+ LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0));
+ }
+
+ ///
+ /// Tests GetLSLStringItem for LSLString item.
+ ///
+ [Test]
+ public void TestGetLSLStringItemForLSLStringItem()
+ {
+ LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all");
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetLSLStringItem(0));
+ }
+
+ ///
+ /// Tests GetLSLStringItem for key item.
+ ///
+ [Test]
+ public void TestGetLSLStringItemForKeyItem()
+ {
+ LSL_Types.key testValue
+ = new LSL_Types.key("98000000-0000-2222-3333-100000001000");
+ LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testStringValue, testList.GetLSLStringItem(0));
+ }
+
+ ///
+ /// Tests GetVector3Item for Vector3 item.
+ ///
+ [Test]
+ public void TestGetVector3ItemForVector3Item()
+ {
+ LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetVector3Item(0));
+ }
+ ///
+ /// Tests GetQuaternionItem for Quaternion item.
+ ///
+ [Test]
+ public void TestGetQuaternionItemForQuaternionItem()
+ {
+ LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987);
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetQuaternionItem(0));
+ }
+
+ ///
+ /// Tests GetKeyItem for key item.
+ ///
+ [Test]
+ public void TestGetKeyItemForKeyItem()
+ {
+ LSL_Types.key testValue
+ = new LSL_Types.key("00000000-0000-2222-3333-100000001012");
+ LSL_Types.list testList = new LSL_Types.list(testValue);
+
+ Assert.AreEqual(testValue, testList.GetKeyItem(0));
+ }
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs
new file mode 100644
index 0000000..fb2c00c
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestVector3.cs
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using OpenSim.Tests.Common;
+using OpenSim.Region.ScriptEngine.Shared;
+
+namespace OpenSim.Region.ScriptEngine.Shared.Tests
+{
+ [TestFixture]
+ public class LSL_TypesTestVector3
+ {
+ ///
+ /// Tests for Vector3
+ ///
+ [Test]
+
+ public void TestDotProduct()
+ {
+ // The numbers we test for.
+ Dictionary expectsSet = new Dictionary();
+ expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0);
+ expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0);
+
+ double result;
+ string[] parts;
+ string[] delim = { "*" };
+
+ foreach (KeyValuePair ex in expectsSet)
+ {
+ parts = ex.Key.Split(delim, System.StringSplitOptions.None);
+ result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]);
+ Assert.AreEqual(ex.Value, result);
+ }
+ }
+ }
+}
--
cgit v1.1