CppUnit is really too large for our needs, would require to be precompiled for many platforms, in all combinations of debug and release modes, with additional variants for libstdc++ versions. We replace it with our own lightweight implementation, LolUnit. Good riddance.legacy
| @@ -10,11 +10,9 @@ set -e | |||
| PATH="$PATH:./contrib/gtk-2.22.1/bin" | |||
| M4PATH="$M4PATH:./contrib/gtk-2.22.1/share/aclocal" | |||
| M4PATH="$M4PATH:./contrib/cppunit-1.12.2/share/aclocal" | |||
| export M4PATH # This looks necessary | |||
| PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`pwd`/contrib/gtkglarea-2.0.1/lib/pkgconfig" | |||
| PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`pwd`/contrib/cppunit-1.12.2/lib/pkgconfig" | |||
| export PKG_CONFIG_PATH # This looks necessary, too | |||
| # SDL include path | |||
| @@ -36,9 +34,6 @@ CPPFLAGS="$CPPFLAGS -I`pwd`/contrib/gtk-2.22.1/include/gdk-pixbuf-2.0" | |||
| CPPFLAGS="$CPPFLAGS -I`pwd`/contrib/gtk-2.22.1/include/atk-1.0" | |||
| CPPFLAGS="$CPPFLAGS -I`pwd`/contrib/gtkglarea-2.0.1/include" | |||
| # CppUnit include path | |||
| CPPFLAGS="$CPPFLAGS -I`pwd`/contrib/cppunit-1.12.2/include" | |||
| # SDL library path | |||
| LDFLAGS="$LDFLAGS -L`pwd`/contrib/sdl-1.2.14/lib" | |||
| LDFLAGS="$LDFLAGS -L`pwd`/contrib/sdl-image-1.2.10/lib" | |||
| @@ -52,9 +47,6 @@ LDFLAGS="$LDFLAGS -L`pwd`/contrib/gtk-2.22.1/lib" | |||
| LDFLAGS="$LDFLAGS -L`pwd`/contrib/gtk-2.22.1/bin" | |||
| LDFLAGS="$LDFLAGS -L`pwd`/contrib/gtkglarea-2.0.1/lib" | |||
| # CppUnit library path | |||
| LDFLAGS="$LDFLAGS -L`pwd`/contrib/cppunit-1.12.2/lib" | |||
| # Prevent issues with GTK+ internals | |||
| CPPFLAGS="$CPPFLAGS -mms-bitfields" | |||
| @@ -14,7 +14,6 @@ | |||
| windows-i386) | |||
| PATH="$''PATH:./contrib/gtk-2.22.1/bin"; | |||
| M4PATH="$''M4PATH:./contrib/gtk-2.22.1/share/aclocal"; | |||
| M4PATH="$''M4PATH:./contrib/cppunit-1.12.2/share/aclocal"; | |||
| PATH="$''PATH" M4PATH="$''M4PATH" ./bootstrap; | |||
| ;; | |||
| *) | |||
| @@ -34,7 +33,6 @@ | |||
| ;; | |||
| windows-i386) | |||
| PKG_CONFIG_PATH="$''PKG_CONFIG_PATH:$''PWD/contrib/gtkglarea-2.0.1/lib/pkgconfig"; | |||
| PKG_CONFIG_PATH="$''PKG_CONFIG_PATH:$''PWD/contrib/cppunit-1.12.2/lib/pkgconfig"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/sdl-1.2.14/include"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/sdl-image-1.2.10/include"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/sdl-mixer-1.2.11/include"; | |||
| @@ -48,7 +46,6 @@ | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/gtk-2.22.1/include/gdk-pixbuf-2.0"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/gtk-2.22.1/include/atk-1.0"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/gtkglarea-2.0.1/include"; | |||
| CPPFLAGS="$''CPPFLAGS -I$''PWD/contrib/cppunit-1.12.2/include"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/sdl-1.2.14/lib"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/sdl-image-1.2.10/lib"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/sdl-mixer-1.2.11/lib"; | |||
| @@ -56,7 +53,6 @@ | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/gtk-2.22.1/lib"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/gtk-2.22.1/bin"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/gtkglarea-2.0.1/lib"; | |||
| LDFLAGS="$''LDFLAGS -L$''PWD/contrib/cppunit-1.12.2/lib"; | |||
| CPPFLAGS="$''CPPFLAGS -mms-bitfields"; | |||
| LDFLAGS="$''LDFLAGS -static-libgcc -static-libstdc++"; | |||
| GTK_LIBS="$''GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"; | |||
| @@ -46,9 +46,6 @@ AC_ARG_ENABLE(release, | |||
| AC_ARG_ENABLE(experimental, | |||
| [ --enable-experimental experimental build (default no)]) | |||
| AC_ARG_ENABLE(cppunit, | |||
| [ --enable-cppunit use cppunit for unit tests (autodetected)]) | |||
| AC_CHECK_HEADERS(stdio.h stdarg.h inttypes.h endian.h stdint.h getopt.h fastmath.h) | |||
| if test "${enable_debug}" = "yes"; then | |||
| @@ -242,11 +239,6 @@ fi | |||
| AM_CONDITIONAL(USE_GTKGL, test "${ac_cv_my_have_gtkgl}" != "no") | |||
| dnl Use cppunit for unit tests? | |||
| PKG_CHECK_MODULES(CPPUNIT, cppunit, [CPPUNIT="yes"], [CPPUNIT="no"]) | |||
| AM_CONDITIONAL(USE_CPPUNIT, test "$CPPUNIT" = "yes") | |||
| dnl How to use the Lol Engine inside this tree | |||
| LOL_CFLAGS="$LOL_CFLAGS -I \$(top_srcdir)/src" | |||
| LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $GL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS" | |||
| @@ -12,6 +12,8 @@ liblol_a_SOURCES = \ | |||
| worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \ | |||
| platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \ | |||
| \ | |||
| lol/unit.h \ | |||
| \ | |||
| eglapp.cpp eglapp.h \ | |||
| \ | |||
| platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ | |||
| @@ -0,0 +1,182 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| // | |||
| // The Unit test framework | |||
| // ----------------------- | |||
| // | |||
| #if !defined __LOL_UNIT_H__ | |||
| #define __LOL_UNIT_H__ | |||
| #include <iostream> | |||
| #include <cstdio> | |||
| #include <cmath> | |||
| namespace lol | |||
| { | |||
| using namespace std; | |||
| class FixtureBase | |||
| { | |||
| friend class TestRunner; | |||
| public: | |||
| virtual void setUp(void) {}; | |||
| virtual void tearDown(void) {}; | |||
| protected: | |||
| FixtureBase() : m_next(NULL), m_tests(0), m_fails(0) {} | |||
| virtual ~FixtureBase() {} | |||
| /* The FixtureBase class keeps track of all instanciated children | |||
| * fixtures through this method. */ | |||
| static FixtureBase *GetOrSetTest(FixtureBase *set = NULL) | |||
| { | |||
| static FixtureBase *head = NULL, *tail = NULL; | |||
| if (set) | |||
| { | |||
| if (!head) | |||
| head = set; | |||
| if (tail) | |||
| tail->m_next = set; | |||
| tail = set; | |||
| } | |||
| return head; | |||
| } | |||
| virtual int RunFixture() = 0; | |||
| /* Prevent compiler complaints about unreachable code */ | |||
| static inline bool True() { return true; } | |||
| FixtureBase *m_next; | |||
| int m_tests, m_fails; | |||
| }; | |||
| template<class T> class Fixture : protected FixtureBase | |||
| { | |||
| public: | |||
| typedef T FixtureClass; | |||
| class TestCase | |||
| { | |||
| public: | |||
| void (FixtureClass::* m_fun)(); | |||
| char const *m_name; | |||
| TestCase *m_next; | |||
| static void AddTestCase(TestCase *that, char const *name, | |||
| void (FixtureClass::*fun)()) | |||
| { | |||
| that->m_name = name; | |||
| that->m_fun = fun; | |||
| GetOrSetTestCase(that); | |||
| } | |||
| }; | |||
| Fixture<T>() | |||
| { | |||
| GetOrSetTest(this); | |||
| } | |||
| /* Run all test cases in this fixture. */ | |||
| virtual int RunFixture() | |||
| { | |||
| for (TestCase *head = GetOrSetTestCase(); head; head = head->m_next) | |||
| { | |||
| (static_cast<FixtureClass *>(this)->*head->m_fun)(); | |||
| std::cout << "."; | |||
| } | |||
| return 0; | |||
| } | |||
| /* Each Fixture class specialisation keeps track of its instanciated | |||
| * test cases through this method. */ | |||
| static TestCase *GetOrSetTestCase(TestCase *set = NULL) | |||
| { | |||
| static TestCase *head = NULL, *tail = NULL; | |||
| if (set) | |||
| { | |||
| if (!head) head = set; | |||
| if (tail) tail->m_next = set; | |||
| tail = set; | |||
| } | |||
| return head; | |||
| } | |||
| }; | |||
| class TestRunner | |||
| { | |||
| public: | |||
| int Run() | |||
| { | |||
| int ret = 0; | |||
| for (FixtureBase *head = FixtureBase::GetOrSetTest(); head; head = head->m_next) | |||
| { | |||
| head->setUp(); | |||
| if (head->RunFixture()) | |||
| ret = 1; | |||
| head->tearDown(); | |||
| } | |||
| std::cout << std::endl; | |||
| return ret; | |||
| } | |||
| }; | |||
| #define LOLUNIT_FIXTURE(FixtureName) \ | |||
| class FixtureName : public lol::Fixture<FixtureName> | |||
| #define LOLUNIT_TEST(TestCaseName) \ | |||
| class TestCase##TestCaseName : public TestCase \ | |||
| { \ | |||
| public: \ | |||
| TestCase##TestCaseName() \ | |||
| { \ | |||
| AddTestCase(this, #TestCaseName, \ | |||
| (void (FixtureClass::*)()) &FixtureClass::TestCaseName); \ | |||
| } \ | |||
| }; \ | |||
| TestCase##TestCaseName test_case_##TestCaseName; \ | |||
| void TestCaseName() | |||
| #define LOLUNIT_SETUP_FIXTURE(ClassName) \ | |||
| ClassName ClassName##Test_Instance; | |||
| #define LOLUNIT_ASSERT(cond) \ | |||
| do { if (True() && !(cond)) \ | |||
| { \ | |||
| std::cout << "FAIL! " #cond << std::endl; \ | |||
| return; \ | |||
| } } while(!True()) | |||
| #define LOLUNIT_ASSERT_EQUAL(a, b) \ | |||
| do { if (True() && (a) != (b)) \ | |||
| { \ | |||
| std::cout << "FAIL! " #a " != " #b << std::endl; \ | |||
| std::cout << "expected: " << (a) << std::endl; \ | |||
| std::cout << "returned: " << (b) << std::endl; \ | |||
| return; \ | |||
| } } while(!True()) | |||
| #define LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, t) \ | |||
| do { if (True() && fabs((a) - (b)) > fabs((t))) \ | |||
| { \ | |||
| std::cout << "FAIL! " #a " != " #b << std::endl; \ | |||
| std::cout << "expected: " << (a) << std::endl; \ | |||
| std::cout << "returned: " << (b) << std::endl; \ | |||
| return; \ | |||
| } } while(!True()) | |||
| } /* namespace lol */ | |||
| #endif // __LOL_UNIT_H__ | |||
| @@ -1,10 +1,6 @@ | |||
| AM_CPPFLAGS = -I$(top_srcdir)/src | |||
| if USE_CPPUNIT | |||
| cppunit_tests = lol-test | |||
| endif | |||
| bench: lol-bench$(EXEEXT) | |||
| ./lol-bench$(EXEEXT) | |||
| @@ -12,17 +8,16 @@ all-local: quad$(EXEEXT) lol-bench$(EXEEXT) | |||
| test x$(MAKE_FSELF) = xno || make_fself quad$(EXEEXT) quad.self | |||
| test x$(MAKE_FSELF) = xno || make_fself sandbox$(EXEEXT) sandbox.self | |||
| test x$(MAKE_FSELF) = xno || make_fself lol-bench$(EXEEXT) lol-bench.self | |||
| test x$(MAKE_FSELF) = xno || make_fself lol-test$(EXEEXT) lol-test.self | |||
| CLEANFILES = quad.self sandbox lol-bench.self | |||
| CLEANFILES = quad.self sandbox lol-bench.self lol-test.self | |||
| noinst_PROGRAMS = quad sandbox lol-bench $(cppunit_tests) | |||
| noinst_PROGRAMS = quad sandbox lol-bench lol-test | |||
| TESTS = $(cppunit_tests) | |||
| TESTS = lol-test | |||
| lol_test_SOURCES = lol-test.cpp matrix.cpp half.cpp trig.cpp | |||
| lol_test_CXXFLAGS = $(CPPUNIT_CFLAGS) | |||
| lol_test_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | |||
| lol_test_LDADD = $(CPPUNIT_LIBS) | |||
| lol_test_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | |||
| lol_test_DEPENDENCIES = $(top_builddir)/src/liblol.a | |||
| @@ -12,14 +12,10 @@ | |||
| # include "config.h" | |||
| #endif | |||
| #include <cppunit/extensions/HelperMacros.h> | |||
| #include <cppunit/TestCaller.h> | |||
| #include <cppunit/TestCase.h> | |||
| #include <cppunit/TestSuite.h> | |||
| #include <cmath> | |||
| #include "core.h" | |||
| #include "lol/unit.h" | |||
| /* Ensure isnan() is present even on systems that don't define it, or | |||
| * when -ffast-math is being used. */ | |||
| @@ -37,159 +33,139 @@ static inline int isnan(float f) | |||
| namespace lol | |||
| { | |||
| class HalfTest : public CppUnit::TestCase | |||
| LOLUNIT_FIXTURE(HalfTest) | |||
| { | |||
| CPPUNIT_TEST_SUITE(HalfTest); | |||
| CPPUNIT_TEST(test_half_from_float); | |||
| CPPUNIT_TEST(test_half_makeaccurate); | |||
| CPPUNIT_TEST(test_half_makebits); | |||
| CPPUNIT_TEST(test_half_is_nan); | |||
| CPPUNIT_TEST(test_half_is_inf); | |||
| CPPUNIT_TEST(test_half_is_finite); | |||
| CPPUNIT_TEST(test_half_is_normal); | |||
| CPPUNIT_TEST(test_half_classify); | |||
| CPPUNIT_TEST(test_half_to_float); | |||
| CPPUNIT_TEST(test_half_to_int); | |||
| CPPUNIT_TEST(test_float_op_half); | |||
| CPPUNIT_TEST(test_half_op_float); | |||
| CPPUNIT_TEST_SUITE_END(); | |||
| public: | |||
| HalfTest() : CppUnit::TestCase("Matrix Test") {} | |||
| void setUp() | |||
| { | |||
| } | |||
| void setUp() {} | |||
| void tearDown() {} | |||
| void test_half_from_float() | |||
| LOLUNIT_TEST(test_half_from_float) | |||
| { | |||
| for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) | |||
| { | |||
| half a = (half)pairs[i].f; | |||
| uint16_t b = pairs[i].x; | |||
| CPPUNIT_ASSERT_EQUAL(a.bits, b); | |||
| LOLUNIT_ASSERT_EQUAL(a.bits, b); | |||
| } | |||
| } | |||
| void test_half_makeaccurate() | |||
| LOLUNIT_TEST(test_half_makeaccurate) | |||
| { | |||
| for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) | |||
| { | |||
| half a = half::makeaccurate(pairs[i].f); | |||
| uint16_t b = pairs[i].x; | |||
| CPPUNIT_ASSERT_EQUAL(a.bits, b); | |||
| LOLUNIT_ASSERT_EQUAL(a.bits, b); | |||
| } | |||
| } | |||
| void test_half_makebits() | |||
| LOLUNIT_TEST(test_half_makebits) | |||
| { | |||
| for (unsigned int i = 0; i < 0x10000; i++) | |||
| { | |||
| half a = half::makebits(i); | |||
| uint16_t b = i; | |||
| CPPUNIT_ASSERT_EQUAL(a.bits, b); | |||
| LOLUNIT_ASSERT_EQUAL(a.bits, b); | |||
| } | |||
| } | |||
| void test_half_is_nan() | |||
| LOLUNIT_TEST(test_half_is_nan) | |||
| { | |||
| CPPUNIT_ASSERT(half::makebits(0x7c01).is_nan()); | |||
| CPPUNIT_ASSERT(half::makebits(0xfc01).is_nan()); | |||
| CPPUNIT_ASSERT(half::makebits(0x7e00).is_nan()); | |||
| CPPUNIT_ASSERT(half::makebits(0xfe00).is_nan()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7c00).is_nan()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfc00).is_nan()); | |||
| CPPUNIT_ASSERT(!half(0.0f).is_nan()); | |||
| CPPUNIT_ASSERT(!half(-0.0f).is_nan()); | |||
| CPPUNIT_ASSERT(!half(2.0f).is_nan()); | |||
| CPPUNIT_ASSERT(!half(-2.0f).is_nan()); | |||
| LOLUNIT_ASSERT(half::makebits(0x7c01).is_nan()); | |||
| LOLUNIT_ASSERT(half::makebits(0xfc01).is_nan()); | |||
| LOLUNIT_ASSERT(half::makebits(0x7e00).is_nan()); | |||
| LOLUNIT_ASSERT(half::makebits(0xfe00).is_nan()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7c00).is_nan()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfc00).is_nan()); | |||
| LOLUNIT_ASSERT(!half(0.0f).is_nan()); | |||
| LOLUNIT_ASSERT(!half(-0.0f).is_nan()); | |||
| LOLUNIT_ASSERT(!half(2.0f).is_nan()); | |||
| LOLUNIT_ASSERT(!half(-2.0f).is_nan()); | |||
| } | |||
| void test_half_is_inf() | |||
| LOLUNIT_TEST(test_half_is_inf) | |||
| { | |||
| CPPUNIT_ASSERT(half(65536.0f).is_inf()); | |||
| CPPUNIT_ASSERT(half(-65536.0f).is_inf()); | |||
| LOLUNIT_ASSERT(half(65536.0f).is_inf()); | |||
| LOLUNIT_ASSERT(half(-65536.0f).is_inf()); | |||
| CPPUNIT_ASSERT(!half(0.0f).is_inf()); | |||
| CPPUNIT_ASSERT(!half(-0.0f).is_inf()); | |||
| CPPUNIT_ASSERT(!half(65535.0f).is_inf()); | |||
| CPPUNIT_ASSERT(!half(-65535.0f).is_inf()); | |||
| LOLUNIT_ASSERT(!half(0.0f).is_inf()); | |||
| LOLUNIT_ASSERT(!half(-0.0f).is_inf()); | |||
| LOLUNIT_ASSERT(!half(65535.0f).is_inf()); | |||
| LOLUNIT_ASSERT(!half(-65535.0f).is_inf()); | |||
| CPPUNIT_ASSERT(half::makebits(0x7c00).is_inf()); | |||
| CPPUNIT_ASSERT(half::makebits(0xfc00).is_inf()); | |||
| LOLUNIT_ASSERT(half::makebits(0x7c00).is_inf()); | |||
| LOLUNIT_ASSERT(half::makebits(0xfc00).is_inf()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7e00).is_inf()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfe00).is_inf()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7e00).is_inf()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfe00).is_inf()); | |||
| } | |||
| void test_half_is_finite() | |||
| LOLUNIT_TEST(test_half_is_finite) | |||
| { | |||
| CPPUNIT_ASSERT(half(0.0f).is_finite()); | |||
| CPPUNIT_ASSERT(half(-0.0f).is_finite()); | |||
| CPPUNIT_ASSERT(half(65535.0f).is_finite()); | |||
| CPPUNIT_ASSERT(half(-65535.0f).is_finite()); | |||
| LOLUNIT_ASSERT(half(0.0f).is_finite()); | |||
| LOLUNIT_ASSERT(half(-0.0f).is_finite()); | |||
| LOLUNIT_ASSERT(half(65535.0f).is_finite()); | |||
| LOLUNIT_ASSERT(half(-65535.0f).is_finite()); | |||
| CPPUNIT_ASSERT(!half(65536.0f).is_finite()); | |||
| CPPUNIT_ASSERT(!half(-65536.0f).is_finite()); | |||
| LOLUNIT_ASSERT(!half(65536.0f).is_finite()); | |||
| LOLUNIT_ASSERT(!half(-65536.0f).is_finite()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7c00).is_finite()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfc00).is_finite()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7c00).is_finite()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfc00).is_finite()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7e00).is_finite()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfe00).is_finite()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7e00).is_finite()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfe00).is_finite()); | |||
| } | |||
| void test_half_is_normal() | |||
| LOLUNIT_TEST(test_half_is_normal) | |||
| { | |||
| CPPUNIT_ASSERT(half(0.0f).is_normal()); | |||
| CPPUNIT_ASSERT(half(-0.0f).is_normal()); | |||
| CPPUNIT_ASSERT(half(65535.0f).is_normal()); | |||
| CPPUNIT_ASSERT(half(-65535.0f).is_normal()); | |||
| LOLUNIT_ASSERT(half(0.0f).is_normal()); | |||
| LOLUNIT_ASSERT(half(-0.0f).is_normal()); | |||
| LOLUNIT_ASSERT(half(65535.0f).is_normal()); | |||
| LOLUNIT_ASSERT(half(-65535.0f).is_normal()); | |||
| CPPUNIT_ASSERT(!half(65536.0f).is_normal()); | |||
| CPPUNIT_ASSERT(!half(-65536.0f).is_normal()); | |||
| LOLUNIT_ASSERT(!half(65536.0f).is_normal()); | |||
| LOLUNIT_ASSERT(!half(-65536.0f).is_normal()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7c00).is_normal()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfc00).is_normal()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7c00).is_normal()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfc00).is_normal()); | |||
| CPPUNIT_ASSERT(!half::makebits(0x7e00).is_normal()); | |||
| CPPUNIT_ASSERT(!half::makebits(0xfe00).is_normal()); | |||
| LOLUNIT_ASSERT(!half::makebits(0x7e00).is_normal()); | |||
| LOLUNIT_ASSERT(!half::makebits(0xfe00).is_normal()); | |||
| } | |||
| void test_half_classify() | |||
| LOLUNIT_TEST(test_half_classify) | |||
| { | |||
| for (uint32_t i = 0; i < 0x10000; i++) | |||
| { | |||
| half h = half::makebits(i); | |||
| if (h.is_nan()) | |||
| { | |||
| CPPUNIT_ASSERT(!h.is_inf()); | |||
| CPPUNIT_ASSERT(!h.is_normal()); | |||
| CPPUNIT_ASSERT(!h.is_finite()); | |||
| LOLUNIT_ASSERT(!h.is_inf()); | |||
| LOLUNIT_ASSERT(!h.is_normal()); | |||
| LOLUNIT_ASSERT(!h.is_finite()); | |||
| } | |||
| else if (h.is_inf()) | |||
| { | |||
| CPPUNIT_ASSERT(!h.is_normal()); | |||
| CPPUNIT_ASSERT(!h.is_finite()); | |||
| LOLUNIT_ASSERT(!h.is_normal()); | |||
| LOLUNIT_ASSERT(!h.is_finite()); | |||
| } | |||
| else | |||
| { | |||
| CPPUNIT_ASSERT(h.is_finite()); | |||
| LOLUNIT_ASSERT(h.is_finite()); | |||
| } | |||
| } | |||
| } | |||
| void test_half_to_float() | |||
| LOLUNIT_TEST(test_half_to_float) | |||
| { | |||
| for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) | |||
| { | |||
| float a = (float)half::makebits(pairs[i].x); | |||
| float b = pairs[i].f; | |||
| CPPUNIT_ASSERT_EQUAL(a, b); | |||
| LOLUNIT_ASSERT_EQUAL(a, b); | |||
| } | |||
| for (uint32_t i = 0; i < 0x10000; i++) | |||
| @@ -199,73 +175,73 @@ public: | |||
| half g = (half)f; | |||
| if (h.is_nan()) | |||
| { | |||
| CPPUNIT_ASSERT(isnan(f)); | |||
| CPPUNIT_ASSERT(g.is_nan()); | |||
| LOLUNIT_ASSERT(isnan(f)); | |||
| LOLUNIT_ASSERT(g.is_nan()); | |||
| } | |||
| else | |||
| { | |||
| CPPUNIT_ASSERT(!isnan(f)); | |||
| CPPUNIT_ASSERT_EQUAL(g.bits, h.bits); | |||
| LOLUNIT_ASSERT(!isnan(f)); | |||
| LOLUNIT_ASSERT_EQUAL(g.bits, h.bits); | |||
| } | |||
| } | |||
| } | |||
| void test_half_to_int() | |||
| LOLUNIT_TEST(test_half_to_int) | |||
| { | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(0.0f), 0); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(-0.0f), 0); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(0.9f), 0); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(-0.9f), 0); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(1.0f), 1); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(-1.0f), -1); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(1.9f), 1); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(-1.9f), -1); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(65504.0f), 65504); | |||
| CPPUNIT_ASSERT_EQUAL((int)(half)(-65504.0f), -65504); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(0.0f), 0); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(-0.0f), 0); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(0.9f), 0); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(-0.9f), 0); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(1.0f), 1); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(-1.0f), -1); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(1.9f), 1); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(-1.9f), -1); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(65504.0f), 65504); | |||
| LOLUNIT_ASSERT_EQUAL((int)(half)(-65504.0f), -65504); | |||
| } | |||
| void test_float_op_half() | |||
| LOLUNIT_TEST(test_float_op_half) | |||
| { | |||
| half zero = 0; | |||
| half one = 1; | |||
| half two = 2; | |||
| float a = zero + one; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, a); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, a); | |||
| a += zero; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, a); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, a); | |||
| a -= zero; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, a); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, a); | |||
| a *= one; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, a); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, a); | |||
| a /= one; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, a); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, a); | |||
| float b = one + zero; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, b); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, b); | |||
| b += one; | |||
| CPPUNIT_ASSERT_EQUAL(2.0f, b); | |||
| LOLUNIT_ASSERT_EQUAL(2.0f, b); | |||
| b *= two; | |||
| CPPUNIT_ASSERT_EQUAL(4.0f, b); | |||
| LOLUNIT_ASSERT_EQUAL(4.0f, b); | |||
| b -= two; | |||
| CPPUNIT_ASSERT_EQUAL(2.0f, b); | |||
| LOLUNIT_ASSERT_EQUAL(2.0f, b); | |||
| b /= two; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, b); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, b); | |||
| float c = one - zero; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, c); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, c); | |||
| float d = two - one; | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, d); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, d); | |||
| float e = two + (-one); | |||
| CPPUNIT_ASSERT_EQUAL(1.0f, e); | |||
| LOLUNIT_ASSERT_EQUAL(1.0f, e); | |||
| float f = (two * two) / (one + one); | |||
| CPPUNIT_ASSERT_EQUAL(2.0f, f); | |||
| LOLUNIT_ASSERT_EQUAL(2.0f, f); | |||
| } | |||
| void test_half_op_float() | |||
| LOLUNIT_TEST(test_half_op_float) | |||
| { | |||
| half zero = 0; | |||
| half one = 1; | |||
| @@ -273,38 +249,38 @@ public: | |||
| half four = 4; | |||
| half a = one + 0.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| a += 0.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| a -= 0.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| a *= 1.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| a /= 1.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, a.bits); | |||
| half b = one + 0.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, b.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, b.bits); | |||
| b += 1.0f; | |||
| CPPUNIT_ASSERT_EQUAL(two.bits, b.bits); | |||
| LOLUNIT_ASSERT_EQUAL(two.bits, b.bits); | |||
| b *= 2.0f; | |||
| CPPUNIT_ASSERT_EQUAL(four.bits, b.bits); | |||
| LOLUNIT_ASSERT_EQUAL(four.bits, b.bits); | |||
| b -= 2.0f; | |||
| CPPUNIT_ASSERT_EQUAL(two.bits, b.bits); | |||
| LOLUNIT_ASSERT_EQUAL(two.bits, b.bits); | |||
| b /= 2.0f; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, b.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, b.bits); | |||
| half c = 1.0f - zero; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, c.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, c.bits); | |||
| half d = 2.0f - one; | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, d.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, d.bits); | |||
| half e = 2.0f + (-one); | |||
| CPPUNIT_ASSERT_EQUAL(one.bits, e.bits); | |||
| LOLUNIT_ASSERT_EQUAL(one.bits, e.bits); | |||
| half f = (2.0f * two) / (1.0f + one); | |||
| CPPUNIT_ASSERT_EQUAL(two.bits, f.bits); | |||
| LOLUNIT_ASSERT_EQUAL(two.bits, f.bits); | |||
| } | |||
| private: | |||
| @@ -329,7 +305,7 @@ HalfTest::TestPair const HalfTest::pairs[] = | |||
| { 31.0f / (1 << 19), 0x03e0 }, /* 0x1.fp-15, denormal */ | |||
| }; | |||
| CPPUNIT_TEST_SUITE_REGISTRATION(HalfTest); | |||
| LOLUNIT_SETUP_FIXTURE(HalfTest); | |||
| } /* namespace lol */ | |||
| @@ -14,19 +14,12 @@ | |||
| #include <cstdio> | |||
| #include <cppunit/TextTestRunner.h> | |||
| #include <cppunit/extensions/TestFactoryRegistry.h> | |||
| #include <lol/unit.h> | |||
| int main(int argc, char *argv[]) | |||
| int main(void) | |||
| { | |||
| CppUnit::TextTestRunner runner; | |||
| runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); | |||
| int ret = !runner.run(); | |||
| #if defined _WIN32 | |||
| getchar(); | |||
| #endif | |||
| lol::TestRunner runner; | |||
| int ret = !runner.Run(); | |||
| return ret; | |||
| } | |||
| @@ -12,31 +12,15 @@ | |||
| # include "config.h" | |||
| #endif | |||
| #include <cppunit/extensions/HelperMacros.h> | |||
| #include <cppunit/TestCaller.h> | |||
| #include <cppunit/TestCase.h> | |||
| #include <cppunit/TestSuite.h> | |||
| #include "core.h" | |||
| #include "lol/unit.h" | |||
| namespace lol | |||
| { | |||
| class MatrixTest : public CppUnit::TestCase | |||
| LOLUNIT_FIXTURE(MatrixTest) | |||
| { | |||
| CPPUNIT_TEST_SUITE(MatrixTest); | |||
| CPPUNIT_TEST(test_vec_eq); | |||
| CPPUNIT_TEST(test_vec_lt); | |||
| CPPUNIT_TEST(test_vec_unary); | |||
| CPPUNIT_TEST(test_vec_cast); | |||
| CPPUNIT_TEST(test_mat_det); | |||
| CPPUNIT_TEST(test_mat_mul); | |||
| CPPUNIT_TEST(test_mat_inv); | |||
| CPPUNIT_TEST_SUITE_END(); | |||
| public: | |||
| MatrixTest() : CppUnit::TestCase("Matrix Test") {} | |||
| void setUp() | |||
| { | |||
| identity = mat4(1.0f); | |||
| @@ -52,34 +36,34 @@ public: | |||
| void tearDown() {} | |||
| void test_vec_eq() | |||
| LOLUNIT_TEST(test_vec_eq) | |||
| { | |||
| vec2 a2(1.0f, 2.0f); | |||
| vec2 b2(0.0f, 2.0f); | |||
| vec2 c2(1.0f, 0.0f); | |||
| CPPUNIT_ASSERT(a2 == a2); | |||
| CPPUNIT_ASSERT(!(a2 != a2)); | |||
| LOLUNIT_ASSERT(a2 == a2); | |||
| LOLUNIT_ASSERT(!(a2 != a2)); | |||
| CPPUNIT_ASSERT(a2 != b2); | |||
| CPPUNIT_ASSERT(!(a2 == b2)); | |||
| CPPUNIT_ASSERT(a2 != c2); | |||
| CPPUNIT_ASSERT(!(a2 == c2)); | |||
| LOLUNIT_ASSERT(a2 != b2); | |||
| LOLUNIT_ASSERT(!(a2 == b2)); | |||
| LOLUNIT_ASSERT(a2 != c2); | |||
| LOLUNIT_ASSERT(!(a2 == c2)); | |||
| vec3 a3(1.0f, 2.0f, 3.0f); | |||
| vec3 b3(0.0f, 2.0f, 3.0f); | |||
| vec3 c3(1.0f, 0.0f, 3.0f); | |||
| vec3 d3(1.0f, 2.0f, 0.0f); | |||
| CPPUNIT_ASSERT(a3 == a3); | |||
| CPPUNIT_ASSERT(!(a3 != a3)); | |||
| LOLUNIT_ASSERT(a3 == a3); | |||
| LOLUNIT_ASSERT(!(a3 != a3)); | |||
| CPPUNIT_ASSERT(a3 != b3); | |||
| CPPUNIT_ASSERT(!(a3 == b3)); | |||
| CPPUNIT_ASSERT(a3 != c3); | |||
| CPPUNIT_ASSERT(!(a3 == c3)); | |||
| CPPUNIT_ASSERT(a3 != d3); | |||
| CPPUNIT_ASSERT(!(a3 == d3)); | |||
| LOLUNIT_ASSERT(a3 != b3); | |||
| LOLUNIT_ASSERT(!(a3 == b3)); | |||
| LOLUNIT_ASSERT(a3 != c3); | |||
| LOLUNIT_ASSERT(!(a3 == c3)); | |||
| LOLUNIT_ASSERT(a3 != d3); | |||
| LOLUNIT_ASSERT(!(a3 == d3)); | |||
| vec4 a4(1.0f, 2.0f, 3.0f, 4.0f); | |||
| vec4 b4(0.0f, 2.0f, 3.0f, 4.0f); | |||
| @@ -87,20 +71,20 @@ public: | |||
| vec4 d4(1.0f, 2.0f, 0.0f, 4.0f); | |||
| vec4 e4(1.0f, 2.0f, 3.0f, 0.0f); | |||
| CPPUNIT_ASSERT(a4 == a4); | |||
| CPPUNIT_ASSERT(!(a4 != a4)); | |||
| CPPUNIT_ASSERT(a4 != b4); | |||
| CPPUNIT_ASSERT(!(a4 == b4)); | |||
| CPPUNIT_ASSERT(a4 != c4); | |||
| CPPUNIT_ASSERT(!(a4 == c4)); | |||
| CPPUNIT_ASSERT(a4 != d4); | |||
| CPPUNIT_ASSERT(!(a4 == d4)); | |||
| CPPUNIT_ASSERT(a4 != e4); | |||
| CPPUNIT_ASSERT(!(a4 == e4)); | |||
| LOLUNIT_ASSERT(a4 == a4); | |||
| LOLUNIT_ASSERT(!(a4 != a4)); | |||
| LOLUNIT_ASSERT(a4 != b4); | |||
| LOLUNIT_ASSERT(!(a4 == b4)); | |||
| LOLUNIT_ASSERT(a4 != c4); | |||
| LOLUNIT_ASSERT(!(a4 == c4)); | |||
| LOLUNIT_ASSERT(a4 != d4); | |||
| LOLUNIT_ASSERT(!(a4 == d4)); | |||
| LOLUNIT_ASSERT(a4 != e4); | |||
| LOLUNIT_ASSERT(!(a4 == e4)); | |||
| } | |||
| void test_vec_lt() | |||
| LOLUNIT_TEST(test_vec_lt) | |||
| { | |||
| vec2 a2(1.0f, 3.0f); | |||
| vec2 b2(0.0f, 0.0f); | |||
| @@ -109,118 +93,118 @@ public: | |||
| vec2 e2(3.0f, 3.0f); | |||
| vec2 f2(4.0f, 4.0f); | |||
| CPPUNIT_ASSERT(a2 <= a2); | |||
| CPPUNIT_ASSERT(!(a2 < a2)); | |||
| CPPUNIT_ASSERT(!(a2 <= b2)); | |||
| CPPUNIT_ASSERT(!(a2 < b2)); | |||
| CPPUNIT_ASSERT(!(a2 <= c2)); | |||
| CPPUNIT_ASSERT(!(a2 < c2)); | |||
| CPPUNIT_ASSERT(!(a2 <= d2)); | |||
| CPPUNIT_ASSERT(!(a2 < d2)); | |||
| CPPUNIT_ASSERT(a2 <= e2); | |||
| CPPUNIT_ASSERT(!(a2 < e2)); | |||
| CPPUNIT_ASSERT(a2 <= f2); | |||
| CPPUNIT_ASSERT(a2 < f2); | |||
| LOLUNIT_ASSERT(a2 <= a2); | |||
| LOLUNIT_ASSERT(!(a2 < a2)); | |||
| LOLUNIT_ASSERT(!(a2 <= b2)); | |||
| LOLUNIT_ASSERT(!(a2 < b2)); | |||
| LOLUNIT_ASSERT(!(a2 <= c2)); | |||
| LOLUNIT_ASSERT(!(a2 < c2)); | |||
| LOLUNIT_ASSERT(!(a2 <= d2)); | |||
| LOLUNIT_ASSERT(!(a2 < d2)); | |||
| LOLUNIT_ASSERT(a2 <= e2); | |||
| LOLUNIT_ASSERT(!(a2 < e2)); | |||
| LOLUNIT_ASSERT(a2 <= f2); | |||
| LOLUNIT_ASSERT(a2 < f2); | |||
| } | |||
| void test_vec_unary() | |||
| LOLUNIT_TEST(test_vec_unary) | |||
| { | |||
| vec2 a(1.0f, 3.0f); | |||
| vec2 b(-1.0f, -3.0f); | |||
| CPPUNIT_ASSERT(a == -b); | |||
| CPPUNIT_ASSERT(-a == b); | |||
| LOLUNIT_ASSERT(a == -b); | |||
| LOLUNIT_ASSERT(-a == b); | |||
| } | |||
| void test_vec_cast() | |||
| LOLUNIT_TEST(test_vec_cast) | |||
| { | |||
| vec2 a1(1.0f, 3.0f); | |||
| vec3 b(a1); | |||
| vec2 a2(b); | |||
| CPPUNIT_ASSERT_EQUAL(b.x, a1.x); | |||
| CPPUNIT_ASSERT_EQUAL(b.y, a1.y); | |||
| CPPUNIT_ASSERT_EQUAL(b.z, 0.0f); | |||
| CPPUNIT_ASSERT(a2 == a1); | |||
| LOLUNIT_ASSERT_EQUAL(b.x, a1.x); | |||
| LOLUNIT_ASSERT_EQUAL(b.y, a1.y); | |||
| LOLUNIT_ASSERT_EQUAL(b.z, 0.0f); | |||
| LOLUNIT_ASSERT(a2 == a1); | |||
| vec4 c(a1); | |||
| vec2 a3(c); | |||
| CPPUNIT_ASSERT_EQUAL(c.x, a1.x); | |||
| CPPUNIT_ASSERT_EQUAL(c.y, a1.y); | |||
| CPPUNIT_ASSERT_EQUAL(c.z, 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(c.w, 0.0f); | |||
| CPPUNIT_ASSERT(a3 == a1); | |||
| LOLUNIT_ASSERT_EQUAL(c.x, a1.x); | |||
| LOLUNIT_ASSERT_EQUAL(c.y, a1.y); | |||
| LOLUNIT_ASSERT_EQUAL(c.z, 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(c.w, 0.0f); | |||
| LOLUNIT_ASSERT(a3 == a1); | |||
| } | |||
| void test_mat_det() | |||
| LOLUNIT_TEST(test_mat_det) | |||
| { | |||
| float d1 = triangular.det(); | |||
| CPPUNIT_ASSERT_EQUAL(d1, 24.0f); | |||
| LOLUNIT_ASSERT_EQUAL(d1, 24.0f); | |||
| float d2 = invertible.det(); | |||
| CPPUNIT_ASSERT_EQUAL(d2, -1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(d2, -1.0f); | |||
| } | |||
| void test_mat_mul() | |||
| LOLUNIT_TEST(test_mat_mul) | |||
| { | |||
| mat4 m0 = identity; | |||
| mat4 m1 = identity; | |||
| mat4 m2 = m0 * m1; | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); | |||
| } | |||
| void test_mat_inv() | |||
| LOLUNIT_TEST(test_mat_inv) | |||
| { | |||
| mat4 m0 = invertible; | |||
| mat4 m1 = m0.invert(); | |||
| mat4 m2 = m0 * m1; | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); | |||
| CPPUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); | |||
| LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); | |||
| } | |||
| private: | |||
| mat4 triangular, identity, invertible; | |||
| }; | |||
| CPPUNIT_TEST_SUITE_REGISTRATION(MatrixTest); | |||
| LOLUNIT_SETUP_FIXTURE(MatrixTest); | |||
| } /* namespace lol */ | |||
| @@ -12,32 +12,21 @@ | |||
| # include "config.h" | |||
| #endif | |||
| #include <cppunit/extensions/HelperMacros.h> | |||
| #include <cppunit/TestCaller.h> | |||
| #include <cppunit/TestCase.h> | |||
| #include <cppunit/TestSuite.h> | |||
| #include <cmath> | |||
| #include "core.h" | |||
| #include "lol/unit.h" | |||
| namespace lol | |||
| { | |||
| class TrigTest : public CppUnit::TestCase | |||
| LOLUNIT_FIXTURE(TrigTest) | |||
| { | |||
| CPPUNIT_TEST_SUITE(TrigTest); | |||
| CPPUNIT_TEST(test_sin); | |||
| CPPUNIT_TEST_SUITE_END(); | |||
| public: | |||
| TrigTest() : CppUnit::TestCase("Trigonometry Test") {} | |||
| void setUp() {} | |||
| void tearDown() {} | |||
| void test_sin() | |||
| LOLUNIT_TEST(test_sin) | |||
| { | |||
| for (int i = -10000; i < 10000; i++) | |||
| { | |||
| @@ -48,7 +37,7 @@ public: | |||
| double a = sin(f); | |||
| #endif | |||
| double b = lol_sin(f); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| for (int i = -10000; i < 10000; i++) | |||
| @@ -60,9 +49,12 @@ public: | |||
| double a = sin(f); | |||
| #endif | |||
| double b = lol_sin(f); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| } | |||
| LOLUNIT_TEST(test_cos) | |||
| { | |||
| for (int i = -10000; i < 10000; i++) | |||
| { | |||
| double f = (double)i * (1.0 / 1000.0); | |||
| @@ -72,7 +64,7 @@ public: | |||
| double a = cos(f); | |||
| #endif | |||
| double b = lol_cos(f); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| for (int i = -10000; i < 10000; i++) | |||
| @@ -84,9 +76,12 @@ public: | |||
| double a = cos(f); | |||
| #endif | |||
| double b = lol_cos(f); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| } | |||
| LOLUNIT_TEST(test_sincos) | |||
| { | |||
| for (int i = -10000; i < 10000; i++) | |||
| { | |||
| double f = (double)i * (1.0 / 1000.0); | |||
| @@ -99,8 +94,8 @@ public: | |||
| #endif | |||
| double b1, b2; | |||
| lol_sincos(f, &b1, &b2); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); | |||
| } | |||
| for (int i = -10000; i < 10000; i++) | |||
| @@ -115,10 +110,13 @@ public: | |||
| #endif | |||
| double b1, b2; | |||
| lol_sincos(f, &b1, &b2); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); | |||
| } | |||
| } | |||
| LOLUNIT_TEST(test_tan) | |||
| { | |||
| for (int i = -100000; i < 100000; i++) | |||
| { | |||
| double f = (double)i * (1.0 / 10000.0); | |||
| @@ -129,11 +127,11 @@ public: | |||
| #endif | |||
| double b = lol_tan(f); | |||
| if (fabs(a) > 1e4) | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); | |||
| else if (fabs(a) > 1.0) | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); | |||
| else | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| for (int i = -10000; i < 10000; i++) | |||
| @@ -146,16 +144,16 @@ public: | |||
| #endif | |||
| double b = lol_tan(f); | |||
| if (fabs(a) > 1e4) | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); | |||
| else if (fabs(a) > 1.0) | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); | |||
| else | |||
| CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); | |||
| } | |||
| } | |||
| }; | |||
| CPPUNIT_TEST_SUITE_REGISTRATION(TrigTest); | |||
| LOLUNIT_SETUP_FIXTURE(TrigTest); | |||
| } /* namespace lol */ | |||
| @@ -3,18 +3,15 @@ | |||
| <ImportGroup Label="PropertySheets" /> | |||
| <PropertyGroup Label="UserMacros"> | |||
| <ContribDir>$(SolutionDir)\..\contrib</ContribDir> | |||
| <CppUnitDir>$(ContribDir)\cppunit-1.12.2</CppUnitDir> | |||
| <GlewDir>$(ContribDir)\glew-1.6.0</GlewDir> | |||
| <GtkDir>$(ContribDir)\gtk-2.22.1</GtkDir> | |||
| <GtkGlDir>$(ContribDir)\gtkglarea-2.0.1</GtkGlDir> | |||
| <SdlDir>$(ContribDir)\sdl-1.2.14</SdlDir> | |||
| <SdlImageDir>$(ContribDir)\sdl-image-1.2.10</SdlImageDir> | |||
| <SdlMixerDir>$(ContribDir)\sdl-mixer-1.2.11</SdlMixerDir> | |||
| <CppUnitIncludes>$(CppUnitDir)\include</CppUnitIncludes> | |||
| <GlIncludes>$(GlewDir)\include</GlIncludes> | |||
| <GtkIncludes>$(GtkDir)\lib\glib-2.0\include;$(GtkDir)\lib\gtk-2.0\include;$(GtkDir)\include\glib-2.0;$(GtkDir)\include\gtk-2.0;$(GtkDir)\include\cairo;$(GtkDir)\include\pango-1.0;$(GtkDir)\include\gdk-pixbuf-2.0;$(GtkDir)\include\atk-1.0;$(GtkGlDir)\include</GtkIncludes> | |||
| <SdlIncludes>$(SdlDir)\include;$(SdlImageDir)\include;$(SdlMixerDir)\include</SdlIncludes> | |||
| <CppUnitLibs>$(CppUnitDir)\lib</CppUnitLibs> | |||
| <GlLibs>$(GlewDir)\lib</GlLibs> | |||
| <GtkLibs>$(GtkDir)\lib;$(GtkDir)\bin;$(GtkGlDir)\lib</GtkLibs> | |||
| <SdlLibs>$(SdlDir)\lib;$(SdlImageDir)\lib;$(SdlMixerDir)\lib</SdlLibs> | |||
| @@ -27,18 +24,15 @@ | |||
| <ItemDefinitionGroup /> | |||
| <ItemGroup> | |||
| <BuildMacro Include="ContribDir"><Value>$(ContribDir)</Value></BuildMacro> | |||
| <BuildMacro Include="CppUnitDir"><Value>$(CppUnitDir)</Value></BuildMacro> | |||
| <BuildMacro Include="GlewDir"><Value>$(GlewDir)</Value></BuildMacro> | |||
| <BuildMacro Include="GtkDir"><Value>$(GtkDir)</Value></BuildMacro> | |||
| <BuildMacro Include="GtkGlDir"><Value>$(GtkGlDir)</Value></BuildMacro> | |||
| <BuildMacro Include="SdlDir"><Value>$(SdlDir)</Value></BuildMacro> | |||
| <BuildMacro Include="SdlImageDir"><Value>$(SdlImageDir)</Value></BuildMacro> | |||
| <BuildMacro Include="SdlMixerDir"><Value>$(SdlMixerDir)</Value></BuildMacro> | |||
| <BuildMacro Include="CppUnitIncludes"><Value>$(CppUnitIncludes)</Value></BuildMacro> | |||
| <BuildMacro Include="GlIncludes"><Value>$(GlIncludes)</Value></BuildMacro> | |||
| <BuildMacro Include="GtkIncludes"><Value>$(GtkIncludes)</Value></BuildMacro> | |||
| <BuildMacro Include="SdlIncludes"><Value>$(SdlIncludes)</Value></BuildMacro> | |||
| <BuildMacro Include="CppUnitLibss"><Value>$(CppUnitLibss)</Value></BuildMacro> | |||
| <BuildMacro Include="GlLibs"><Value>$(GlLibs)</Value></BuildMacro> | |||
| <BuildMacro Include="GtkLibs"><Value>$(GtkLibs)</Value></BuildMacro> | |||
| <BuildMacro Include="SdlLibs"><Value>$(SdlLibs)</Value></BuildMacro> | |||
| @@ -62,13 +62,13 @@ | |||
| <WarningLevel>Level3</WarningLevel> | |||
| <Optimization>Disabled</Optimization> | |||
| <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;$(LolDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
| <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(CppUnitIncludes);$(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
| <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
| </ClCompile> | |||
| <Link> | |||
| <SubSystem>Console</SubSystem> | |||
| <GenerateDebugInformation>true</GenerateDebugInformation> | |||
| <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);$(SdlDeps);libcppunit_msvcd.lib;$(GlDeps);$(OutDir)\lolcore.lib</AdditionalDependencies> | |||
| <AdditionalLibraryDirectories>$(SdlLibs);$(CppUnitLibs);$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
| <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);$(SdlDeps);$(GlDeps);$(OutDir)\lolcore.lib</AdditionalDependencies> | |||
| <AdditionalLibraryDirectories>$(SdlLibs);$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
| </Link> | |||
| <PostBuildEvent> | |||
| <Command>for %%I in ($(SdlLibs)) do xcopy /y /c /d %%I\*.dll $(TargetDir)</Command> | |||
| @@ -83,15 +83,15 @@ | |||
| <FunctionLevelLinking>true</FunctionLevelLinking> | |||
| <IntrinsicFunctions>true</IntrinsicFunctions> | |||
| <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;$(LolDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
| <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(CppUnitIncludes);$(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
| <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
| </ClCompile> | |||
| <Link> | |||
| <SubSystem>Console</SubSystem> | |||
| <GenerateDebugInformation>true</GenerateDebugInformation> | |||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
| <OptimizeReferences>true</OptimizeReferences> | |||
| <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);$(SdlDeps);libcppunit_msvc.lib;$(GlDeps);$(OutDir)\lolcore.lib</AdditionalDependencies> | |||
| <AdditionalLibraryDirectories>$(SdlLibs);$(CppUnitLibs);$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
| <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);$(SdlDeps);$(GlDeps);$(OutDir)\lolcore.lib</AdditionalDependencies> | |||
| <AdditionalLibraryDirectories>$(SdlLibs);$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
| </Link> | |||
| <PostBuildEvent> | |||
| <Command>for %%I in ($(SdlLibs)) do xcopy /y /c /d %%I\*.dll $(TargetDir)</Command> | |||