diff options
Diffstat (limited to 'indra/llmath/tests')
-rw-r--r-- | indra/llmath/tests/llbbox_test.cpp | 4 | ||||
-rw-r--r-- | indra/llmath/tests/llbboxlocal_test.cpp | 5 | ||||
-rw-r--r-- | indra/llmath/tests/llmodularmath_test.cpp | 82 | ||||
-rw-r--r-- | indra/llmath/tests/llquaternion_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/llrect_test.cpp | 4 | ||||
-rw-r--r-- | indra/llmath/tests/m3math_test.cpp | 327 | ||||
-rw-r--r-- | indra/llmath/tests/v2math_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v3color_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v3dmath_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v3math_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v4color_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v4coloru_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/v4math_test.cpp | 2 | ||||
-rw-r--r-- | indra/llmath/tests/xform_test.cpp | 2 |
14 files changed, 425 insertions, 15 deletions
diff --git a/indra/llmath/tests/llbbox_test.cpp b/indra/llmath/tests/llbbox_test.cpp index 2cfdd8b36d..3031310a5d 100644 --- a/indra/llmath/tests/llbbox_test.cpp +++ b/indra/llmath/tests/llbbox_test.cpp @@ -1,5 +1,5 @@ /** - * @file llbbox_tut.cpp + * @file llbbox_test.cpp * @author Martin Reddy * @date 2009-06-25 * @brief Test for llbbox.cpp. @@ -32,6 +32,8 @@ * $/LicenseInfo$ */ +#include "linden_common.h" + #include "../test/lltut.h" #include "../llbbox.h" diff --git a/indra/llmath/tests/llbboxlocal_test.cpp b/indra/llmath/tests/llbboxlocal_test.cpp index 92cdf1c8a2..fb51deab4a 100644 --- a/indra/llmath/tests/llbboxlocal_test.cpp +++ b/indra/llmath/tests/llbboxlocal_test.cpp @@ -1,5 +1,5 @@ /** - * @file llbboxlocal_tut.cpp + * @file llbboxlocal_test.cpp * @author Martin Reddy * @date 2009-06-25 * @brief Test for llbboxlocal.cpp. @@ -32,11 +32,10 @@ * $/LicenseInfo$ */ +#include "linden_common.h" #include "../test/lltut.h" - #include "../llbboxlocal.h" - namespace tut { struct LLBBoxLocalData diff --git a/indra/llmath/tests/llmodularmath_test.cpp b/indra/llmath/tests/llmodularmath_test.cpp new file mode 100644 index 0000000000..dc61c85859 --- /dev/null +++ b/indra/llmath/tests/llmodularmath_test.cpp @@ -0,0 +1,82 @@ +/** + * @file modularmath_test.cpp + * @author babbage + * @date 2008-09 + * @brief llmodularmath tests + * + * $LicenseInfo:firstyear=2007&license=viewergpl$ + * + * Copyright (c) 2007-2009, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "../llmodularmath.h" + +#include "../test/lltut.h" + +namespace tut +{ + struct modularmath_data + { + }; + typedef test_group<modularmath_data> modularmath_test; + typedef modularmath_test::object modularmath_object; + tut::modularmath_test modularmath_testcase("modularmath"); + + template<> template<> + void modularmath_object::test<1>() + { + // lhs < rhs + const U32 lhs = 0x000001; + const U32 rhs = 0xFFFFFF; + const U32 width = 24; + U32 result = LLModularMath::subtract<width>(lhs, rhs); + ensure_equals("diff(0x000001, 0xFFFFFF, 24)", result, 2); + } + + template<> template<> + void modularmath_object::test<2>() + { + // lhs > rhs + const U32 lhs = 0x000002; + const U32 rhs = 0x000001; + const U32 width = 24; + U32 result = LLModularMath::subtract<width>(lhs, rhs); + ensure_equals("diff(0x000002, 0x000001, 24)", result, 1); + } + + template<> template<> + void modularmath_object::test<3>() + { + // lhs == rhs + const U32 lhs = 0xABCDEF; + const U32 rhs = 0xABCDEF; + const U32 width = 24; + U32 result = LLModularMath::subtract<width>(lhs, rhs); + ensure_equals("diff(0xABCDEF, 0xABCDEF, 24)", result, 0); + } +} diff --git a/indra/llmath/tests/llquaternion_test.cpp b/indra/llmath/tests/llquaternion_test.cpp index bfa475d91b..2d27d1eb32 100644 --- a/indra/llmath/tests/llquaternion_test.cpp +++ b/indra/llmath/tests/llquaternion_test.cpp @@ -1,5 +1,5 @@ /** - * @file llquaternion_tut.cpp + * @file llquaternion_test.cpp * @author Adroit * @date 2007-03 * @brief Test cases of llquaternion.h diff --git a/indra/llmath/tests/llrect_test.cpp b/indra/llmath/tests/llrect_test.cpp index b16716a72c..c5e9e425bb 100644 --- a/indra/llmath/tests/llrect_test.cpp +++ b/indra/llmath/tests/llrect_test.cpp @@ -1,5 +1,5 @@ /** - * @file llrect_tut.cpp + * @file llrect_test.cpp * @author Martin Reddy * @date 2009-06-25 * @brief Test for llrect.cpp. @@ -32,8 +32,8 @@ * $/LicenseInfo$ */ +#include "linden_common.h" #include "../test/lltut.h" - #include "../llrect.h" namespace tut diff --git a/indra/llmath/tests/m3math_test.cpp b/indra/llmath/tests/m3math_test.cpp new file mode 100644 index 0000000000..83ca5768df --- /dev/null +++ b/indra/llmath/tests/m3math_test.cpp @@ -0,0 +1,327 @@ +/** + * @file m3math_test.cpp + * @author Adroit + * @date 2007-03 + * @brief Test cases of m3math.h + * + * $LicenseInfo:firstyear=2007&license=viewergpl$ + * + * Copyright (c) 2007-2009, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "../m3math.h" +#include "../v3math.h" +#include "../v4math.h" +#include "../m4math.h" +#include "../llquaternion.h" +#include "../v3dmath.h" + +#include "../test/lltut.h" + +namespace tut +{ + struct m3math_test + { + }; + typedef test_group<m3math_test> m3math_test_t; + typedef m3math_test_t::object m3math_test_object_t; + tut::m3math_test_t tut_m3math_test("m3math_test"); + + //test case for setIdentity() fn. + template<> template<> + void m3math_test_object_t::test<1>() + { + LLMatrix3 llmat3_obj; + llmat3_obj.setIdentity(); + ensure("LLMatrix3::setIdentity failed", 1.f == llmat3_obj.mMatrix[0][0] && + 0.f == llmat3_obj.mMatrix[0][1] && + 0.f == llmat3_obj.mMatrix[0][2] && + 0.f == llmat3_obj.mMatrix[1][0] && + 1.f == llmat3_obj.mMatrix[1][1] && + 0.f == llmat3_obj.mMatrix[1][2] && + 0.f == llmat3_obj.mMatrix[2][0] && + 0.f == llmat3_obj.mMatrix[2][1] && + 1.f == llmat3_obj.mMatrix[2][2]); + } + + //test case for LLMatrix3& setZero() fn. + template<> template<> + void m3math_test_object_t::test<2>() + { + LLMatrix3 llmat3_obj(30, 1, 2, 3); + llmat3_obj.setZero(); + + ensure("LLMatrix3::setZero failed", 0.f == llmat3_obj.setZero().mMatrix[0][0] && + 0.f == llmat3_obj.setZero().mMatrix[0][1] && + 0.f == llmat3_obj.setZero().mMatrix[0][2] && + 0.f == llmat3_obj.setZero().mMatrix[1][0] && + 0.f == llmat3_obj.setZero().mMatrix[1][1] && + 0.f == llmat3_obj.setZero().mMatrix[1][2] && + 0.f == llmat3_obj.setZero().mMatrix[2][0] && + 0.f == llmat3_obj.setZero().mMatrix[2][1] && + 0.f == llmat3_obj.setZero().mMatrix[2][2]); + } + + //test case for setRows(const LLVector3 &x_axis, const LLVector3 &y_axis, const LLVector3 &z_axis) fns. + template<> template<> + void m3math_test_object_t::test<3>() + { + LLMatrix3 llmat3_obj; + LLVector3 vect1(2, 1, 4); + LLVector3 vect2(3, 5, 7); + LLVector3 vect3(6, 9, 7); + llmat3_obj.setRows(vect1, vect2, vect3); + ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] && + 1 == llmat3_obj.mMatrix[0][1] && + 4 == llmat3_obj.mMatrix[0][2] && + 3 == llmat3_obj.mMatrix[1][0] && + 5 == llmat3_obj.mMatrix[1][1] && + 7 == llmat3_obj.mMatrix[1][2] && + 6 == llmat3_obj.mMatrix[2][0] && + 9 == llmat3_obj.mMatrix[2][1] && + 7 == llmat3_obj.mMatrix[2][2]); + } + + //test case for getFwdRow(), getLeftRow(), getUpRow() fns. + template<> template<> + void m3math_test_object_t::test<4>() + { + LLMatrix3 llmat3_obj; + LLVector3 vect1(2, 1, 4); + LLVector3 vect2(3, 5, 7); + LLVector3 vect3(6, 9, 7); + llmat3_obj.setRows(vect1, vect2, vect3); + + ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow()); + ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow()); + ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow()); + } + + //test case for operator*(const LLMatrix3 &a, const LLMatrix3 &b) + template<> template<> + void m3math_test_object_t::test<5>() + { + LLMatrix3 llmat_obj1; + LLMatrix3 llmat_obj2; + LLMatrix3 llmat_obj3; + + LLVector3 llvec1(1, 3, 5); + LLVector3 llvec2(3, 6, 1); + LLVector3 llvec3(4, 6, 9); + + LLVector3 llvec4(1, 1, 5); + LLVector3 llvec5(3, 6, 8); + LLVector3 llvec6(8, 6, 2); + + LLVector3 llvec7(0, 0, 0); + LLVector3 llvec8(0, 0, 0); + LLVector3 llvec9(0, 0, 0); + + llmat_obj1.setRows(llvec1, llvec2, llvec3); + llmat_obj2.setRows(llvec4, llvec5, llvec6); + llmat_obj3.setRows(llvec7, llvec8, llvec9); + llmat_obj3 = llmat_obj1 * llmat_obj2; + ensure("LLMatrix3::operator*(const LLMatrix3 &a, const LLMatrix3 &b) failed", + 50 == llmat_obj3.mMatrix[0][0] && + 49 == llmat_obj3.mMatrix[0][1] && + 39 == llmat_obj3.mMatrix[0][2] && + 29 == llmat_obj3.mMatrix[1][0] && + 45 == llmat_obj3.mMatrix[1][1] && + 65 == llmat_obj3.mMatrix[1][2] && + 94 == llmat_obj3.mMatrix[2][0] && + 94 == llmat_obj3.mMatrix[2][1] && + 86 == llmat_obj3.mMatrix[2][2]); + } + + + //test case for operator*(const LLVector3 &a, const LLMatrix3 &b) + template<> template<> + void m3math_test_object_t::test<6>() + { + + LLMatrix3 llmat_obj1; + + LLVector3 llvec(1, 3, 5); + LLVector3 res_vec(0, 0, 0); + LLVector3 llvec1(1, 3, 5); + LLVector3 llvec2(3, 6, 1); + LLVector3 llvec3(4, 6, 9); + + llmat_obj1.setRows(llvec1, llvec2, llvec3); + res_vec = llvec * llmat_obj1; + + LLVector3 expected_result(30, 51, 53); + + ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", res_vec == expected_result); + } + + //test case for operator*(const LLVector3d &a, const LLMatrix3 &b) + template<> template<> + void m3math_test_object_t::test<7>() + { + LLMatrix3 llmat_obj1; + LLVector3d llvec3d1; + LLVector3d llvec3d2(0, 3, 4); + + LLVector3 llvec1(1, 3, 5); + LLVector3 llvec2(3, 2, 1); + LLVector3 llvec3(4, 6, 0); + + llmat_obj1.setRows(llvec1, llvec2, llvec3); + llvec3d1 = llvec3d2 * llmat_obj1; + + LLVector3d expected_result(25, 30, 3); + + ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", llvec3d1 == expected_result); + } + + // test case for operator==(const LLMatrix3 &a, const LLMatrix3 &b) + template<> template<> + void m3math_test_object_t::test<8>() + { + LLMatrix3 llmat_obj1; + LLMatrix3 llmat_obj2; + + LLVector3 llvec1(1, 3, 5); + LLVector3 llvec2(3, 6, 1); + LLVector3 llvec3(4, 6, 9); + + llmat_obj1.setRows(llvec1, llvec2, llvec3); + llmat_obj2.setRows(llvec1, llvec2, llvec3); + ensure("LLMatrix3::operator==(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 == llmat_obj2); + + llmat_obj2.setRows(llvec2, llvec2, llvec3); + ensure("LLMatrix3::operator!=(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 != llmat_obj2); + } + + //test case for quaternion() fn. + template<> template<> + void m3math_test_object_t::test<9>() + { + LLMatrix3 llmat_obj1; + LLQuaternion llmat_quat; + + LLVector3 llmat1(2.0f, 1.0f, 6.0f); + LLVector3 llmat2(1.0f, 1.0f, 3.0f); + LLVector3 llmat3(1.0f, 7.0f, 5.0f); + + llmat_obj1.setRows(llmat1, llmat2, llmat3); + llmat_quat = llmat_obj1.quaternion(); + ensure("LLMatrix3::quaternion failed ", is_approx_equal(-0.66666669f, llmat_quat.mQ[0]) && + is_approx_equal(-0.83333337f, llmat_quat.mQ[1]) && + is_approx_equal(0.0f, llmat_quat.mQ[2]) && + is_approx_equal(1.5f, llmat_quat.mQ[3])); + } + + //test case for transpose() fn. + template<> template<> + void m3math_test_object_t::test<10>() + { + LLMatrix3 llmat_obj; + + LLVector3 llvec1(1, 2, 3); + LLVector3 llvec2(3, 2, 1); + LLVector3 llvec3(2, 2, 2); + + llmat_obj.setRows(llvec1, llvec2, llvec3); + llmat_obj.transpose(); + + LLVector3 resllvec1(1, 3, 2); + LLVector3 resllvec2(2, 2, 2); + LLVector3 resllvec3(3, 1, 2); + LLMatrix3 expectedllmat_obj; + expectedllmat_obj.setRows(resllvec1, resllvec2, resllvec3); + + ensure("LLMatrix3::transpose failed ", llmat_obj == expectedllmat_obj); + } + + //test case for determinant() fn. + template<> template<> + void m3math_test_object_t::test<11>() + { + LLMatrix3 llmat_obj1; + + LLVector3 llvec1(1, 2, 3); + LLVector3 llvec2(3, 2, 1); + LLVector3 llvec3(2, 2, 2); + llmat_obj1.setRows(llvec1, llvec2, llvec3); + ensure("LLMatrix3::determinant failed ", 0.0f == llmat_obj1.determinant()); + } + + //test case for orthogonalize() fn. + template<> template<> + void m3math_test_object_t::test<12>() + { + LLMatrix3 llmat_obj; + + LLVector3 llvec1(1, 4, 3); + LLVector3 llvec2(1, 2, 0); + LLVector3 llvec3(2, 4, 2); + + llmat_obj.setRows(llvec1, llvec2, llvec3); + llmat_obj.orthogonalize(); + + skip("Grr, LLMatrix3::orthogonalize test is failing. Has it ever worked?"); + ensure("LLMatrix3::orthogonalize failed ", + is_approx_equal(0.19611613f, llmat_obj.mMatrix[0][0]) && + is_approx_equal(0.78446454f, llmat_obj.mMatrix[0][1]) && + is_approx_equal(0.58834839f, llmat_obj.mMatrix[0][2]) && + is_approx_equal(0.47628206f, llmat_obj.mMatrix[1][0]) && + is_approx_equal(0.44826555f, llmat_obj.mMatrix[1][1]) && + is_approx_equal(-0.75644791f, llmat_obj.mMatrix[1][2]) && + is_approx_equal(-0.85714287f, llmat_obj.mMatrix[2][0]) && + is_approx_equal(0.42857143f, llmat_obj.mMatrix[2][1]) && + is_approx_equal(-0.28571427f, llmat_obj.mMatrix[2][2])); + } + + //test case for adjointTranspose() fn. + template<> template<> + void m3math_test_object_t::test<13>() + { + LLMatrix3 llmat_obj; + + LLVector3 llvec1(3, 2, 1); + LLVector3 llvec2(6, 2, 1); + LLVector3 llvec3(3, 6, 8); + + llmat_obj.setRows(llvec1, llvec2, llvec3); + llmat_obj.adjointTranspose(); + + ensure("LLMatrix3::adjointTranspose failed ", 10 == llmat_obj.mMatrix[0][0] && + -45 == llmat_obj.mMatrix[1][0] && + 30 == llmat_obj.mMatrix[2][0] && + -10 == llmat_obj.mMatrix[0][1] && + 21 == llmat_obj.mMatrix[1][1] && + -12 == llmat_obj.mMatrix[2][1] && + 0 == llmat_obj.mMatrix[0][2] && + 3 == llmat_obj.mMatrix[1][2] && + -6 == llmat_obj.mMatrix[2][2]); + } + + /* TBD: Need to add test cases for getEulerAngles() and setRot() functions */ +} diff --git a/indra/llmath/tests/v2math_test.cpp b/indra/llmath/tests/v2math_test.cpp index 456faf7c0c..4660fcb955 100644 --- a/indra/llmath/tests/v2math_test.cpp +++ b/indra/llmath/tests/v2math_test.cpp @@ -1,5 +1,5 @@ /** - * @file v2math_tut.cpp + * @file v2math_test.cpp * @author Adroit * @date 2007-02 * @brief v2math test cases. diff --git a/indra/llmath/tests/v3color_test.cpp b/indra/llmath/tests/v3color_test.cpp index bb6e234fd6..316b6e392f 100644 --- a/indra/llmath/tests/v3color_test.cpp +++ b/indra/llmath/tests/v3color_test.cpp @@ -1,5 +1,5 @@ /** - * @file v3color_tut.cpp + * @file v3color_test.cpp * @author Adroit * @date 2007-03 * @brief v3color test cases. diff --git a/indra/llmath/tests/v3dmath_test.cpp b/indra/llmath/tests/v3dmath_test.cpp index 780495e53d..e7c949186c 100644 --- a/indra/llmath/tests/v3dmath_test.cpp +++ b/indra/llmath/tests/v3dmath_test.cpp @@ -1,5 +1,5 @@ /** - * @file v3dmath_tut.cpp + * @file v3dmath_test.cpp * @author Adroit * @date 2007-03 * @brief v3dmath test cases. diff --git a/indra/llmath/tests/v3math_test.cpp b/indra/llmath/tests/v3math_test.cpp index 14159974a3..7faf076243 100644 --- a/indra/llmath/tests/v3math_test.cpp +++ b/indra/llmath/tests/v3math_test.cpp @@ -1,5 +1,5 @@ /** - * @file v3math_tut.cpp + * @file v3math_test.cpp * @author Adroit * @date 2007-02 * @brief v3math test cases. diff --git a/indra/llmath/tests/v4color_test.cpp b/indra/llmath/tests/v4color_test.cpp index cebb026ce6..33921e0f0f 100644 --- a/indra/llmath/tests/v4color_test.cpp +++ b/indra/llmath/tests/v4color_test.cpp @@ -1,5 +1,5 @@ /** - * @file v4color_tut.cpp + * @file v4color_test.cpp * @author Adroit * @date 2007-03 * @brief v4color test cases. diff --git a/indra/llmath/tests/v4coloru_test.cpp b/indra/llmath/tests/v4coloru_test.cpp index 00515893da..9f71cfc8cc 100644 --- a/indra/llmath/tests/v4coloru_test.cpp +++ b/indra/llmath/tests/v4coloru_test.cpp @@ -1,5 +1,5 @@ /** - * @file v4coloru_tut.cpp + * @file v4coloru_test.cpp * @author Adroit * @date 2007-03 * @brief v4coloru test cases. diff --git a/indra/llmath/tests/v4math_test.cpp b/indra/llmath/tests/v4math_test.cpp index e020038ae5..fe051c27e9 100644 --- a/indra/llmath/tests/v4math_test.cpp +++ b/indra/llmath/tests/v4math_test.cpp @@ -1,5 +1,5 @@ /** - * @file v4math_tut.cpp + * @file v4math_test.cpp * @author Adroit * @date 2007-03 * @brief v4math test cases. diff --git a/indra/llmath/tests/xform_test.cpp b/indra/llmath/tests/xform_test.cpp index 81116a58f0..e697a0b7a1 100644 --- a/indra/llmath/tests/xform_test.cpp +++ b/indra/llmath/tests/xform_test.cpp @@ -1,5 +1,5 @@ /** - * @file xform_tut.cpp + * @file xform_test.cpp * @author Adroit * @date March 2007 * @brief Test cases for LLXform |