changes to Test directory structure per opensim-dev conversation

This commit is contained in:
Sean Dague
2008-09-08 20:34:45 +00:00
parent 41a68ca5db
commit ce0a8d7bef
17 changed files with 23 additions and 16 deletions

View File

@@ -0,0 +1,583 @@
/*
* 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.Common;
namespace OpenSim.Region.ScriptEngine.Common.Tests
{
[TestFixture]
public class LSL_TypesTestLSLFloat
{
// Used for testing equality of two floats.
private double _lowPrecisionTolerance = 0.000001;
private Dictionary<int, double> m_intDoubleSet;
private Dictionary<double, double> m_doubleDoubleSet;
private Dictionary<double, int> m_doubleIntSet;
private Dictionary<double, int> m_doubleUintSet;
private Dictionary<string, double> m_stringDoubleSet;
private Dictionary<double, string> m_doubleStringSet;
private List<int> m_intList;
private List<double> m_doubleList;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_intDoubleSet = new Dictionary<int, double>();
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<double, double>();
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<double, int>();
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<double, int>();
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<string, double>();
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<double, string>();
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<double>();
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<int>();
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);
}
/// <summary>
/// Tests constructing a LSLFloat from an integer.
/// </summary>
[Test]
public void TestConstructFromInt()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<int, double> number in m_intDoubleSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests constructing a LSLFloat from a double.
/// </summary>
[Test]
public void TestConstructFromDouble()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to integer.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToInt()
{
int testNumber;
foreach (KeyValuePair<double, int> 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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to unsigned integer.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToUint()
{
uint testNumber;
foreach (KeyValuePair<double, int> 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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero.
/// </summary>
[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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to Boolean if zero.
/// </summary>
[Test]
public void TestImplicitCastLSLFloatToBooleanFalse()
{
LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0);
bool testBool = testFloat;
Assert.IsFalse(testBool);
}
/// <summary>
/// Tests integer is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestImplicitCastIntToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (int number in m_intList)
{
testFloat = number;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLInteger is correctly cast implicitly to LSLFloat.
/// </summary>
[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));
}
}
/// <summary>
/// Tests LSLInteger is correctly cast explicitly to LSLFloat.
/// </summary>
[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));
}
}
/// <summary>
/// Tests string is correctly cast explicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastStringToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
{
testFloat = (LSL_Types.LSLFloat) number.Key;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLString is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLStringToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
{
testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests double is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestImplicitCastDoubleToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (double number in m_doubleList)
{
testFloat = number;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to double.
/// </summary>
[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));
}
}
/// <summary>
/// Tests the equality (==) operator.
/// </summary>
[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);
}
}
/// <summary>
/// Tests the inequality (!=) operator.
/// </summary>
[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);
}
}
/// <summary>
/// Tests the increment operator.
/// </summary>
[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));
}
}
/// <summary>
/// Tests the decrement operator.
/// </summary>
[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));
}
}
/// <summary>
/// Tests LSLFloat.ToString().
/// </summary>
[Test]
public void TestToString()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(number.Value, testFloat.ToString());
}
}
/// <summary>
/// Tests addition of two LSLFloats.
/// </summary>
[Test]
public void TestAddTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests subtraction of two LSLFloats.
/// </summary>
[Test]
public void TestSubtractTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests multiplication of two LSLFloats.
/// </summary>
[Test]
public void TestMultiplyTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests division of two LSLFloats.
/// </summary>
[Test]
public void TestDivideTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
}
/// <summary>
/// Tests boolean correctly cast implicitly to LSLFloat.
/// </summary>
[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));
}
}
}

View File

@@ -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.Common;
namespace OpenSim.Region.ScriptEngine.Common.Tests
{
[TestFixture]
public class LSL_TypesTestLSLInteger
{
private Dictionary<double, int> m_doubleIntSet;
private Dictionary<string, int> m_stringIntSet;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_doubleIntSet = new Dictionary<double, int>();
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<string, int>();
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);
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<double, int> number in m_doubleIntSet)
{
testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests string is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastStringToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<string, int> number in m_stringIntSet)
{
testInteger = (LSL_Types.LSLInteger) number.Key;
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests LSLString is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastLSLStringToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<string, int> number in m_stringIntSet)
{
testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key);
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests boolean correctly cast implicitly to LSLInteger.
/// </summary>
[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);
}
}
}

View File

@@ -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.Common;
namespace OpenSim.Region.ScriptEngine.Common.Tests
{
[TestFixture]
public class LSL_TypesTestLSLString
{
private Dictionary<double, string> m_doubleStringSet;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_doubleStringSet = new Dictionary<double, string>();
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");
}
/// <summary>
/// Tests constructing a LSLString from an LSLFloat.
/// </summary>
[Test]
public void TestConstructFromLSLFloat()
{
LSL_Types.LSLString testString;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
Assert.AreEqual(number.Value, testString.m_string);
}
}
/// <summary>
/// Tests constructing a LSLString from an LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToLSLString()
{
LSL_Types.LSLString testString;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(number.Value, testString.m_string);
}
}
/// <summary>
/// Test constructing a Quaternion from a string.
/// </summary>
[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);
}
/// <summary>
/// Tests boolean correctly cast explicitly to LSLString.
/// </summary>
[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);
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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.Common;
namespace OpenSim.Region.ScriptEngine.Common.Tests
{
/// <summary>
/// Tests the LSL_Types.list class.
/// </summary>
[TestFixture]
public class LSL_TypesTestList
{
/// <summary>
/// Tests concatenating a string to a list.
/// </summary>
[Test]
public void TestConcatenateString()
{
LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
testList += "addition";
Assert.AreEqual(4, testList.Length);
Assert.AreEqual("addition", testList.Data[3]);
Assert.AreEqual(typeof(System.String), testList.Data[3].GetType());
LSL_Types.list secondTestList = testList + "more";
Assert.AreEqual(5, secondTestList.Length);
Assert.AreEqual("more", secondTestList.Data[4]);
Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType());
}
/// <summary>
/// Tests concatenating an integer to a list.
/// </summary>
[Test]
public void TestConcatenateInteger()
{
LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
testList += 20;
Assert.AreEqual(4, testList.Length);
Assert.AreEqual(20, testList.Data[3]);
Assert.AreEqual(typeof(int), testList.Data[3].GetType());
LSL_Types.list secondTestList = testList + 2;
Assert.AreEqual(5, secondTestList.Length);
Assert.AreEqual(2, secondTestList.Data[4]);
Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType());
}
/// <summary>
/// Tests concatenating a double to a list.
/// </summary>
[Test]
public void TestConcatenateDouble()
{
LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
testList += 2.0;
Assert.AreEqual(4, testList.Length);
Assert.AreEqual(2.0, testList.Data[3]);
Assert.AreEqual(typeof(double), testList.Data[3].GetType());
LSL_Types.list secondTestList = testList + 0.04;
Assert.AreEqual(5, secondTestList.Length);
Assert.AreEqual(0.04, secondTestList.Data[4]);
Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType());
}
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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.Common;
using vector = OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3;
namespace OpenSim.Region.ScriptEngine.Common.Tests
{
[TestFixture]
public class LSL_TypesTestVector3
{
/// <summary>
/// Tests for Vector3
/// </summary>
[Test]
public void TestDotProduct()
{
// The numbers we test for.
Dictionary<string, double> expectsSet = new Dictionary<string, double>();
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<string, double> ex in expectsSet)
{
parts = ex.Key.Split(delim, System.StringSplitOptions.None);
result = new vector(parts[0]) * new vector(parts[1]);
Assert.AreEqual(ex.Value, result);
}
}
[Test]
public void TestUnaryMinusOperator()
{
Assert.AreEqual(new vector(-1, -1, -1), - (new vector(1, 1, 1)));
Assert.AreEqual(new vector(0, 0, 0), - (new vector(0, 0, 0)));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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
{
/// <summary>
/// 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.
/// </summary>
[TestFixture]
public class CompilerTest
{
private string m_testDir;
private CSharpCodeProvider m_CSCodeProvider;
private CompilerParameters m_compilerParameters;
private CompilerResults m_compilerResults;
/// <summary>
/// Creates a temporary directory where build artifacts are stored.
/// </summary>
[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;
}
/// <summary>
/// Removes the temporary build directory and any build artifacts
/// inside it.
/// </summary>
[TestFixtureTearDown]
public void CleanUp()
{
if (Directory.Exists(m_testDir))
{
// Blow away the temporary directory with artifacts.
Directory.Delete(m_testDir, true);
}
}
/// <summary>
/// Test the C# compiler error message can be mapped to the correct
/// line/column in the LSL source when an undeclared variable is used.
/// </summary>
//[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<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
Assert.AreEqual(new KeyValuePair<int, int>(5, 21),
positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
}
/// <summary>
/// Test that a string can be cast to string and another string
/// concatenated.
/// </summary>
//[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);
}
}
}

View File

@@ -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<int, double> m_intDoubleSet;
private Dictionary<double, double> m_doubleDoubleSet;
private Dictionary<double, int> m_doubleIntSet;
private Dictionary<double, int> m_doubleUintSet;
private Dictionary<string, double> m_stringDoubleSet;
private Dictionary<double, string> m_doubleStringSet;
private List<int> m_intList;
private List<double> m_doubleList;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_intDoubleSet = new Dictionary<int, double>();
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<double, double>();
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<double, int>();
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<double, int>();
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<string, double>();
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<double, string>();
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<double>();
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<int>();
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);
}
/// <summary>
/// Tests constructing a LSLFloat from an integer.
/// </summary>
[Test]
public void TestConstructFromInt()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<int, double> number in m_intDoubleSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests constructing a LSLFloat from a double.
/// </summary>
[Test]
public void TestConstructFromDouble()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to integer.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToInt()
{
int testNumber;
foreach (KeyValuePair<double, int> 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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to unsigned integer.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToUint()
{
uint testNumber;
foreach (KeyValuePair<double, int> 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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero.
/// </summary>
[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);
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to Boolean if zero.
/// </summary>
[Test]
public void TestImplicitCastLSLFloatToBooleanFalse()
{
LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0);
bool testBool = testFloat;
Assert.IsFalse(testBool);
}
/// <summary>
/// Tests integer is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestImplicitCastIntToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (int number in m_intList)
{
testFloat = number;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLInteger is correctly cast implicitly to LSLFloat.
/// </summary>
[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));
}
}
/// <summary>
/// Tests LSLInteger is correctly cast explicitly to LSLFloat.
/// </summary>
[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));
}
}
/// <summary>
/// Tests string is correctly cast explicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastStringToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
{
testFloat = (LSL_Types.LSLFloat) number.Key;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLString is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLStringToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
{
testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests double is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestImplicitCastDoubleToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (double number in m_doubleList)
{
testFloat = number;
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLFloat is correctly cast implicitly to double.
/// </summary>
[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));
}
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to float
/// </summary>
[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));
}
}
/// <summary>
/// Tests the equality (==) operator.
/// </summary>
[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);
}
}
/// <summary>
/// Tests the inequality (!=) operator.
/// </summary>
[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);
}
}
/// <summary>
/// Tests the increment operator.
/// </summary>
[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));
}
}
/// <summary>
/// Tests the decrement operator.
/// </summary>
[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));
}
}
/// <summary>
/// Tests LSLFloat.ToString().
/// </summary>
[Test]
public void TestToString()
{
LSL_Types.LSLFloat testFloat;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testFloat = new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(number.Value, testFloat.ToString());
}
}
/// <summary>
/// Tests addition of two LSLFloats.
/// </summary>
[Test]
public void TestAddTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests subtraction of two LSLFloats.
/// </summary>
[Test]
public void TestSubtractTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests multiplication of two LSLFloats.
/// </summary>
[Test]
public void TestMultiplyTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
/// <summary>
/// Tests division of two LSLFloats.
/// </summary>
[Test]
public void TestDivideTwoLSLFloats()
{
LSL_Types.LSLFloat testResult;
foreach (KeyValuePair<double, double> 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));
}
}
}
/// <summary>
/// Tests boolean correctly cast implicitly to LSLFloat.
/// </summary>
[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));
}
}
}

View File

@@ -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<double, int> m_doubleIntSet;
private Dictionary<string, int> m_stringIntSet;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_doubleIntSet = new Dictionary<double, int>();
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<string, int>();
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);
}
/// <summary>
/// Tests LSLFloat is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<double, int> number in m_doubleIntSet)
{
testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests string is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastStringToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<string, int> number in m_stringIntSet)
{
testInteger = (LSL_Types.LSLInteger) number.Key;
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests LSLString is correctly cast explicitly to LSLInteger.
/// </summary>
[Test]
public void TestExplicitCastLSLStringToLSLInteger()
{
LSL_Types.LSLInteger testInteger;
foreach (KeyValuePair<string, int> number in m_stringIntSet)
{
testInteger = (LSL_Types.LSLInteger) new LSL_Types.LSLString(number.Key);
Assert.AreEqual(testInteger.value, number.Value);
}
}
/// <summary>
/// Tests boolean correctly cast implicitly to LSLInteger.
/// </summary>
[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);
}
}
}

View File

@@ -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<double, string> m_doubleStringSet;
/// <summary>
/// Sets up dictionaries and arrays used in the tests.
/// </summary>
[TestFixtureSetUp]
public void SetUpDataSets()
{
m_doubleStringSet = new Dictionary<double, string>();
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");
}
/// <summary>
/// Tests constructing a LSLString from an LSLFloat.
/// </summary>
[Test]
public void TestConstructFromLSLFloat()
{
LSL_Types.LSLString testString;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
Assert.AreEqual(number.Value, testString.m_string);
}
}
/// <summary>
/// Tests constructing a LSLString from an LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLFloatToLSLString()
{
LSL_Types.LSLString testString;
foreach (KeyValuePair<double, string> number in m_doubleStringSet)
{
testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
Assert.AreEqual(number.Value, testString.m_string);
}
}
/// <summary>
/// Test constructing a Quaternion from a string.
/// </summary>
[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);
}
/// <summary>
/// Tests boolean correctly cast explicitly to LSLString.
/// </summary>
[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);
}
}
}

View File

@@ -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
{
/// <summary>
/// Tests the LSL_Types.list class.
/// </summary>
[TestFixture]
public class LSL_TypesTestList
{
/// <summary>
/// Tests concatenating a string to a list.
/// </summary>
[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());
}
/// <summary>
/// Tests concatenating an integer to a list.
/// </summary>
[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());
}
/// <summary>
/// Tests concatenating a float to a list.
/// </summary>
[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());
}
/// <summary>
/// Tests casting LSLInteger item to LSLInteger.
/// </summary>
[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]);
}
/// <summary>
/// Tests casting LSLFloat item to LSLFloat.
/// </summary>
[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]);
}
/// <summary>
/// Tests casting LSLString item to LSLString.
/// </summary>
[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]);
}
/// <summary>
/// Tests casting Vector3 item to Vector3.
/// </summary>
[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]);
}
/// <summary>
/// Tests casting Quaternion item to Quaternion.
/// </summary>
[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]);
}
//====================================================================================
/// <summary>
/// Tests GetLSLIntegerItem for LSLInteger item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetLSLFloatItem for LSLFloat item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetLSLFloatItem for LSLInteger item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetLSLStringItem for LSLString item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetLSLStringItem for key item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetVector3Item for Vector3 item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetQuaternionItem for Quaternion item.
/// </summary>
[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));
}
/// <summary>
/// Tests GetKeyItem for key item.
/// </summary>
[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));
}
}
}

View File

@@ -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
{
/// <summary>
/// Tests for Vector3
/// </summary>
[Test]
public void TestDotProduct()
{
// The numbers we test for.
Dictionary<string, double> expectsSet = new Dictionary<string, double>();
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<string, double> 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);
}
}
}
}