Hash :
becb282a
Author :
Date :
2002-12-17T23:28:16
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
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include "Fontdefs.h"
#include "FTFace.h"
#include "FTGlyph.h"
#include "FTGlyphContainer.h"
class TestGlyph : public FTGlyph
{
public:
TestGlyph()
: FTGlyph(0)
{
advance = 50.0f;
}
virtual float Render( const FTPoint& pen){ return advance;}
};
class FTGlyphContainerTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE( FTGlyphContainerTest);
CPPUNIT_TEST( testAdd);
CPPUNIT_TEST( testAdvance);
CPPUNIT_TEST( testRender);
CPPUNIT_TEST_SUITE_END();
public:
FTGlyphContainerTest() : CppUnit::TestCase( "FTGlyphContainer Test")
{
face = new FTFace;
face->Open( GOOD_FONT_FILE);
face->Size( 72, 72);
face->CharMap( ft_encoding_unicode);
}
FTGlyphContainerTest( const std::string& name) : CppUnit::TestCase(name)
{
delete face;
}
void testAdd()
{
TestGlyph* glyph = new TestGlyph();
CPPUNIT_ASSERT( !glyphContainer->Add( glyph, TOO_MANY_GLYPHS));
CPPUNIT_ASSERT( glyphContainer->Add( glyph, FONT_INDEX_OF_A));
CPPUNIT_ASSERT( glyphContainer->Glyph( 'A') == glyph);
}
void testAdvance()
{
TestGlyph* glyph = new TestGlyph();
CPPUNIT_ASSERT( glyphContainer->Add( glyph, FONT_INDEX_OF_A));
float advance = glyphContainer->Advance( 'A', 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 50, advance, 0.01);
}
void testRender()
{
TestGlyph* glyph = new TestGlyph();
CPPUNIT_ASSERT( glyphContainer->Add( glyph, FONT_INDEX_OF_A));
FTPoint pen;
float advance = glyphContainer->Render( 'A', 0, pen).x;
CPPUNIT_ASSERT_DOUBLES_EQUAL( 50, advance, 0.01);
}
void setUp()
{
glyphContainer = new FTGlyphContainer( face);
}
void tearDown()
{
delete glyphContainer;
delete face;
}
private:
FTFace* face;
FTGlyphContainer* glyphContainer;
};
CPPUNIT_TEST_SUITE_REGISTRATION( FTGlyphContainerTest);