* Fix memory leaks in the font tests due to temporary variables not being deleted. * Add a few method calls to the C test program.
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
diff --git a/test/CTest.c b/test/CTest.c
index 7c96f8a..883126e 100644
--- a/test/CTest.c
+++ b/test/CTest.c
@@ -1,19 +1,55 @@
/* Small C bindings test program */
+#include "config.h"
+
+#if defined HAVE_GL_GLUT_H
+# include <GL/glut.h>
+#elif defined HAVE_GLUT_GLUT_H
+# include <GLUT/glut.h>
+#else
+# error GLUT headers not present
+#endif
#include <FTGL/ftgl.h>
+#define ALLOC(ctor, var, arg) \
+ var = ctor(arg); \
+ if(var == NULL) \
+ return 2
+
int main(int argc, char *argv[])
{
- FTGLfont *f;
+ FTGLfont *f[6];
+ char *glutchar = NULL;
+ int glutint = 0;
+ int i;
if(argc < 2)
return 1;
- f = ftglCreateBitmapFont(argv[1]);
- if(f == NULL)
- return 2;
+ glutInit(&glutint, &glutchar);
+ glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(150, 150);
+ glutCreateWindow("FTGL C test");
+
+ ALLOC(ftglCreateBitmapFont, f[0], argv[1]);
+ ALLOC(ftglCreateExtrudeFont, f[1], argv[1]);
+ ALLOC(ftglCreateOutlineFont, f[2], argv[1]);
+ ALLOC(ftglCreatePixmapFont, f[3], argv[1]);
+ ALLOC(ftglCreatePolygonFont, f[4], argv[1]);
+ ALLOC(ftglCreateTextureFont, f[5], argv[1]);
+
+ for(i = 0; i < 6; i++)
+ ftglRender(f[i], "Hello world");
+
+ for(i = 0; i < 6; i++)
+ ftglSetFaceSize(f[i], 37);
+
+ for(i = 0; i < 6; i++)
+ ftglRender(f[i], "Hello world");
- ftglDestroyFont(f);
+ for(i = 0; i < 6; i++)
+ ftglDestroyFont(f[i]);
return 0;
}
diff --git a/test/FTBitmapFont-Test.cpp b/test/FTBitmapFont-Test.cpp
index 7adbcd5..a3a2f71 100644
--- a/test/FTBitmapFont-Test.cpp
+++ b/test/FTBitmapFont-Test.cpp
@@ -39,6 +39,7 @@ class FTBitmapFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(bitmapFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete bitmapFont;
}
void testRender()
@@ -56,6 +57,7 @@ class FTBitmapFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(bitmapFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete bitmapFont;
}
@@ -78,6 +80,7 @@ class FTBitmapFontTest : public CppUnit::TestCase
glGetFloatv(GL_CURRENT_RASTER_POSITION, rasterPosition);
CPPUNIT_ASSERT_DOUBLES_EQUAL(122, rasterPosition[0], 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rasterPosition[1], 0.01);
+ delete bitmapFont;
}
@@ -96,6 +99,7 @@ class FTBitmapFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete bitmapFont;
}
void setUp()
diff --git a/test/FTExtrudeFont-Test.cpp b/test/FTExtrudeFont-Test.cpp
index 913e097..7928f23 100644
--- a/test/FTExtrudeFont-Test.cpp
+++ b/test/FTExtrudeFont-Test.cpp
@@ -39,6 +39,7 @@ class FTExtrudeFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(extrudedFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete extrudedFont;
}
void testRender()
@@ -56,6 +57,7 @@ class FTExtrudeFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(extrudedFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete extrudedFont;
}
void testBadDisplayList()
@@ -73,6 +75,7 @@ class FTExtrudeFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL((int)glGetError(), GL_INVALID_OPERATION);
+ delete extrudedFont;
}
void testGoodDisplayList()
@@ -91,6 +94,7 @@ class FTExtrudeFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete extrudedFont;
}
void setUp()
diff --git a/test/FTOutlineFont-Test.cpp b/test/FTOutlineFont-Test.cpp
index 69b7baa..08ba406 100644
--- a/test/FTOutlineFont-Test.cpp
+++ b/test/FTOutlineFont-Test.cpp
@@ -39,6 +39,7 @@ class FTOutlineFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(outlineFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete outlineFont;
}
void testRender()
@@ -56,6 +57,7 @@ class FTOutlineFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(outlineFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete outlineFont;
}
void testBadDisplayList()
@@ -73,6 +75,7 @@ class FTOutlineFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL((int)glGetError(), GL_INVALID_OPERATION);
+ delete outlineFont;
}
void testGoodDisplayList()
@@ -91,6 +94,7 @@ class FTOutlineFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete outlineFont;
}
void setUp()
diff --git a/test/FTPixmapFont-Test.cpp b/test/FTPixmapFont-Test.cpp
index 0ea48c5..4102a7d 100644
--- a/test/FTPixmapFont-Test.cpp
+++ b/test/FTPixmapFont-Test.cpp
@@ -38,6 +38,7 @@ class FTPixmapFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(pixmapFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete pixmapFont;
}
void testRender()
@@ -55,6 +56,7 @@ class FTPixmapFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(pixmapFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete pixmapFont;
}
void testDisplayList()
@@ -72,6 +74,7 @@ class FTPixmapFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete pixmapFont;
}
void setUp()
diff --git a/test/FTPolygonFont-Test.cpp b/test/FTPolygonFont-Test.cpp
index 4110a85..b8c4474 100644
--- a/test/FTPolygonFont-Test.cpp
+++ b/test/FTPolygonFont-Test.cpp
@@ -39,6 +39,7 @@ class FTPolygonFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(polygonFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete polygonFont;
}
void testRender()
@@ -57,6 +58,7 @@ class FTPolygonFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(polygonFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete polygonFont;
}
void testBadDisplayList()
@@ -74,6 +76,7 @@ class FTPolygonFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL((int)glGetError(), GL_INVALID_OPERATION);
+ delete polygonFont;
}
void testGoodDisplayList()
@@ -92,6 +95,7 @@ class FTPolygonFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete polygonFont;
}
void setUp()
diff --git a/test/FTTextureFont-Test.cpp b/test/FTTextureFont-Test.cpp
index 2c4e904..81bacff 100644
--- a/test/FTTextureFont-Test.cpp
+++ b/test/FTTextureFont-Test.cpp
@@ -38,6 +38,7 @@ class FTTextureFontTest : public CppUnit::TestCase
FTTextureFont* textureFont = new FTTextureFont(FONT_FILE);
CPPUNIT_ASSERT_EQUAL(textureFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete textureFont;
}
void testResizeBug()
@@ -54,6 +55,7 @@ class FTTextureFontTest : public CppUnit::TestCase
textureFont->Render("second");
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete textureFont;
}
void testRender()
@@ -71,6 +73,7 @@ class FTTextureFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(textureFont->Error(), 0);
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete textureFont;
}
void testDisplayList()
@@ -88,6 +91,7 @@ class FTTextureFontTest : public CppUnit::TestCase
glEndList();
CPPUNIT_ASSERT_EQUAL(GL_NO_ERROR, (int)glGetError());
+ delete textureFont;
}
void setUp()