Debian Codegraph @

test/FTSize-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 <ft2build.h>
8 #include FT_FREETYPE_H
9 #include FT_GLYPH_H
10
11 #include "Fontdefs.h"
12 #include "FTSize.h"
13
14
15 class FTSizeTest : public CppUnit::TestCase
16 {
17 CPPUNIT_TEST_SUITE(FTSizeTest);
18 CPPUNIT_TEST(testConstructor);
19 CPPUNIT_TEST(testSetCharSize);
20 CPPUNIT_TEST_SUITE_END();
21
22 public:
23 FTSizeTest() : CppUnit::TestCase("FTSize Test")
24 {}
25
26 FTSizeTest(const std::string& name) : CppUnit::TestCase(name) {}
27
28 void testConstructor()
29 {
30 FTSize size;
31
32 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.CharSize(), 0.01);
33 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Ascender(), 0.01);
34 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Descender(), 0.01);
35
36 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Height(), 0.01);
37 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Width(), 0.01);
38
39 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Underline(), 0.01);
40
41 }
42
43
44 void testSetCharSize()
45 {
46 setUpFreetype();
47
48 FTSize size;
49
50 CPPUNIT_ASSERT(size.CharSize(&face, FONT_POINT_SIZE, RESOLUTION, RESOLUTION));
51 CPPUNIT_ASSERT(size.Error() == 0);
52
53 CPPUNIT_ASSERT_DOUBLES_EQUAL(72, size.CharSize(), 0.01);
54 CPPUNIT_ASSERT_DOUBLES_EQUAL(52, size.Ascender(), 0.01);
55 CPPUNIT_ASSERT_DOUBLES_EQUAL(-15, size.Descender(), 0.01);
56
57 CPPUNIT_ASSERT_DOUBLES_EQUAL(81.86, size.Height(), 0.01);
58 CPPUNIT_ASSERT_DOUBLES_EQUAL(76.32, size.Width(), 0.01);
59
60 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, size.Underline(), 0.01);
61
62 tearDownFreetype();
63 }
64
65
66 void setUp()
67 {}
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, GOOD_FONT_FILE, 0, &face);
82 assert(!error);
83 }
84
85 void tearDownFreetype()
86 {
87 FT_Done_Face(face);
88 FT_Done_FreeType(library);
89 }
90
91 };
92
93 CPPUNIT_TEST_SUITE_REGISTRATION(FTSizeTest);
94