summaryrefslogtreecommitdiff
path: root/test/unittests.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'test/unittests.cxx')
-rw-r--r--test/unittests.cxx208
1 files changed, 87 insertions, 121 deletions
diff --git a/test/unittests.cxx b/test/unittests.cxx
index b81a007d1..47261241c 100644
--- a/test/unittests.cxx
+++ b/test/unittests.cxx
@@ -21,6 +21,8 @@
// v1.0 - Submit for svn
// v1.1 - Matthias seperated all tests into multiple source files for hopefully easier handling
+#include "unittests.h"
+
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Hold_Browser.H>
@@ -31,129 +33,90 @@
#include <FL/fl_string_functions.h> // fl_strdup()
#include <stdlib.h> // malloc, free
-// WINDOW/WIDGET SIZES
-#define MAINWIN_W 700 // main window w()
-#define MAINWIN_H 400 // main window h()
-#define BROWSER_X 10 // browser x()
-#define BROWSER_Y 25 // browser y()
-#define BROWSER_W 150 // browser w()
-#define BROWSER_H MAINWIN_H-35 // browser h()
-#define TESTAREA_X (BROWSER_W + 20) // test area x()
-#define TESTAREA_Y 25 // test area y()
-#define TESTAREA_W (MAINWIN_W - BROWSER_W - 30) // test area w()
-#define TESTAREA_H BROWSER_H // test area h()
+class MainWindow *mainwin = 0;
+class Fl_Hold_Browser *browser = 0;
+
+UnitTest::UnitTest(int index, const char *label, Fl_Widget* (*create)()) :
+ fWidget(0L)
+{
+ fLabel = fl_strdup(label);
+ fCreate = create;
+ add(index, this);
+}
-typedef void (*UnitTestCallback)(const char*,Fl_Group*);
+UnitTest::~UnitTest() {
+ delete fWidget;
+ free(fLabel);
+}
-class MainWindow *mainwin = 0;
-Fl_Hold_Browser *browser = 0;
-
-// This class helps to automagically register a new test with the unittest app.
-// Please see the examples on how this is used.
-class UnitTest {
-public:
- UnitTest(const char *label, Fl_Widget* (*create)()) :
- fWidget(0L)
- {
- fLabel = fl_strdup(label);
- fCreate = create;
- add(this);
- }
- ~UnitTest() {
- delete fWidget;
- free(fLabel);
- }
- const char *label() {
- return fLabel;
- }
- void create() {
- fWidget = fCreate();
- if (fWidget) fWidget->hide();
- }
- void show() {
- if (fWidget) fWidget->show();
- }
- void hide() {
- if (fWidget) fWidget->hide();
- }
- static int numTest() { return nTest; }
- static UnitTest *test(int i) { return fTest[i]; }
-private:
- char *fLabel;
- Fl_Widget *(*fCreate)();
- Fl_Widget *fWidget;
-
- static void add(UnitTest *t) {
- fTest[nTest] = t;
- nTest++;
- }
- static int nTest;
- static UnitTest *fTest[];
-};
+const char *UnitTest::label() {
+ return fLabel;
+}
+
+void UnitTest::create() {
+ fWidget = fCreate();
+ if (fWidget) fWidget->hide();
+}
+
+void UnitTest::show() {
+ if (fWidget) fWidget->show();
+}
+
+void UnitTest::hide() {
+ if (fWidget) fWidget->hide();
+}
+
+void UnitTest::add(int index, UnitTest *t) {
+ fTest[index] = t;
+ if (index>=nTest)
+ nTest = index+1;
+}
int UnitTest::nTest = 0;
-UnitTest *UnitTest::fTest[200];
-
-
-// The main window needs an additional drawing feature in order to support
-// the viewport alignment test.
-class MainWindow : public Fl_Double_Window {
-public:
- MainWindow(int w, int h, const char *l=0L) :
- Fl_Double_Window(w, h, l),
- fTestAlignment(0)
- { }
- // this code is used by the viewport alignment test
- void drawAlignmentIndicators() {
- const int sze = 16;
- // top left corner
- fl_color(FL_GREEN); fl_yxline(0, sze, 0, sze);
- fl_color(FL_RED); fl_yxline(-1, sze, -1, sze);
- fl_color(FL_WHITE); fl_rectf(3, 3, sze-2, sze-2);
- fl_color(FL_BLACK); fl_rect(3, 3, sze-2, sze-2);
- // bottom left corner
- fl_color(FL_GREEN); fl_yxline(0, h()-sze-1, h()-1, sze);
- fl_color(FL_RED); fl_yxline(-1, h()-sze-1, h(), sze);
- fl_color(FL_WHITE); fl_rectf(3, h()-sze-1, sze-2, sze-2);
- fl_color(FL_BLACK); fl_rect(3, h()-sze-1, sze-2, sze-2);
- // bottom right corner
- fl_color(FL_GREEN); fl_yxline(w()-1, h()-sze-1, h()-1, w()-sze-1);
- fl_color(FL_RED); fl_yxline(w(), h()-sze-1, h(), w()-sze-1);
- fl_color(FL_WHITE); fl_rectf(w()-sze-1, h()-sze-1, sze-2, sze-2);
- fl_color(FL_BLACK); fl_rect(w()-sze-1, h()-sze-1, sze-2, sze-2);
- // top right corner
- fl_color(FL_GREEN); fl_yxline(w()-1, sze, 0, w()-sze-1);
- fl_color(FL_RED); fl_yxline(w(), sze, -1, w()-sze-1);
- fl_color(FL_WHITE); fl_rectf(w()-sze-1, 3, sze-2, sze-2);
- fl_color(FL_BLACK); fl_rect(w()-sze-1, 3, sze-2, sze-2);
- }
- void draw() {
- Fl_Double_Window::draw();
- if (fTestAlignment) {
- drawAlignmentIndicators();
- }
- }
- void testAlignment(int v) {
- fTestAlignment = v;
- redraw();
+UnitTest *UnitTest::fTest[200] = { 0 };
+
+MainWindow::MainWindow(int w, int h, const char *l) :
+Fl_Double_Window(w, h, l),
+fTestAlignment(0)
+{ }
+
+void MainWindow::drawAlignmentIndicators() {
+ const int sze = 16;
+ // top left corner
+ fl_color(FL_GREEN); fl_yxline(0, sze, 0, sze);
+ fl_color(FL_RED); fl_yxline(-1, sze, -1, sze);
+ fl_color(FL_WHITE); fl_rectf(3, 3, sze-2, sze-2);
+ fl_color(FL_BLACK); fl_rect(3, 3, sze-2, sze-2);
+ // bottom left corner
+ fl_color(FL_GREEN); fl_yxline(0, h()-sze-1, h()-1, sze);
+ fl_color(FL_RED); fl_yxline(-1, h()-sze-1, h(), sze);
+ fl_color(FL_WHITE); fl_rectf(3, h()-sze-1, sze-2, sze-2);
+ fl_color(FL_BLACK); fl_rect(3, h()-sze-1, sze-2, sze-2);
+ // bottom right corner
+ fl_color(FL_GREEN); fl_yxline(w()-1, h()-sze-1, h()-1, w()-sze-1);
+ fl_color(FL_RED); fl_yxline(w(), h()-sze-1, h(), w()-sze-1);
+ fl_color(FL_WHITE); fl_rectf(w()-sze-1, h()-sze-1, sze-2, sze-2);
+ fl_color(FL_BLACK); fl_rect(w()-sze-1, h()-sze-1, sze-2, sze-2);
+ // top right corner
+ fl_color(FL_GREEN); fl_yxline(w()-1, sze, 0, w()-sze-1);
+ fl_color(FL_RED); fl_yxline(w(), sze, -1, w()-sze-1);
+ fl_color(FL_WHITE); fl_rectf(w()-sze-1, 3, sze-2, sze-2);
+ fl_color(FL_BLACK); fl_rect(w()-sze-1, 3, sze-2, sze-2);
+}
+
+void MainWindow::draw() {
+ Fl_Double_Window::draw();
+ if (fTestAlignment) {
+ drawAlignmentIndicators();
}
- int fTestAlignment;
-};
+}
-//------- include the various unit tests as inline code -------
+void MainWindow::testAlignment(int v) {
+ fTestAlignment = v;
+ redraw();
+}
-#include "unittest_about.cxx"
-#include "unittest_points.cxx"
-#include "unittest_lines.cxx"
-#include "unittest_rects.cxx"
-#include "unittest_circles.cxx"
-#include "unittest_text.cxx"
-#include "unittest_symbol.cxx"
-#include "unittest_images.cxx"
-#include "unittest_viewport.cxx"
-#include "unittest_scrollbarsize.cxx"
-#include "unittest_schemes.cxx"
-#include "unittest_simple_terminal.cxx"
+//------- include the various unit tests as inline code -------
// callback whenever the browser value changes
void Browser_CB(Fl_Widget*, void*) {
@@ -175,6 +138,7 @@ int main(int argc, char **argv) {
Fl::get_system_colors();
Fl::scheme(Fl::scheme()); // init scheme before instantiating tests
Fl::visual(FL_RGB);
+ Fl::use_high_res_GL(1);
mainwin = new MainWindow(MAINWIN_W, MAINWIN_H, "FLTK Unit Tests");
browser = new Fl_Hold_Browser(BROWSER_X, BROWSER_Y, BROWSER_W, BROWSER_H, "Unit Tests");
browser->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
@@ -184,16 +148,18 @@ int main(int argc, char **argv) {
int i, n = UnitTest::numTest();
for (i=0; i<n; i++) {
UnitTest *t = UnitTest::test(i);
- mainwin->begin();
- t->create();
- mainwin->end();
- browser->add(t->label(), (void*)t);
+ if (t) {
+ mainwin->begin();
+ t->create();
+ mainwin->end();
+ browser->add(t->label(), (void*)t);
+ }
}
mainwin->resizable(mainwin);
mainwin->show(argc,argv);
// Select first test in browser, and show that test.
- browser->select(1);
+ browser->select(kTestAbout+1);
Browser_CB(browser,0);
return(Fl::run());
}