Hash :
d228d390
Author :
Date :
2008-04-13T21:27:22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <assert.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "Fontdefs.h"
#include "FTBBox.h"
class FTBBoxTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE( FTBBoxTest);
CPPUNIT_TEST( testDefaultConstructor);
CPPUNIT_TEST( testGlyphConstructor);
CPPUNIT_TEST( testBitmapConstructor);
CPPUNIT_TEST( testMoveBBox);
CPPUNIT_TEST( testPlusEquals);
CPPUNIT_TEST( testSetDepth);
CPPUNIT_TEST_SUITE_END();
public:
FTBBoxTest() : CppUnit::TestCase( "FTBBox Test")
{}
FTBBoxTest( const std::string& name) : CppUnit::TestCase(name) {}
void testDefaultConstructor()
{
FTBBox boundingBox;
CPPUNIT_ASSERT( boundingBox.lowerX == 0.0f);
CPPUNIT_ASSERT( boundingBox.lowerY == 0.0f);
CPPUNIT_ASSERT( boundingBox.lowerZ == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperX == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperY == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperZ == 0.0f);
}
void testGlyphConstructor()
{
setUpFreetype( GOOD_FONT_FILE);
// FTBBox boundingBox2( (FT_GlyphSlot)(0));
// CPPUNIT_ASSERT( boundingBox2.lowerX == 0.0f);
// CPPUNIT_ASSERT( boundingBox2.lowerY == 0.0f);
// CPPUNIT_ASSERT( boundingBox2.lowerZ == 0.0f);
// CPPUNIT_ASSERT( boundingBox2.upperX == 0.0f);
// CPPUNIT_ASSERT( boundingBox2.upperY == 0.0f);
// CPPUNIT_ASSERT( boundingBox2.upperZ == 0.0f);
FTBBox boundingBox( face->glyph);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox.lowerX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox.lowerY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox.lowerZ, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox.upperX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox.upperY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox.upperZ, 0.01);
tearDownFreetype();
}
void testBitmapConstructor()
{
setUpFreetype( GOOD_FONT_FILE);
FT_Load_Char( face, CHARACTER_CODE_G, FT_LOAD_MONOCHROME);
CPPUNIT_ASSERT( ft_glyph_format_bitmap != face->glyph->format);
FTBBox boundingBox3( face->glyph);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox3.lowerX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox3.lowerY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox3.lowerZ, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox3.upperX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox3.upperY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox3.upperZ, 0.01);
}
void testMoveBBox()
{
FTBBox boundingBox;
FTPoint firstMove( 3.5f, 1.0f, -2.5f);
FTPoint secondMove( -3.5f, -1.0f, 2.5f);
boundingBox.Move( firstMove);
CPPUNIT_ASSERT( boundingBox.lowerX == 3.5f);
CPPUNIT_ASSERT( boundingBox.lowerY == 1.0f);
CPPUNIT_ASSERT( boundingBox.lowerZ == -2.5f);
CPPUNIT_ASSERT( boundingBox.upperX == 3.5f);
CPPUNIT_ASSERT( boundingBox.upperY == 1.0f);
CPPUNIT_ASSERT( boundingBox.upperZ == -2.5f);
boundingBox.Move( secondMove);
CPPUNIT_ASSERT( boundingBox.lowerX == 0.0f);
CPPUNIT_ASSERT( boundingBox.lowerY == 0.0f);
CPPUNIT_ASSERT( boundingBox.lowerZ == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperX == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperY == 0.0f);
CPPUNIT_ASSERT( boundingBox.upperZ == 0.0f);
}
void testPlusEquals()
{
setUpFreetype( GOOD_FONT_FILE);
FTBBox boundingBox1;
FTBBox boundingBox2( face->glyph);
boundingBox1 += boundingBox2;
CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox2.lowerX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox2.lowerY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.lowerZ, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox2.upperX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox2.upperY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.upperZ, 0.01);
float advance = 40;
boundingBox2.Move( FTPoint( advance, 0, 0));
boundingBox1 += boundingBox2;
CPPUNIT_ASSERT_DOUBLES_EQUAL( 42, boundingBox2.lowerX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox2.lowerY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.lowerZ, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 75, boundingBox2.upperX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox2.upperY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.upperZ, 0.01);
tearDownFreetype();
}
void testSetDepth()
{
setUpFreetype( GOOD_FONT_FILE);
FTBBox boundingBox( face->glyph);
boundingBox.SetDepth( 37.754);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox.lowerX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox.lowerY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox.lowerZ, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox.upperX, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox.upperY, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 37.754, boundingBox.upperZ, 0.01);
tearDownFreetype();
}
void setUp()
{}
void tearDown()
{}
private:
FT_Library library;
FT_Face face;
void setUpFreetype(const char *fontName)
{
FT_Error error = FT_Init_FreeType( &library);
CPPUNIT_ASSERT(!error);
error = FT_New_Face( library, fontName, 0, &face);
CPPUNIT_ASSERT(!error);
FT_Set_Char_Size( face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION);
error = FT_Load_Char( face, CHARACTER_CODE_G, FT_LOAD_RENDER);
CPPUNIT_ASSERT(!error);
}
void tearDownFreetype()
{
FT_Done_Face( face);
FT_Done_FreeType( library);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( FTBBoxTest);