Commit 8d4c7414705d65d98ea584cfa1e7ae918dc3799c

sammy 2008-05-02T07:21:39

* Fix memory leaks in the font tests due to temporary variables not being deleted. * Add a few method calls to the C test program.

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()