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