Debian Codegraph @

test/FTPixmapGlyph-Test.cpp

raw
1 #include <iostream>
2
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCaller.h>
5 #include <cppunit/TestCase.h>
6 #include <cppunit/TestSuite.h>
7 #include <assert.h>
8
9 #include "Fontdefs.h"
10
11 #include "FTGL/ftgl.h"
12 #include "FTInternals.h"
13
14 #define GL_ASSERT() {GLenum sci_err; while ((sci_err = glGetError()) != GL_NO_ERROR) \
15 std::cerr << "OpenGL error: " << (char *)gluErrorString(sci_err) << " at " << __FILE__ <<":" << __LINE__ << std::endl; }
16
17
18 extern void buildGLContext();
19
20 class FTPixmapGlyphTest : public CppUnit::TestCase
21 {
22 CPPUNIT_TEST_SUITE(FTPixmapGlyphTest);
23 CPPUNIT_TEST(testConstructor);
24 CPPUNIT_TEST(testRender);
25 CPPUNIT_TEST_SUITE_END();
26
27 public:
28 FTPixmapGlyphTest() : CppUnit::TestCase("FTPixmapGlyph Test")
29 {
30 }
31
32 FTPixmapGlyphTest(const std::string& name) : CppUnit::TestCase(name) {}
33
34 ~FTPixmapGlyphTest()
35 {
36 }
37
38 void testConstructor()
39 {
40 setUpFreetype();
41
42 buildGLContext();
43
44 FTPixmapGlyph* PixmapGlyph = new FTPixmapGlyph(face->glyph);
45 CPPUNIT_ASSERT(PixmapGlyph->Error() == 0);
46
47 CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR);
48
49 tearDownFreetype();
50 }
51
52 void testRender()
53 {
54 setUpFreetype();
55
56 buildGLContext();
57
58 FTPixmapGlyph* pixmapGlyph = new FTPixmapGlyph(face->glyph);
59 CPPUNIT_ASSERT(pixmapGlyph->Error() == 0);
60 pixmapGlyph->Render(FTPoint(0, 0, 0), FTGL::RENDER_FRONT);
61
62 CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR);
63
64 tearDownFreetype();
65 }
66
67 void setUp()
68 {}
69
70 void tearDown()
71 {}
72
73 private:
74 FT_Library library;
75 FT_Face face;
76
77 void setUpFreetype()
78 {
79 FT_Error error = FT_Init_FreeType(&library);
80 assert(!error);
81 error = FT_New_Face(library, FONT_FILE, 0, &face);
82 assert(!error);
83
84 FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION);
85
86 error = FT_Load_Char(face, CHARACTER_CODE_A, FT_LOAD_DEFAULT);
87 assert(!error);
88 }
89
90 void tearDownFreetype()
91 {
92 FT_Done_Face(face);
93 FT_Done_FreeType(library);
94 }
95
96 };
97
98 CPPUNIT_TEST_SUITE_REGISTRATION(FTPixmapGlyphTest);
99