Debian Codegraph @

test/FTFace-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
6 #include "Fontdefs.h"
7 #include "FTFace.h"
8
9
10 class FTFaceTest : public CppUnit::TestCase
11 {
12 CPPUNIT_TEST_SUITE(FTFaceTest);
13 CPPUNIT_TEST(testOpenFace);
14 CPPUNIT_TEST(testOpenFaceFromMemory);
15 CPPUNIT_TEST(testAttachFile);
16 CPPUNIT_TEST(testAttachMemoryData);
17 CPPUNIT_TEST(testGlyphCount);
18 CPPUNIT_TEST(testSetFontSize);
19 CPPUNIT_TEST(testGetCharmapList);
20 CPPUNIT_TEST(testKerning);
21 CPPUNIT_TEST_SUITE_END();
22
23 public:
24 FTFaceTest() : CppUnit::TestCase("FTFace test") {};
25 FTFaceTest(const std::string& name) : CppUnit::TestCase(name) {};
26
27
28 void testOpenFace()
29 {
30 FTFace face1(BAD_FONT_FILE);
31 CPPUNIT_ASSERT_EQUAL(face1.Error(), 0x06);
32
33 FTFace face2(GOOD_FONT_FILE);
34 CPPUNIT_ASSERT_EQUAL(face2.Error(), 0);
35 }
36
37
38 void testOpenFaceFromMemory()
39 {
40 FTFace face1((unsigned char*)100, 0);
41 CPPUNIT_ASSERT_EQUAL(face1.Error(), 0x02);
42
43 FTFace face2(HPGCalc_pfb.dataBytes, HPGCalc_pfb.numBytes);
44 CPPUNIT_ASSERT_EQUAL(face2.Error(), 0);
45 }
46
47
48 void testAttachFile()
49 {
50 CPPUNIT_ASSERT(!testFace->Attach(TYPE1_AFM_FILE));
51 CPPUNIT_ASSERT_EQUAL(testFace->Error(), 0x07); // unimplemented feature
52
53 FTFace test(TYPE1_FONT_FILE);
54 CPPUNIT_ASSERT_EQUAL(test.Error(), 0);
55
56 CPPUNIT_ASSERT(test.Attach(TYPE1_AFM_FILE));
57 CPPUNIT_ASSERT_EQUAL(test.Error(), 0);
58 }
59
60
61 void testAttachMemoryData()
62 {
63 CPPUNIT_ASSERT(!testFace->Attach((unsigned char*)100, 0));
64 CPPUNIT_ASSERT_EQUAL(testFace->Error(), 0x07); // unimplemented feature
65
66 FTFace test(TYPE1_FONT_FILE);
67 CPPUNIT_ASSERT_EQUAL(test.Error(), 0);
68
69 CPPUNIT_ASSERT(test.Attach(HPGCalc_afm.dataBytes, HPGCalc_afm.numBytes));
70 CPPUNIT_ASSERT_EQUAL(test.Error(), 0);
71 }
72
73
74 void testGlyphCount()
75 {
76 CPPUNIT_ASSERT_EQUAL(testFace->GlyphCount(), 14099U);
77 }
78
79
80 void testSetFontSize()
81 {
82 FTSize size = testFace->Size(FONT_POINT_SIZE, RESOLUTION);
83 CPPUNIT_ASSERT_EQUAL(testFace->Error(), 0);
84 }
85
86
87 void testGetCharmapList()
88 {
89 CPPUNIT_ASSERT_EQUAL(testFace->CharMapCount(), 2U);
90
91 FT_Encoding* charmapList = testFace->CharMapList();
92
93 CPPUNIT_ASSERT_EQUAL(charmapList[0], ft_encoding_unicode);
94 CPPUNIT_ASSERT_EQUAL(charmapList[1], ft_encoding_adobe_standard);
95 }
96
97
98 void testKerning()
99 {
100 FTFace test(ARIAL_FONT_FILE);
101 FTPoint kerningVector = test.KernAdvance('A', 'A');
102 CPPUNIT_ASSERT_EQUAL(kerningVector.X(), 0.);
103 CPPUNIT_ASSERT_EQUAL(kerningVector.Y(), 0.);
104 CPPUNIT_ASSERT_EQUAL(kerningVector.Z(), 0.);
105
106 kerningVector = test.KernAdvance(0x6FB3, 0x9580);
107 CPPUNIT_ASSERT_EQUAL(kerningVector.X(), 0.);
108 CPPUNIT_ASSERT_EQUAL(kerningVector.Y(), 0.);
109 CPPUNIT_ASSERT_EQUAL(kerningVector.Z(), 0.);
110 }
111
112
113 void setUp()
114 {
115 testFace = new FTFace(GOOD_FONT_FILE);
116 }
117
118
119 void tearDown()
120 {
121 delete testFace;
122 }
123
124 private:
125 FTFace* testFace;
126
127 };
128
129 CPPUNIT_TEST_SUITE_REGISTRATION(FTFaceTest);
130