Debian Codegraph @

test/FTOutlineGlyph-Test.cpp

raw
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 FTOutlineGlyphTest : public CppUnit::TestCase
15 {
16 CPPUNIT_TEST_SUITE(FTOutlineGlyphTest);
17 CPPUNIT_TEST(testConstructor);
18 CPPUNIT_TEST(testRender);
19 CPPUNIT_TEST_SUITE_END();
20
21 public:
22 FTOutlineGlyphTest() : CppUnit::TestCase("FTOutlineGlyph Test")
23 {
24 }
25
26 FTOutlineGlyphTest(const std::string& name) : CppUnit::TestCase(name) {}
27
28 ~FTOutlineGlyphTest()
29 {
30 }
31
32 void testConstructor()
33 {
34 setUpFreetype();
35
36 buildGLContext();
37
38 FTOutlineGlyph* outlineGlyph = new FTOutlineGlyph(face->glyph, 0,
39 true);
40 CPPUNIT_ASSERT(outlineGlyph->Error() == 0);
41 CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR);
42
43 tearDownFreetype();
44 }
45
46 void testRender()
47 {
48 setUpFreetype();
49
50 buildGLContext();
51
52 FTOutlineGlyph* outlineGlyph = new FTOutlineGlyph(face->glyph, 0,
53 true);
54 outlineGlyph->Render(FTPoint(0, 0, 0), FTGL::RENDER_FRONT);
55 CPPUNIT_ASSERT(outlineGlyph->Error() == 0);
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
92 CPPUNIT_TEST_SUITE_REGISTRATION(FTOutlineGlyphTest);
93