Debian Codegraph @

test/FTTextureGlyph-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 FTTextureGlyphTest : public CppUnit::TestCase
15 {
16 CPPUNIT_TEST_SUITE(FTTextureGlyphTest);
17 CPPUNIT_TEST(testConstructor);
18 CPPUNIT_TEST(testRender);
19 CPPUNIT_TEST_SUITE_END();
20
21 public:
22 FTTextureGlyphTest() : CppUnit::TestCase("FTTextureGlyph Test")
23 {
24 }
25
26 FTTextureGlyphTest(const std::string& name) : CppUnit::TestCase(name) {}
27
28 ~FTTextureGlyphTest()
29 {
30 }
31
32 void testConstructor()
33 {
34 setUpFreetype();
35
36 buildGLContext();
37
38 GLuint textureID;
39 glGenTextures(1, &textureID);
40
41 char* texture[64*64];
42
43 glBindTexture(GL_TEXTURE_2D, textureID);
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
45 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
48
49 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 64, 64, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture);
50
51 FTTextureGlyph* textureGlyph = new FTTextureGlyph(face->glyph, textureID, 0, 0, 64, 64);
52
53 CPPUNIT_ASSERT(textureGlyph->Error() == 0);
54 CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR);
55
56 tearDownFreetype();
57 }
58
59 void testRender()
60 {
61 setUpFreetype();
62
63 buildGLContext();
64
65 GLuint textureID;
66 glGenTextures(1, &textureID);
67
68 char* texture[64*64];
69
70 glBindTexture(GL_TEXTURE_2D, textureID);
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
75
76 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 64, 64, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture);
77
78 FTTextureGlyph* textureGlyph = new FTTextureGlyph(face->glyph, textureID, 0, 0, 64, 64);
79 textureGlyph->Render(FTPoint(0, 0, 0), FTGL::RENDER_FRONT);
80 CPPUNIT_ASSERT(textureGlyph->Error() == 0);
81
82 CPPUNIT_ASSERT(glGetError() == GL_NO_ERROR);
83
84 tearDownFreetype();
85 }
86
87 void setUp()
88 {}
89
90 void tearDown()
91 {}
92
93 private:
94 FT_Library library;
95 FT_Face face;
96
97 void setUpFreetype()
98 {
99 FT_Error error = FT_Init_FreeType(&library);
100 assert(!error);
101 error = FT_New_Face(library, FONT_FILE, 0, &face);
102 assert(!error);
103
104 FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION);
105
106 error = FT_Load_Char(face, CHARACTER_CODE_A, FT_LOAD_DEFAULT);
107 assert(!error);
108 }
109
110 void tearDownFreetype()
111 {
112 FT_Done_Face(face);
113 FT_Done_FreeType(library);
114 }
115
116 };
117
118 CPPUNIT_TEST_SUITE_REGISTRATION(FTTextureGlyphTest);
119