| 1 |
#include <cppunit/extensions/HelperMacros.h> |
| 2 |
#include <cppunit/TestCaller.h> |
| 3 |
#include <cppunit/TestCase.h> |
| 4 |
#include <cppunit/TestSuite.h> |
| 5 |
#include <assert.h> |
| 6 |
|
| 7 |
#include "Fontdefs.h" |
| 8 |
|
| 9 |
#include "FTGL/ftgl.h" |
| 10 |
#include "FTInternals.h" |
| 11 |
|
| 12 |
extern void buildGLContext(); |
| 13 |
|
| 14 |
class FTBitmapFontTest : public CppUnit::TestCase |
| 15 |
{ |
| 16 |
CPPUNIT_TEST_SUITE(FTBitmapFontTest); |
| 17 |
CPPUNIT_TEST(testConstructor); |
| 18 |
CPPUNIT_TEST(testRender); |
| 19 |
CPPUNIT_TEST(testPenPosition); |
| 20 |
CPPUNIT_TEST(testDisplayList); |
| 21 |
CPPUNIT_TEST_SUITE_END(); |
| 22 |
|
| 23 |
public: |
| 24 |
FTBitmapFontTest() : CppUnit::TestCase("FTBitmapFont Test") |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
FTBitmapFontTest(const std::string& name) : CppUnit::TestCase(name) {} |
| 29 |
|
| 30 |
~FTBitmapFontTest() |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
void testConstructor() |
| 35 |
{ |
| 36 |
buildGLContext(); |
| 37 |
|
| 38 |
FTBitmapFont* bitmapFont = new FTBitmapFont(FONT_FILE); |
| 39 |
CPPUNIT_ASSERT_EQUAL(bitmapFont->Error(), 0); |
| 40 |
|
| 41 |
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError()); |
| 42 |
delete bitmapFont; |
| 43 |
} |
| 44 |
|
| 45 |
void testRender() |
| 46 |
{ |
| 47 |
buildGLContext(); |
| 48 |
|
| 49 |
FTBitmapFont* bitmapFont = new FTBitmapFont(FONT_FILE); |
| 50 |
bitmapFont->Render(GOOD_ASCII_TEST_STRING); |
| 51 |
|
| 52 |
CPPUNIT_ASSERT_EQUAL(bitmapFont->Error(), 0); |
| 53 |
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError()); |
| 54 |
|
| 55 |
bitmapFont->FaceSize(18); |
| 56 |
bitmapFont->Render(GOOD_ASCII_TEST_STRING); |
| 57 |
|
| 58 |
CPPUNIT_ASSERT_EQUAL(bitmapFont->Error(), 0); |
| 59 |
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError()); |
| 60 |
delete bitmapFont; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
void testPenPosition() |
| 65 |
{ |
| 66 |
buildGLContext(); |
| 67 |
float rasterPosition[4]; |
| 68 |
|
| 69 |
glRasterPos2f(0.0f,0.0f); |
| 70 |
|
| 71 |
glGetFloatv(GL_CURRENT_RASTER_POSITION, rasterPosition); |
| 72 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rasterPosition[0], 0.01); |
| 73 |
|
| 74 |
FTBitmapFont* bitmapFont = new FTBitmapFont(FONT_FILE); |
| 75 |
bitmapFont->FaceSize(18); |
| 76 |
|
| 77 |
bitmapFont->Render(GOOD_ASCII_TEST_STRING); |
| 78 |
bitmapFont->Render(GOOD_ASCII_TEST_STRING); |
| 79 |
|
| 80 |
glGetFloatv(GL_CURRENT_RASTER_POSITION, rasterPosition); |
| 81 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(122, rasterPosition[0], 0.01); |
| 82 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rasterPosition[1], 0.01); |
| 83 |
delete bitmapFont; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
void testDisplayList() |
| 88 |
{ |
| 89 |
buildGLContext(); |
| 90 |
|
| 91 |
FTBitmapFont* bitmapFont = new FTBitmapFont(FONT_FILE); |
| 92 |
bitmapFont->FaceSize(18); |
| 93 |
|
| 94 |
int glList = glGenLists(1); |
| 95 |
glNewList(glList, GL_COMPILE); |
| 96 |
|
| 97 |
bitmapFont->Render(GOOD_ASCII_TEST_STRING); |
| 98 |
|
| 99 |
glEndList(); |
| 100 |
|
| 101 |
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError()); |
| 102 |
delete bitmapFont; |
| 103 |
} |
| 104 |
|
| 105 |
void setUp() |
| 106 |
{} |
| 107 |
|
| 108 |
void tearDown() |
| 109 |
{} |
| 110 |
|
| 111 |
private: |
| 112 |
}; |
| 113 |
|
| 114 |
CPPUNIT_TEST_SUITE_REGISTRATION(FTBitmapFontTest); |
| 115 |
|