| 1 |
#include <cppunit/extensions/HelperMacros.h> |
| 2 |
#include <cppunit/TestCaller.h> |
| 3 |
#include <cppunit/TestCase.h> |
| 4 |
#include <cppunit/TestSuite.h> |
| 5 |
|
| 6 |
#include "FTGL/ftgl.h" |
| 7 |
|
| 8 |
|
| 9 |
class FTPointTest : public CppUnit::TestCase |
| 10 |
{ |
| 11 |
CPPUNIT_TEST_SUITE(FTPointTest); |
| 12 |
CPPUNIT_TEST(testConstructor); |
| 13 |
CPPUNIT_TEST(testOperatorEqual); |
| 14 |
CPPUNIT_TEST(testOperatorPlus); |
| 15 |
CPPUNIT_TEST(testOperatorMultiply); |
| 16 |
CPPUNIT_TEST(testOperatorNotEqual); |
| 17 |
CPPUNIT_TEST(testOperatorPlusEquals); |
| 18 |
CPPUNIT_TEST(testOperatorDouble); |
| 19 |
CPPUNIT_TEST(testSetters); |
| 20 |
CPPUNIT_TEST(testGetters); |
| 21 |
CPPUNIT_TEST_SUITE_END(); |
| 22 |
|
| 23 |
public: |
| 24 |
FTPointTest() : CppUnit::TestCase("FTPoint Test") |
| 25 |
{} |
| 26 |
|
| 27 |
FTPointTest(const std::string& name) : CppUnit::TestCase(name) {} |
| 28 |
|
| 29 |
void testConstructor() |
| 30 |
{ |
| 31 |
FTPoint point1; |
| 32 |
|
| 33 |
CPPUNIT_ASSERT(point1.X() == 0.0f); |
| 34 |
CPPUNIT_ASSERT(point1.Y() == 0.0f); |
| 35 |
CPPUNIT_ASSERT(point1.Z() == 0.0f); |
| 36 |
|
| 37 |
FTPoint point2(1.0f, 2.0f, 3.0f); |
| 38 |
|
| 39 |
CPPUNIT_ASSERT(point2.X() == 1.0f); |
| 40 |
CPPUNIT_ASSERT(point2.Y() == 2.0f); |
| 41 |
CPPUNIT_ASSERT(point2.Z() == 3.0f); |
| 42 |
|
| 43 |
FT_Vector ftVector; |
| 44 |
ftVector.x = 4; |
| 45 |
ftVector.y = 23; |
| 46 |
|
| 47 |
FTPoint point3(ftVector); |
| 48 |
|
| 49 |
CPPUNIT_ASSERT(point3.X() == 4.0f); |
| 50 |
CPPUNIT_ASSERT(point3.Y() == 23.0f); |
| 51 |
CPPUNIT_ASSERT(point3.Z() == 0.0f); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
void testOperatorEqual() |
| 56 |
{ |
| 57 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 58 |
FTPoint point2(1.0f, 2.0f, 3.0f); |
| 59 |
FTPoint point3(-1.0f, 2.3f, 23.0f); |
| 60 |
|
| 61 |
CPPUNIT_ASSERT(point1 == point1); |
| 62 |
CPPUNIT_ASSERT(point1 == point2); |
| 63 |
CPPUNIT_ASSERT(!(point1 == point3)); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
void testOperatorNotEqual() |
| 68 |
{ |
| 69 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 70 |
FTPoint point2(1.0f, 2.0f, 3.0f); |
| 71 |
FTPoint point3(-1.0f, 2.3f, 23.0f); |
| 72 |
|
| 73 |
CPPUNIT_ASSERT(!(point1 != point1)); |
| 74 |
CPPUNIT_ASSERT(!(point1 != point2)); |
| 75 |
CPPUNIT_ASSERT(point1 != point3); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
void testOperatorPlus() |
| 80 |
{ |
| 81 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 82 |
FTPoint point2(1.0f, 2.0f, 3.0f); |
| 83 |
|
| 84 |
FTPoint point3(2.0f, 4.0f, 6.0f); |
| 85 |
FTPoint point4 = point1 + point2; |
| 86 |
|
| 87 |
CPPUNIT_ASSERT(point4 == point3); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
void testOperatorMultiply() |
| 92 |
{ |
| 93 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 94 |
FTPoint point2(1.0f, 2.0f, 3.0f); |
| 95 |
|
| 96 |
FTPoint point3(2.0f, 4.0f, 6.0f); |
| 97 |
FTPoint point4 = point1 * 2.0; |
| 98 |
|
| 99 |
CPPUNIT_ASSERT(point4 == point3); |
| 100 |
|
| 101 |
point4 = 2.0 * point2; |
| 102 |
|
| 103 |
CPPUNIT_ASSERT(point4 == point3); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
void testOperatorPlusEquals() |
| 108 |
{ |
| 109 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 110 |
FTPoint point2(-2.0f, 21.0f, 0.0f); |
| 111 |
FTPoint point3(-1.0f, 23.0f, 3.0f); |
| 112 |
|
| 113 |
point1 += point2; |
| 114 |
|
| 115 |
CPPUNIT_ASSERT(point1 == point3); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
void testOperatorDouble() |
| 120 |
{ |
| 121 |
FTPoint point1(1.0f, 2.0f, 3.0f); |
| 122 |
|
| 123 |
const double* pointer = static_cast<const double*>(point1); |
| 124 |
CPPUNIT_ASSERT(pointer[0] == 1.0f); |
| 125 |
CPPUNIT_ASSERT(pointer[1] == 2.0f); |
| 126 |
CPPUNIT_ASSERT(pointer[2] == 3.0f); |
| 127 |
} |
| 128 |
|
| 129 |
void testSetters() |
| 130 |
{ |
| 131 |
FTPoint point; |
| 132 |
FTPoint point1(1, 2, 3); |
| 133 |
|
| 134 |
point.X(1); |
| 135 |
point.Y(2); |
| 136 |
point.Z(3); |
| 137 |
|
| 138 |
CPPUNIT_ASSERT(point == point1); |
| 139 |
} |
| 140 |
|
| 141 |
void testGetters() |
| 142 |
{ |
| 143 |
FTPoint point(1.0f, 2.0f, 3.0f); |
| 144 |
|
| 145 |
CPPUNIT_ASSERT(point.X() == 1.0); |
| 146 |
CPPUNIT_ASSERT(point.Y() == 2.0); |
| 147 |
CPPUNIT_ASSERT(point.Z() == 3.0); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
void setUp() |
| 152 |
{} |
| 153 |
|
| 154 |
|
| 155 |
void tearDown() |
| 156 |
{} |
| 157 |
|
| 158 |
private: |
| 159 |
}; |
| 160 |
|
| 161 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTPointTest); |
| 162 |
|