| 1 |
#include <assert.h> |
| 2 |
|
| 3 |
#include <cppunit/extensions/HelperMacros.h> |
| 4 |
#include <cppunit/TestCaller.h> |
| 5 |
#include <cppunit/TestCase.h> |
| 6 |
#include <cppunit/TestSuite.h> |
| 7 |
|
| 8 |
#include "Fontdefs.h" |
| 9 |
|
| 10 |
#include "FTGL/ftgl.h" |
| 11 |
|
| 12 |
class TestGlyph : public FTGlyph |
| 13 |
{ |
| 14 |
public: |
| 15 |
TestGlyph(FT_GlyphSlot glyph) |
| 16 |
: FTGlyph(glyph), |
| 17 |
advance(FTPoint(Advance(), 0.0)) |
| 18 |
{} |
| 19 |
|
| 20 |
const FTPoint& Render(const FTPoint& pen, int renderMode) { return advance; }; |
| 21 |
|
| 22 |
private: |
| 23 |
FTPoint advance; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
class FTGlyphTest : public CppUnit::TestCase |
| 28 |
{ |
| 29 |
CPPUNIT_TEST_SUITE(FTGlyphTest); |
| 30 |
CPPUNIT_TEST(testBadConstructor); |
| 31 |
CPPUNIT_TEST(testGoodConstructor); |
| 32 |
CPPUNIT_TEST_SUITE_END(); |
| 33 |
|
| 34 |
public: |
| 35 |
FTGlyphTest() : CppUnit::TestCase("FTGlyph Test") |
| 36 |
{} |
| 37 |
|
| 38 |
FTGlyphTest(const std::string& name) : CppUnit::TestCase(name) {} |
| 39 |
|
| 40 |
void testBadConstructor() |
| 41 |
{ |
| 42 |
TestGlyph testGlyph(0); |
| 43 |
|
| 44 |
CPPUNIT_ASSERT(0.0 == testGlyph.Advance()); |
| 45 |
|
| 46 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, testGlyph.BBox().Upper().Y(), 0.01); |
| 47 |
|
| 48 |
CPPUNIT_ASSERT_EQUAL(testGlyph.Error(), 0); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
void testGoodConstructor() |
| 53 |
{ |
| 54 |
setUpFreetype(CHARACTER_CODE_A); |
| 55 |
TestGlyph testGlyph(face->glyph); |
| 56 |
|
| 57 |
float testPoint = 47.0; |
| 58 |
float nextPoint = testGlyph.Advance(); |
| 59 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(testPoint, nextPoint, 0.0001); |
| 60 |
|
| 61 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(51.39, testGlyph.BBox().Upper().Y(), 0.01); |
| 62 |
|
| 63 |
CPPUNIT_ASSERT(testGlyph.Error() == 0); |
| 64 |
|
| 65 |
tearDownFreetype(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
void setUp() |
| 70 |
{} |
| 71 |
|
| 72 |
|
| 73 |
void tearDown() |
| 74 |
{} |
| 75 |
|
| 76 |
private: |
| 77 |
FT_Library library; |
| 78 |
FT_Face face; |
| 79 |
|
| 80 |
void setUpFreetype(unsigned int characterIndex) |
| 81 |
{ |
| 82 |
FT_Error error = FT_Init_FreeType(&library); |
| 83 |
assert(!error); |
| 84 |
error = FT_New_Face(library, ARIAL_FONT_FILE, 0, &face); |
| 85 |
assert(!error); |
| 86 |
|
| 87 |
loadGlyph(characterIndex); |
| 88 |
} |
| 89 |
|
| 90 |
void loadGlyph(unsigned int characterIndex) |
| 91 |
{ |
| 92 |
long glyphIndex = FT_Get_Char_Index(face, characterIndex); |
| 93 |
|
| 94 |
FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION); |
| 95 |
|
| 96 |
FT_Error error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT); |
| 97 |
assert(!error); |
| 98 |
} |
| 99 |
|
| 100 |
void tearDownFreetype() |
| 101 |
{ |
| 102 |
FT_Done_Face(face); |
| 103 |
FT_Done_FreeType(library); |
| 104 |
} |
| 105 |
|
| 106 |
}; |
| 107 |
|
| 108 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTGlyphTest); |
| 109 |
|