/Code/Angel/Libraries/FTGLES/ftgles/test/FTGlyph-Test.cpp

http://angel-engine.googlecode.com/ · C++ · 109 lines · 75 code · 34 blank · 0 comment · 2 complexity · 69c0a71024d866412175eba1fe1264d4 MD5 · raw file

  1. #include <assert.h>
  2. #include <cppunit/extensions/HelperMacros.h>
  3. #include <cppunit/TestCaller.h>
  4. #include <cppunit/TestCase.h>
  5. #include <cppunit/TestSuite.h>
  6. #include "Fontdefs.h"
  7. #include "FTGL/ftgl.h"
  8. class TestGlyph : public FTGlyph
  9. {
  10. public:
  11. TestGlyph(FT_GlyphSlot glyph)
  12. : FTGlyph(glyph),
  13. advance(FTPoint(Advance(), 0.0))
  14. {}
  15. const FTPoint& Render(const FTPoint& pen, int renderMode) { return advance; };
  16. private:
  17. FTPoint advance;
  18. };
  19. class FTGlyphTest : public CppUnit::TestCase
  20. {
  21. CPPUNIT_TEST_SUITE(FTGlyphTest);
  22. CPPUNIT_TEST(testBadConstructor);
  23. CPPUNIT_TEST(testGoodConstructor);
  24. CPPUNIT_TEST_SUITE_END();
  25. public:
  26. FTGlyphTest() : CppUnit::TestCase("FTGlyph Test")
  27. {}
  28. FTGlyphTest(const std::string& name) : CppUnit::TestCase(name) {}
  29. void testBadConstructor()
  30. {
  31. TestGlyph testGlyph(0);
  32. CPPUNIT_ASSERT(0.0 == testGlyph.Advance());
  33. CPPUNIT_ASSERT_DOUBLES_EQUAL(0, testGlyph.BBox().Upper().Y(), 0.01);
  34. CPPUNIT_ASSERT_EQUAL(testGlyph.Error(), 0);
  35. }
  36. void testGoodConstructor()
  37. {
  38. setUpFreetype(CHARACTER_CODE_A);
  39. TestGlyph testGlyph(face->glyph);
  40. float testPoint = 47.0;
  41. float nextPoint = testGlyph.Advance();
  42. CPPUNIT_ASSERT_DOUBLES_EQUAL(testPoint, nextPoint, 0.0001);
  43. CPPUNIT_ASSERT_DOUBLES_EQUAL(51.39, testGlyph.BBox().Upper().Y(), 0.01);
  44. CPPUNIT_ASSERT(testGlyph.Error() == 0);
  45. tearDownFreetype();
  46. }
  47. void setUp()
  48. {}
  49. void tearDown()
  50. {}
  51. private:
  52. FT_Library library;
  53. FT_Face face;
  54. void setUpFreetype(unsigned int characterIndex)
  55. {
  56. FT_Error error = FT_Init_FreeType(&library);
  57. assert(!error);
  58. error = FT_New_Face(library, ARIAL_FONT_FILE, 0, &face);
  59. assert(!error);
  60. loadGlyph(characterIndex);
  61. }
  62. void loadGlyph(unsigned int characterIndex)
  63. {
  64. long glyphIndex = FT_Get_Char_Index(face, characterIndex);
  65. FT_Set_Char_Size(face, 0L, FONT_POINT_SIZE * 64, RESOLUTION, RESOLUTION);
  66. FT_Error error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
  67. assert(!error);
  68. }
  69. void tearDownFreetype()
  70. {
  71. FT_Done_Face(face);
  72. FT_Done_FreeType(library);
  73. }
  74. };
  75. CPPUNIT_TEST_SUITE_REGISTRATION(FTGlyphTest);