| 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 |
#include "FTInternals.h" |
| 11 |
|
| 12 |
extern void buildGLContext(); |
| 13 |
|
| 14 |
class FTBitmapGlyphTest : public CppUnit::TestCase |
| 15 |
{ |
| 16 |
CPPUNIT_TEST_SUITE(FTBitmapGlyphTest); |
| 17 |
CPPUNIT_TEST(testConstructor); |
| 18 |
CPPUNIT_TEST(testRender); |
| 19 |
CPPUNIT_TEST_SUITE_END(); |
| 20 |
|
| 21 |
public: |
| 22 |
FTBitmapGlyphTest() : CppUnit::TestCase("FTBitmapGlyph Test") |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
FTBitmapGlyphTest(const std::string& name) : CppUnit::TestCase(name) {} |
| 27 |
|
| 28 |
~FTBitmapGlyphTest() |
| 29 |
{ |
| 30 |
} |
| 31 |
|
| 32 |
void testConstructor() |
| 33 |
{ |
| 34 |
setUpFreetype(); |
| 35 |
|
| 36 |
buildGLContext(); |
| 37 |
|
| 38 |
FTBitmapGlyph* bitmapGlyph = new FTBitmapGlyph(face->glyph); |
| 39 |
CPPUNIT_ASSERT(bitmapGlyph->Error() == 0); |
| 40 |
|
| 41 |
CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR); |
| 42 |
|
| 43 |
tearDownFreetype(); |
| 44 |
} |
| 45 |
|
| 46 |
void testRender() |
| 47 |
{ |
| 48 |
setUpFreetype(); |
| 49 |
|
| 50 |
buildGLContext(); |
| 51 |
|
| 52 |
FTBitmapGlyph* bitmapGlyph = new FTBitmapGlyph(face->glyph); |
| 53 |
CPPUNIT_ASSERT(bitmapGlyph->Error() == 0); |
| 54 |
bitmapGlyph->Render(FTPoint(0, 0, 0), FTGL::RENDER_FRONT); |
| 55 |
|
| 56 |
CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR); |
| 57 |
|
| 58 |
tearDownFreetype(); |
| 59 |
} |
| 60 |
|
| 61 |
void setUp() |
| 62 |
{} |
| 63 |
|
| 64 |
void tearDown() |
| 65 |
{} |
| 66 |
|
| 67 |
private: |
| 68 |
FT_Library library; |
| 69 |
FT_Face face; |
| 70 |
|
| 71 |
void setUpFreetype() |
| 72 |
{ |
| 73 |
FT_Error error = FT_Init_FreeType(&library); |
| 74 |
assert(!error); |
| 75 |
error = FT_New_Face(library, FONT_FILE, 0, &face); |
| 76 |
assert(!error); |
| 77 |
|
| 78 |
FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION); |
| 79 |
|
| 80 |
error = FT_Load_Char(face, CHARACTER_CODE_A, FT_LOAD_DEFAULT); |
| 81 |
assert(!error); |
| 82 |
} |
| 83 |
|
| 84 |
void tearDownFreetype() |
| 85 |
{ |
| 86 |
FT_Done_Face(face); |
| 87 |
FT_Done_FreeType(library); |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTBitmapGlyphTest); |
| 92 |
|