| 1 |
#include <cppunit/extensions/HelperMacros.h> |
| 2 |
#include <cppunit/TestCaller.h> |
| 3 |
#include <cppunit/TestCase.h> |
| 4 |
#include <cppunit/TestSuite.h> |
| 5 |
|
| 6 |
#include "FTContour.h" |
| 7 |
|
| 8 |
// FT_Curve_Tag_On 1 |
| 9 |
// FT_Curve_Tag_Conic 0 |
| 10 |
// FT_Curve_Tag_Cubic 2 |
| 11 |
|
| 12 |
static FT_Vector shortLine[2] = |
| 13 |
{ |
| 14 |
{ 1, 1}, |
| 15 |
{ 2, 2}, |
| 16 |
}; |
| 17 |
|
| 18 |
static FT_Vector straightLinePoints[3] = |
| 19 |
{ |
| 20 |
{ 0, 0}, |
| 21 |
{ 6, 7}, |
| 22 |
{ 9, -2} |
| 23 |
}; |
| 24 |
|
| 25 |
static char straightLineTags[3] = |
| 26 |
{ |
| 27 |
FT_Curve_Tag_On, |
| 28 |
FT_Curve_Tag_On, |
| 29 |
FT_Curve_Tag_On |
| 30 |
}; |
| 31 |
|
| 32 |
static char brokenTags[3] = |
| 33 |
{ |
| 34 |
FT_Curve_Tag_Conic, |
| 35 |
69, |
| 36 |
FT_Curve_Tag_On |
| 37 |
}; |
| 38 |
|
| 39 |
static FT_Vector simpleConicPoints[3] = |
| 40 |
{ |
| 41 |
{ 0, 0}, |
| 42 |
{ 6, 7}, |
| 43 |
{ 9, -2} |
| 44 |
}; |
| 45 |
|
| 46 |
static FT_Vector brokenPoints[3] = |
| 47 |
{ |
| 48 |
{ 0, 0}, |
| 49 |
{ 0, 0}, |
| 50 |
{ 0, 0} |
| 51 |
}; |
| 52 |
|
| 53 |
static char simpleConicTags[3] = |
| 54 |
{ |
| 55 |
FT_Curve_Tag_Conic, |
| 56 |
FT_Curve_Tag_On, |
| 57 |
FT_Curve_Tag_On |
| 58 |
}; |
| 59 |
|
| 60 |
static FT_Vector doubleConicPoints[4] = |
| 61 |
{ |
| 62 |
{ 0, 0}, |
| 63 |
{ 6, 7}, |
| 64 |
{ 9, -2}, |
| 65 |
{ 4, 0} |
| 66 |
}; |
| 67 |
|
| 68 |
static char doubleConicTags[4] = |
| 69 |
{ |
| 70 |
FT_Curve_Tag_On, |
| 71 |
FT_Curve_Tag_On, |
| 72 |
FT_Curve_Tag_Conic, |
| 73 |
FT_Curve_Tag_Conic |
| 74 |
}; |
| 75 |
|
| 76 |
static FT_Vector cubicPoints[4] = |
| 77 |
{ |
| 78 |
{ 0, 0}, |
| 79 |
{ 6, 7}, |
| 80 |
{ 9, -2}, |
| 81 |
{ 4, 0} |
| 82 |
}; |
| 83 |
|
| 84 |
static char cubicTags[4] = |
| 85 |
{ |
| 86 |
FT_Curve_Tag_On, |
| 87 |
FT_Curve_Tag_On, |
| 88 |
FT_Curve_Tag_Cubic, |
| 89 |
FT_Curve_Tag_Cubic |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
// ARIAl 'd' |
| 94 |
static FT_Vector compositePoints[18] = |
| 95 |
{ |
| 96 |
{ 1856, 0 }, |
| 97 |
{ 1856, 279 }, |
| 98 |
{ 1625, -64 }, |
| 99 |
{ 1175, -64 }, |
| 100 |
{ 884, -64 }, |
| 101 |
{ 396, 251 }, |
| 102 |
{ 128, 815 }, |
| 103 |
{ 128, 1182 }, |
| 104 |
{ 128, 1539 }, |
| 105 |
{ 370, 2121 }, |
| 106 |
{ 855, 2432 }, |
| 107 |
{ 1156, 2432 }, |
| 108 |
{ 1375, 2432 }, |
| 109 |
{ 1718, 2257 }, |
| 110 |
{ 1826, 2118 }, |
| 111 |
{ 1826, 3264 }, |
| 112 |
{ 2240, 3264 }, |
| 113 |
{ 2240, 0 }, |
| 114 |
}; |
| 115 |
|
| 116 |
static char compositeTags[18] = |
| 117 |
{ |
| 118 |
FT_Curve_Tag_On, |
| 119 |
FT_Curve_Tag_On, |
| 120 |
FT_Curve_Tag_Conic, |
| 121 |
FT_Curve_Tag_On, |
| 122 |
FT_Curve_Tag_Conic, |
| 123 |
FT_Curve_Tag_Conic, |
| 124 |
FT_Curve_Tag_Conic, |
| 125 |
FT_Curve_Tag_On, |
| 126 |
FT_Curve_Tag_Conic, |
| 127 |
FT_Curve_Tag_Conic, |
| 128 |
FT_Curve_Tag_Conic, |
| 129 |
FT_Curve_Tag_On, |
| 130 |
FT_Curve_Tag_Conic, |
| 131 |
FT_Curve_Tag_Conic, |
| 132 |
FT_Curve_Tag_On, |
| 133 |
FT_Curve_Tag_On, |
| 134 |
FT_Curve_Tag_On, |
| 135 |
FT_Curve_Tag_On |
| 136 |
}; |
| 137 |
|
| 138 |
class FTContourTest : public CppUnit::TestCase |
| 139 |
{ |
| 140 |
CPPUNIT_TEST_SUITE(FTContourTest); |
| 141 |
CPPUNIT_TEST(testNullCurve); |
| 142 |
CPPUNIT_TEST(testBrokenCurve); |
| 143 |
CPPUNIT_TEST(testStraightLine); |
| 144 |
CPPUNIT_TEST(testConicCurve); |
| 145 |
CPPUNIT_TEST(testDoubleConicCurve); |
| 146 |
CPPUNIT_TEST(testCubicCurve); |
| 147 |
CPPUNIT_TEST(testCompositeCurve); |
| 148 |
CPPUNIT_TEST_SUITE_END(); |
| 149 |
|
| 150 |
public: |
| 151 |
FTContourTest() : CppUnit::TestCase("FTContour Test") |
| 152 |
{} |
| 153 |
|
| 154 |
FTContourTest(const std::string& name) : CppUnit::TestCase(name) |
| 155 |
{} |
| 156 |
|
| 157 |
void testNullCurve() |
| 158 |
{ |
| 159 |
FTContour contour(NULL, NULL, 0); |
| 160 |
CPPUNIT_ASSERT(contour.PointCount() == 0); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
void testBrokenCurve() |
| 165 |
{ |
| 166 |
FTContour contour(brokenPoints, simpleConicTags, 3); |
| 167 |
CPPUNIT_ASSERT(contour.PointCount() == 1); |
| 168 |
|
| 169 |
FTContour shortContour(shortLine, simpleConicTags, 2); |
| 170 |
CPPUNIT_ASSERT(shortContour.PointCount() == 6); |
| 171 |
|
| 172 |
FTContour reallyShortContour(shortLine, simpleConicTags, 1); |
| 173 |
CPPUNIT_ASSERT(reallyShortContour.PointCount() == 1); |
| 174 |
|
| 175 |
FTContour brokenTagtContour(shortLine, brokenTags, 3); |
| 176 |
CPPUNIT_ASSERT(brokenTagtContour.PointCount() == 7); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
void testStraightLine() |
| 181 |
{ |
| 182 |
FTContour contour(straightLinePoints, straightLineTags, 3); |
| 183 |
CPPUNIT_ASSERT(contour.PointCount() == 3); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
void testConicCurve() |
| 188 |
{ |
| 189 |
FTContour contour(simpleConicPoints, simpleConicTags, 3); |
| 190 |
CPPUNIT_ASSERT(contour.PointCount() == 7); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
void testDoubleConicCurve() |
| 195 |
{ |
| 196 |
FTContour contour(doubleConicPoints, doubleConicTags, 4); |
| 197 |
CPPUNIT_ASSERT(contour.PointCount() == 12); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
void testCubicCurve() |
| 202 |
{ |
| 203 |
FTContour contour(cubicPoints, cubicTags, 4); |
| 204 |
CPPUNIT_ASSERT(contour.PointCount() == 7); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
void testCompositeCurve() |
| 209 |
{ |
| 210 |
FTContour contour(compositePoints, compositeTags, 18); |
| 211 |
CPPUNIT_ASSERT(contour.PointCount() == 50); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
void setUp() |
| 216 |
{} |
| 217 |
|
| 218 |
|
| 219 |
void tearDown() |
| 220 |
{} |
| 221 |
|
| 222 |
private: |
| 223 |
}; |
| 224 |
|
| 225 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTContourTest); |
| 226 |
|