| 1 |
#include <cppunit/extensions/HelperMacros.h> |
| 2 |
#include <cppunit/TestCaller.h> |
| 3 |
#include <cppunit/TestCase.h> |
| 4 |
#include <cppunit/TestSuite.h> |
| 5 |
#include <assert.h> |
| 6 |
|
| 7 |
#include "Fontdefs.h" |
| 8 |
|
| 9 |
#include "FTGL/ftgl.h" |
| 10 |
|
| 11 |
|
| 12 |
class FTBBoxTest : public CppUnit::TestCase |
| 13 |
{ |
| 14 |
CPPUNIT_TEST_SUITE(FTBBoxTest); |
| 15 |
CPPUNIT_TEST(testDefaultConstructor); |
| 16 |
CPPUNIT_TEST(testGlyphConstructor); |
| 17 |
CPPUNIT_TEST(testBitmapConstructor); |
| 18 |
CPPUNIT_TEST(testMoveBBox); |
| 19 |
CPPUNIT_TEST(testPlusEquals); |
| 20 |
CPPUNIT_TEST(testSetDepth); |
| 21 |
CPPUNIT_TEST_SUITE_END(); |
| 22 |
|
| 23 |
public: |
| 24 |
FTBBoxTest() : CppUnit::TestCase("FTBBox Test") |
| 25 |
{} |
| 26 |
|
| 27 |
FTBBoxTest(const std::string& name) : CppUnit::TestCase(name) {} |
| 28 |
|
| 29 |
void testDefaultConstructor() |
| 30 |
{ |
| 31 |
FTBBox boundingBox; |
| 32 |
|
| 33 |
CPPUNIT_ASSERT(boundingBox.Lower().X() == 0.0f); |
| 34 |
CPPUNIT_ASSERT(boundingBox.Lower().Y() == 0.0f); |
| 35 |
CPPUNIT_ASSERT(boundingBox.Lower().Z() == 0.0f); |
| 36 |
CPPUNIT_ASSERT(boundingBox.Upper().X() == 0.0f); |
| 37 |
CPPUNIT_ASSERT(boundingBox.Upper().Y() == 0.0f); |
| 38 |
CPPUNIT_ASSERT(boundingBox.Upper().Z() == 0.0f); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
void testGlyphConstructor() |
| 43 |
{ |
| 44 |
setUpFreetype(GOOD_FONT_FILE); |
| 45 |
|
| 46 |
// FTBBox boundingBox2((FT_GlyphSlot)(0)); |
| 47 |
|
| 48 |
// CPPUNIT_ASSERT(boundingBox2.Lower().X() == 0.0f); |
| 49 |
// CPPUNIT_ASSERT(boundingBox2.Lower().Y() == 0.0f); |
| 50 |
// CPPUNIT_ASSERT(boundingBox2.Lower().Z() == 0.0f); |
| 51 |
// CPPUNIT_ASSERT(boundingBox2.Upper().X() == 0.0f); |
| 52 |
// CPPUNIT_ASSERT(boundingBox2.Upper().Y() == 0.0f); |
| 53 |
// CPPUNIT_ASSERT(boundingBox2.Upper().Z() == 0.0f); |
| 54 |
|
| 55 |
FTBBox boundingBox(face->glyph); |
| 56 |
|
| 57 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(2, boundingBox.Lower().X(), 0.01); |
| 58 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, boundingBox.Lower().Y(), 0.01); |
| 59 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox.Lower().Z(), 0.01); |
| 60 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(35, boundingBox.Upper().X(), 0.01); |
| 61 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(38, boundingBox.Upper().Y(), 0.01); |
| 62 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox.Upper().Z(), 0.01); |
| 63 |
|
| 64 |
|
| 65 |
tearDownFreetype(); |
| 66 |
} |
| 67 |
|
| 68 |
void testBitmapConstructor() |
| 69 |
{ |
| 70 |
setUpFreetype(GOOD_FONT_FILE); |
| 71 |
|
| 72 |
FT_Load_Char(face, CHARACTER_CODE_G, FT_LOAD_MONOCHROME); |
| 73 |
|
| 74 |
CPPUNIT_ASSERT(ft_glyph_format_bitmap != face->glyph->format); |
| 75 |
|
| 76 |
FTBBox boundingBox3(face->glyph); |
| 77 |
|
| 78 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(2, boundingBox3.Lower().X(), 0.01); |
| 79 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, boundingBox3.Lower().Y(), 0.01); |
| 80 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox3.Lower().Z(), 0.01); |
| 81 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(35, boundingBox3.Upper().X(), 0.01); |
| 82 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(38, boundingBox3.Upper().Y(), 0.01); |
| 83 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox3.Upper().Z(), 0.01); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
void testMoveBBox() |
| 88 |
{ |
| 89 |
FTBBox boundingBox; |
| 90 |
FTPoint firstMove(3.5f, 1.0f, -2.5f); |
| 91 |
FTPoint secondMove(-3.5f, -1.0f, 2.5f); |
| 92 |
|
| 93 |
boundingBox += firstMove; |
| 94 |
|
| 95 |
CPPUNIT_ASSERT(boundingBox.Lower().X() == 3.5f); |
| 96 |
CPPUNIT_ASSERT(boundingBox.Lower().Y() == 1.0f); |
| 97 |
CPPUNIT_ASSERT(boundingBox.Lower().Z() == -2.5f); |
| 98 |
CPPUNIT_ASSERT(boundingBox.Upper().X() == 3.5f); |
| 99 |
CPPUNIT_ASSERT(boundingBox.Upper().Y() == 1.0f); |
| 100 |
CPPUNIT_ASSERT(boundingBox.Upper().Z() == -2.5f); |
| 101 |
|
| 102 |
boundingBox += secondMove; |
| 103 |
|
| 104 |
CPPUNIT_ASSERT(boundingBox.Lower().X() == 0.0f); |
| 105 |
CPPUNIT_ASSERT(boundingBox.Lower().Y() == 0.0f); |
| 106 |
CPPUNIT_ASSERT(boundingBox.Lower().Z() == 0.0f); |
| 107 |
CPPUNIT_ASSERT(boundingBox.Upper().X() == 0.0f); |
| 108 |
CPPUNIT_ASSERT(boundingBox.Upper().Y() == 0.0f); |
| 109 |
CPPUNIT_ASSERT(boundingBox.Upper().Z() == 0.0f); |
| 110 |
} |
| 111 |
|
| 112 |
void testPlusEquals() |
| 113 |
{ |
| 114 |
setUpFreetype(GOOD_FONT_FILE); |
| 115 |
|
| 116 |
FTBBox boundingBox1; |
| 117 |
FTBBox boundingBox2(face->glyph); |
| 118 |
|
| 119 |
boundingBox1 |= boundingBox2; |
| 120 |
|
| 121 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(2, boundingBox2.Lower().X(), 0.01); |
| 122 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, boundingBox2.Lower().Y(), 0.01); |
| 123 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox2.Lower().Z(), 0.01); |
| 124 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(35, boundingBox2.Upper().X(), 0.01); |
| 125 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(38, boundingBox2.Upper().Y(), 0.01); |
| 126 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox2.Upper().Z(), 0.01); |
| 127 |
|
| 128 |
float advance = 40; |
| 129 |
|
| 130 |
boundingBox2 += FTPoint(advance, 0, 0); |
| 131 |
boundingBox1 |= boundingBox2; |
| 132 |
|
| 133 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(42, boundingBox2.Lower().X(), 0.01); |
| 134 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, boundingBox2.Lower().Y(), 0.01); |
| 135 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox2.Lower().Z(), 0.01); |
| 136 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(75, boundingBox2.Upper().X(), 0.01); |
| 137 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(38, boundingBox2.Upper().Y(), 0.01); |
| 138 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox2.Upper().Z(), 0.01); |
| 139 |
|
| 140 |
tearDownFreetype(); |
| 141 |
} |
| 142 |
|
| 143 |
void testSetDepth() |
| 144 |
{ |
| 145 |
setUpFreetype(GOOD_FONT_FILE); |
| 146 |
|
| 147 |
FTBBox boundingBox(face->glyph); |
| 148 |
|
| 149 |
boundingBox.SetDepth(37.754); |
| 150 |
|
| 151 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(2, boundingBox.Lower().X(), 0.01); |
| 152 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, boundingBox.Lower().Y(), 0.01); |
| 153 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, boundingBox.Lower().Z(), 0.01); |
| 154 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(35, boundingBox.Upper().X(), 0.01); |
| 155 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(38, boundingBox.Upper().Y(), 0.01); |
| 156 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(37.754, boundingBox.Upper().Z(), 0.01); |
| 157 |
|
| 158 |
tearDownFreetype(); |
| 159 |
} |
| 160 |
|
| 161 |
void setUp() |
| 162 |
{} |
| 163 |
|
| 164 |
|
| 165 |
void tearDown() |
| 166 |
{} |
| 167 |
|
| 168 |
private: |
| 169 |
FT_Library library; |
| 170 |
FT_Face face; |
| 171 |
|
| 172 |
void setUpFreetype(const char *fontName) |
| 173 |
{ |
| 174 |
FT_Error error = FT_Init_FreeType(&library); |
| 175 |
CPPUNIT_ASSERT(!error); |
| 176 |
error = FT_New_Face(library, fontName, 0, &face); |
| 177 |
CPPUNIT_ASSERT(!error); |
| 178 |
|
| 179 |
FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION); |
| 180 |
|
| 181 |
error = FT_Load_Char(face, CHARACTER_CODE_G, FT_LOAD_RENDER); |
| 182 |
CPPUNIT_ASSERT(!error); |
| 183 |
} |
| 184 |
|
| 185 |
void tearDownFreetype() |
| 186 |
{ |
| 187 |
FT_Done_Face(face); |
| 188 |
FT_Done_FreeType(library); |
| 189 |
} |
| 190 |
|
| 191 |
}; |
| 192 |
|
| 193 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTBBoxTest); |
| 194 |
|