Make unittest conform to CMP (#597)

Update unittest README
This commit is contained in:
Matthias Melcher 2022-12-17 13:16:57 +01:00 committed by GitHub
parent 07041ea06e
commit 08f6741d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 409 additions and 393 deletions

View File

@ -150,6 +150,7 @@ CREATE_EXAMPLE (wizard wizard.cxx fltk)
SET (UNITTEST_SRCS SET (UNITTEST_SRCS
unittests.cxx unittests.cxx
unittests.h
unittest_about.cxx unittest_about.cxx
unittest_points.cxx unittest_points.cxx
unittest_complex_shapes.cxx unittest_complex_shapes.cxx

View File

@ -4,7 +4,7 @@ HOW TO CREATE A NEW UNIT TEST
1) Create your new test/unittest_xxx.cxx file (or use an existing one) 1) Create your new test/unittest_xxx.cxx file (or use an existing one)
2) In your new cxx file, define a class derived from Fl_Group 2) In your new cxx file, define a class derived from Fl_Group
for your test (e.g. TestFoo). for your test (e.g. Ut_Test_Foo).
The following should be a good starting template for the new file: The following should be a good starting template for the new file:
@ -19,44 +19,42 @@ HOW TO CREATE A NEW UNIT TEST
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
// Your class to do the test // Your class to do the test
// Your test must do its work within the TESTAREA_XYWH area. // Your test must do its work within the UT_TESTAREA_XYWH area.
// //
class TestFoo : public Fl_Group { class Ut_Test_Foo : public Fl_Group {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new TestFoo(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Test_Foo(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
TestFoo(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { .. } Ut_Test_Foo(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { .. }
}; };
// Create an instance of your class and register it with the main app // Create an instance of your class and register it with the main app
UnitTest testfoo(kTestFoo, "My foo tester", TestFoo::create); UnitTest testfoo(UT_TEST_FOO, "My foo tester", Ut_Test_Foo::create);
* * * * * *
Note that the last line in the above is what "registers" your new test Note that the last line in the above is what "registers" your new test
with the unittests main application: with the unittests main application:
UnitTest testfoo(kTestFoo, "My foo tester", TestFoo::create); UnitTest testfoo(UT_TEST_FOO, "My foo tester", Ut_Test_Foo::create);
------- -------- ------------- --------------- ------- ----------- ------------- -------------------
| | | | | | | |
| | | Your class's static create() method | | | Your class's static create() method
| | | | | |
| | Text name for your test that shows up in unittests browser | | Text name for your test that shows up in unittests browser
| | | |
| Just put 'k' in front of your class name. | This will be defined as an enum constant in the next step
| (This will be defined as an enum constant in the next step)
| |
The global instance name for your test. The global instance name for your test.
3) Take the 'k' name you used above, e.g. kTestFoo, and add it to the enum {} 3) Add an entry anywhere to the enum {} at the top of the unittests.h file. Example:
at the top of the unittests.h file. Example:
enum { enum {
kTestAbout = 0, UT_TEST_ABOUT = 0,
kTestPoints, UT_TEST_POINTS,
... ...
kTestFoo, <-- ADD YOUR TEST CLASS WITH THE 'k' PREFIX UT_TEST_FOO, <-- ADD YOUR TEST CLASS NAME IN ALL CAPS
... ...
}; };
@ -81,7 +79,7 @@ HOW TO CREATE A NEW UNIT TEST
GENERAL TEST PRACTICES GENERAL TEST PRACTICES
---------------------- ----------------------
TESTAREA_X, Y, W, and H will be the position and size of the Group, UT_TESTAREA_X, Y, W, and H will be the position and size of the Group,
and that the Group must expect to be resized, but not any smaller than and that the Group must expect to be resized, but not any smaller than
that area. that area.

View File

@ -265,10 +265,10 @@ Fl_Window *create_editor()
return win; return win;
} }
class MainWindow : public Fl_Double_Window class Ut_Main_Window : public Fl_Double_Window
{ {
public: public:
MainWindow(int w, int h, const char *l=0) Ut_Main_Window(int w, int h, const char *l=0)
: Fl_Double_Window(w, h, l) { } : Fl_Double_Window(w, h, l) { }
int handle(int event) { int handle(int event) {
if (event==FL_KEYBOARD && Fl::event_key()==FL_F+1) { if (event==FL_KEYBOARD && Fl::event_key()==FL_F+1) {
@ -300,7 +300,7 @@ void create_the_forms() {
label[i] = 0; label[i] = 0;
// create the basic layout // create the basic layout
form = new MainWindow(550,370); form = new Ut_Main_Window(550,370);
tile = new Fl_Tile(0, 0, 550, 370); tile = new Fl_Tile(0, 0, 550, 370);

View File

@ -21,12 +21,12 @@
// //
//------- Introduction to FLTK drawing test ------- //------- Introduction to FLTK drawing test -------
// //
class About : public Fl_Help_View { class Ut_About_View : public Fl_Help_View {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new About(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_About_View(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
About(int x, int y, int w, int h) : Fl_Help_View(x, y, w, h) { Ut_About_View(int x, int y, int w, int h) : Fl_Help_View(x, y, w, h) {
value( value(
"<htmL><body><h2>About Unit Testing...</h2>\n" "<htmL><body><h2>About Unit Testing...</h2>\n"
"The Unit Testing application can be used to verify correct graphics rendering " "The Unit Testing application can be used to verify correct graphics rendering "
@ -53,4 +53,4 @@ public:
} }
}; };
UnitTest about(kTestAbout, "About...", About::create); UnitTest about(UT_TEST_ABOUT, "About...", Ut_About_View::create);

View File

@ -75,18 +75,18 @@ void draw_circles() {
b+=44; b+=44;
// ---- 2: draw arcs and pies // ---- 2: draw arcs and pies
fl_color(FL_RED); fl_color(FL_RED);
// arc(a-5, b-5, w+10, h+10, 45.0, 315.0); // arc(a-5, b-5, w+10, h+10, 45.0, 315.0);
arc(a+1, b+1, w-2, h-2, 45.0, 315.0); arc(a+1, b+1, w-2, h-2, 45.0, 315.0);
// arc(a+5, b+5, w-10, h-10, 45.0, 315.0); // arc(a+5, b+5, w-10, h-10, 45.0, 315.0);
// arc(a+10, b+10, w-20, h-20, 45.0, 315.0); // arc(a+10, b+10, w-20, h-20, 45.0, 315.0);
fl_color(FL_GREEN); fl_color(FL_GREEN);
arc(a, b, w, h, 45.0, 315.0); arc(a, b, w, h, 45.0, 315.0);
arc(a+2, b+2, w-4, h-4, 45.0, 315.0); arc(a+2, b+2, w-4, h-4, 45.0, 315.0);
fl_color(FL_BLACK); fl_color(FL_BLACK);
// fl_arc(a-5, b-5, w+10, h+10, 45.0, 315.0); // fl_arc(a-5, b-5, w+10, h+10, 45.0, 315.0);
fl_arc(a+1, b+1, w-1, h-1, 45.0, 315.0); fl_arc(a+1, b+1, w-1, h-1, 45.0, 315.0);
// fl_arc(a+5, b+5, w-10, h-10, 45.0, 315.0); // fl_arc(a+5, b+5, w-10, h-10, 45.0, 315.0);
// fl_arc(a+10, b+10, w-20, h-20, 45.0, 315.0); // fl_arc(a+10, b+10, w-20, h-20, 45.0, 315.0);
fl_color(FL_RED); fl_color(FL_RED);
// ---- // ----
arc(a+1+50, b+1, w-2, h-2, 45.0, 315.0); arc(a+1+50, b+1, w-2, h-2, 45.0, 315.0);
@ -102,10 +102,10 @@ void draw_circles() {
#if HAVE_GL #if HAVE_GL
class GLCircleTest : public Fl_Gl_Window { class Ut_GL_Circle_Test : public Fl_Gl_Window {
public: public:
GLCircleTest(int x, int y, int w, int h) Ut_GL_Circle_Test(int x, int y, int w, int h)
: Fl_Gl_Window(x, y, w, h) { : Fl_Gl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
} }
void draw() { void draw() {
@ -118,10 +118,10 @@ public:
#endif #endif
class NativeCircleTest : public Fl_Window { class Ut_Native_Circle_Test : public Fl_Window {
public: public:
NativeCircleTest(int x, int y, int w, int h) Ut_Native_Circle_Test(int x, int y, int w, int h)
: Fl_Window(x, y, w, h) { : Fl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
end(); end();
} }
@ -134,12 +134,13 @@ public:
// //
//------- test the circle drawing capabilities of this implementation ---------- //------- test the circle drawing capabilities of this implementation ----------
// //
class CircleTest : public Fl_Group { class Ut_Circle_Test : public Fl_Group {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new CircleTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Circle_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
CircleTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Circle_Test(int x, int y, int w, int h)
: Fl_Group(x, y, w, h) {
label("Testing fast circle, arc, and pie drawing\n\n" label("Testing fast circle, arc, and pie drawing\n\n"
"No red lines should be visible. " "No red lines should be visible. "
"The green outlines should not be overwritten by circle drawings."); "The green outlines should not be overwritten by circle drawings.");
@ -147,10 +148,10 @@ public:
box(FL_BORDER_BOX); box(FL_BORDER_BOX);
int a = x+16, b = y+34; int a = x+16, b = y+34;
Fl_Box *t = new Fl_Box(a, b-24, 80, 18, "native"); Fl_Box* t = new Fl_Box(a, b-24, 80, 18, "native");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
/* NativeCircleTest *nr = */ new NativeCircleTest(a+23, b-1, 200, 200); /* NativeCircleTest *nr = */ new Ut_Native_Circle_Test(a+23, b-1, 200, 200);
t = new Fl_Box(a, b, 18, 18, "1"); t = new Fl_Box(a, b, 18, 18, "1");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -180,7 +181,7 @@ public:
t = new Fl_Box(a, b-24, 80, 18, "OpenGL"); t = new Fl_Box(a, b-24, 80, 18, "OpenGL");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
/* GLCircleTest *glr = */ new GLCircleTest(a+31, b-1, 200, 200); /* GLCircleTest *glr = */ new Ut_GL_Circle_Test(a+31, b-1, 200, 200);
t = new Fl_Box(a, b, 26, 18, "1a"); t = new Fl_Box(a, b, 26, 18, "1a");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -210,4 +211,4 @@ public:
} }
}; };
UnitTest circle(kTestCircles, "Circles and Arcs", CircleTest::create); UnitTest circle(UT_TEST_CIRCLES, "Circles and Arcs", Ut_Circle_Test::create);

View File

@ -31,70 +31,70 @@
// --- test drawing circles and arcs ------ // --- test drawing circles and arcs ------
// //
class ComplexShapesTest; class Ut_Complex_Shapes_Test;
void draw_complex(ComplexShapesTest *p); void draw_complex(Ut_Complex_Shapes_Test *p);
#if HAVE_GL #if HAVE_GL
class GLComplexShapesTest : public Fl_Gl_Window { class Ut_GL_Complex_Shapes_Test : public Fl_Gl_Window {
public: public:
GLComplexShapesTest(int x, int y, int w, int h) Ut_GL_Complex_Shapes_Test(int x, int y, int w, int h)
: Fl_Gl_Window(x, y, w, h) { : Fl_Gl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
end(); end();
} }
void draw() { void draw() {
draw_begin(); draw_begin();
Fl_Window::draw(); Fl_Window::draw();
draw_complex((ComplexShapesTest*)parent()); draw_complex((Ut_Complex_Shapes_Test*)parent());
draw_end(); draw_end();
} }
}; };
#endif #endif
class NativeComplexShapesTest : public Fl_Window { class Ut_Native_Complex_Shapes_Test : public Fl_Window {
public: public:
NativeComplexShapesTest(int x, int y, int w, int h) Ut_Native_Complex_Shapes_Test(int x, int y, int w, int h)
: Fl_Window(x, y, w, h) { : Fl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
end(); end();
} }
void draw() { void draw() {
Fl_Window::draw(); Fl_Window::draw();
draw_complex((ComplexShapesTest*)parent()); draw_complex((Ut_Complex_Shapes_Test*)parent());
} }
}; };
// //
//------- test the compelx shape drawing capabilities of this implementation ---------- //------- test the compelx shape drawing capabilities of this implementation ----------
// //
class ComplexShapesTest : public Fl_Group { class Ut_Complex_Shapes_Test : public Fl_Group {
NativeComplexShapesTest *native_test_window; Ut_Native_Complex_Shapes_Test* native_test_window;
#if HAVE_GL #if HAVE_GL
GLComplexShapesTest *gl_test_window; Ut_GL_Complex_Shapes_Test* gl_test_window;
#endif #endif
static void update_cb(Fl_Widget *, void *v) { static void update_cb(Fl_Widget*, void *v) {
ComplexShapesTest *This = (ComplexShapesTest*)v; Ut_Complex_Shapes_Test* This = (Ut_Complex_Shapes_Test*)v;
This->native_test_window->redraw(); This->native_test_window->redraw();
#if HAVE_GL #if HAVE_GL
This->gl_test_window->redraw(); This->gl_test_window->redraw();
#endif #endif
} }
public: public:
Fl_Hor_Value_Slider *scale; Fl_Hor_Value_Slider* scale;
Fl_Dial *rotate; Fl_Dial* rotate;
Fl_Positioner *position; Fl_Positioner* position;
void set_transformation() { void set_transformation() {
fl_translate(position->xvalue(), position->yvalue()); fl_translate(position->xvalue(), position->yvalue());
fl_rotate(-rotate->value()); fl_rotate(-rotate->value());
fl_scale(scale->value(), scale->value()); fl_scale(scale->value(), scale->value());
} }
static Fl_Widget *create() { static Fl_Widget* create() {
return new ComplexShapesTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Complex_Shapes_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
ComplexShapesTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Complex_Shapes_Test(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
label("Testing complex shape drawing."); label("Testing complex shape drawing.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX); box(FL_BORDER_BOX);
@ -103,7 +103,7 @@ public:
Fl_Box *t = new Fl_Box(a, b-24, 80, 18, "native"); Fl_Box *t = new Fl_Box(a, b-24, 80, 18, "native");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
native_test_window = new NativeComplexShapesTest(a+23, b-1, 200, 200); native_test_window = new Ut_Native_Complex_Shapes_Test(a+23, b-1, 200, 200);
t = new Fl_Box(a, b, 18, 18, "1"); t = new Fl_Box(a, b, 18, 18, "1");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -146,7 +146,7 @@ public:
t = new Fl_Box(a, b-24, 80, 18, "OpenGL"); t = new Fl_Box(a, b-24, 80, 18, "OpenGL");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
gl_test_window = new GLComplexShapesTest(a+31, b-1, 200, 200); gl_test_window = new Ut_GL_Complex_Shapes_Test(a+31, b-1, 200, 200);
t = new Fl_Box(a, b, 26, 18, "1a"); t = new Fl_Box(a, b, 26, 18, "1a");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -185,8 +185,8 @@ public:
); );
#endif #endif
a = TESTAREA_X+TESTAREA_W-250; a = UT_TESTAREA_X+UT_TESTAREA_W-250;
b = TESTAREA_Y+TESTAREA_H-50; b = UT_TESTAREA_Y+UT_TESTAREA_H-50;
scale = new Fl_Hor_Value_Slider(a, b+10, 120, 20, "Scale:"); scale = new Fl_Hor_Value_Slider(a, b+10, 120, 20, "Scale:");
scale->align(FL_ALIGN_TOP_LEFT); scale->align(FL_ALIGN_TOP_LEFT);
@ -265,7 +265,7 @@ void complex_shape_with_hole(int w, int h) {
fl_vertex( w2, -h2); fl_vertex( w2, -h2);
} }
void draw_complex(ComplexShapesTest *p) { void draw_complex(Ut_Complex_Shapes_Test *p) {
int a = 0, b = 0, dx = 20, dy = 20, w = 10, h = 10; int a = 0, b = 0, dx = 20, dy = 20, w = 10, h = 10;
int w2 = w/3, h2 = h/3; int w2 = w/3, h2 = h/3;
// ---- 1: draw a random shape // ---- 1: draw a random shape
@ -430,15 +430,6 @@ void draw_complex(ComplexShapesTest *p) {
fl_vertex(w, h); fl_vertex(-w, h); fl_vertex(w, h); fl_vertex(-w, h);
fl_end_loop(); fl_end_loop();
fl_pop_matrix(); fl_pop_matrix();
// Test fl_begin_points(), fl_end_points()
// Test fl_begin_line() fl_end_line()
// Test fl_begin_loop() fl_end_loop()
// Test fl_begin_polygon() fl_end_polygon()
// Test fl_begin_complex_polygon() fl_gap() fl_arc() void fl_end_complex_polygon()
// Test fl_curve()
// Test translate, rotate, scale, push, pop
} }
UnitTest complex_shapes(kTestComplexShapes, "Complex Shapes", ComplexShapesTest::create); UnitTest complex_shapes(UT_TEST_COMPLEX_SHAPES, "Complex Shapes", Ut_Complex_Shapes_Test::create);

View File

@ -25,7 +25,7 @@
#if 0 #if 0
// TODO: // not testing yet:
void fl_line(int x, int y, int x1, int y1) void fl_line(int x, int y, int x1, int y1)
void fl_line(int x, int y, int x1, int y1, int x2, int y2) void fl_line(int x, int y, int x1, int y1, int x2, int y2)
@ -186,10 +186,10 @@ void draw_fast_shapes() {
#if HAVE_GL #if HAVE_GL
class GLRectTest : public Fl_Gl_Window { class Ut_GL_Rect_Test : public Fl_Gl_Window {
public: public:
GLRectTest(int x, int y, int w, int h) Ut_GL_Rect_Test(int x, int y, int w, int h)
: Fl_Gl_Window(x, y, w, h) { : Fl_Gl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
} }
void draw() { void draw() {
@ -203,10 +203,10 @@ public:
#endif #endif
class NativeRectTest : public Fl_Window { class Ut_Native_Rect_Test : public Fl_Window {
public: public:
NativeRectTest(int x, int y, int w, int h) Ut_Native_Rect_Test(int x, int y, int w, int h)
: Fl_Window(x, y, w, h) { : Fl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
end(); end();
} }
@ -216,12 +216,13 @@ public:
} }
}; };
class RectTest : public Fl_Group { // 520 x 365 class Ut_Rect_Test : public Fl_Group { // 520 x 365
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new RectTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Rect_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
RectTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Rect_Test(int x, int y, int w, int h)
: Fl_Group(x, y, w, h) {
label("Testing FLTK fast shape calls.\n" label("Testing FLTK fast shape calls.\n"
"These calls draw horizontal and vertical lines, frames, and rectangles.\n\n" "These calls draw horizontal and vertical lines, frames, and rectangles.\n\n"
"No red pixels should be visible. " "No red pixels should be visible. "
@ -234,7 +235,7 @@ public:
Fl_Box *t = new Fl_Box(a, b-24, 80, 18, "native"); Fl_Box *t = new Fl_Box(a, b-24, 80, 18, "native");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
/* NativeRectTest *nr = */ new NativeRectTest(a+23, b-1, 200, 200); /* NativeRectTest *nr = */ new Ut_Native_Rect_Test(a+23, b-1, 200, 200);
t = new Fl_Box(a, b, 18, 18, "1"); t = new Fl_Box(a, b, 18, 18, "1");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -306,7 +307,7 @@ public:
t = new Fl_Box(a, b-24, 80, 18, "OpenGL"); t = new Fl_Box(a, b-24, 80, 18, "OpenGL");
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
/*GLRectTest *glr = */ new GLRectTest(a+31, b-1, 200, 200); /*GLRectTest *glr = */ new Ut_GL_Rect_Test(a+31, b-1, 200, 200);
t = new Fl_Box(a, b, 26, 18, "1a"); t = new Fl_Box(a, b, 26, 18, "1a");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -380,4 +381,4 @@ public:
} }
}; };
UnitTest rects(kTestFastShapes, "Fast Shapes", RectTest::create); UnitTest rects(UT_TEST_FAST_SHAPES, "Fast Shapes", Ut_Rect_Test::create);

View File

@ -35,41 +35,41 @@
// Parameters for fine tuning for developers. // Parameters for fine tuning for developers.
// Default values: CB=1, DX=0, IMG=1, LX=0, FLIPH=0 // Default values: CB=1, DX=0, IMG=1, LX=0, FLIPH=0
static int CB = 1; // 1 to show the checker board background for alpha images, static int cb = 1; // 1 to show the checker board background for alpha images,
// 0 otherwise // 0 otherwise
static int DX = 0; // additional (undefined (0)) pixels per line, must be >= 0 static int dx = 0; // additional (undefined (0)) pixels per line, must be >= 0
// ignored (irrelevant), if LX == 0 (see below) // ignored (irrelevant), if LX == 0 (see below)
static int IMG = 1; // 1 to use Fl_RGB_Image for drawing images with transparency, static int img = 1; // 1 to use Fl_RGB_Image for drawing images with transparency,
// 0 to use fl_draw_image() instead. // 0 to use fl_draw_image() instead.
// Note: as of Feb 2016, only 1 (Fl_RGB_Image) works with // Note: as of Feb 2016, only 1 (Fl_RGB_Image) works with
// alpha channel, 0 (fl_draw_image()) ignores the alpha // alpha channel, 0 (fl_draw_image()) ignores the alpha
// channel (FLTK 1.3.x). // channel (FLTK 1.3.x).
// There are plans to support transparency (alpha channel) // There are plans to support transparency (alpha channel)
// in fl_draw_image() in FLTK 1.4.0 and/or later. // in fl_draw_image() in FLTK 1.4.0 and/or later.
static int LX = 0; // 0 for default: ld() = 0, i.e. ld() defaults (internally) to w()*d() static int lx = 0; // 0 for default: ld() = 0, i.e. ld() defaults (internally) to w()*d()
// +1: ld() = (w() + DX) * d() // +1: ld() = (w() + DX) * d()
// -1 to flip image vertically: ld() = - ((w() + DX) * d()) // -1 to flip image vertically: ld() = - ((w() + DX) * d())
static int FLIPH = 0; // 1 = Flip image horizontally (only if IMG == 0) static int flip_h = 0; // 1 = Flip image horizontally (only if IMG == 0)
// 0 = Draw image normal, w/o horizontal flipping // 0 = Draw image normal, w/o horizontal flipping
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Test scenario for fl_draw_image() with pos. and neg. d and ld args: // Test scenario for fl_draw_image() with pos. and neg. d and ld args:
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// (1) set IMG = 0: normal, but w/o transparency: no checker board // (1) set img = 0: normal, but w/o transparency: no checker board
// (2) set LX = -1: images flipped vertically // (2) set lx = -1: images flipped vertically
// (3) set FLIPH = 1: images flipped vertically and horizontally // (3) set flip_h = 1: images flipped vertically and horizontally
// (4) set LX = 0: images flipped horizontally // (4) set lx = 0: images flipped horizontally
// (5) set FLIPH = 0, IMG = 1: back to default (with transparency) // (5) set flip_h = 0, IMG = 1: back to default (with transparency)
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
class ImageTest : public Fl_Group { class Ut_Image_Test : public Fl_Group {
static void build_imgs() { static void build_imgs() {
int x, y; int x, y;
uchar *dg, *dga, *drgb, *drgba; uchar *dg, *dga, *drgb, *drgba;
dg = img_gray = img_gray_base = (uchar*)malloc((128+DX)*128*1); dg = img_gray = img_gray_base = (uchar*)malloc((128+dx)*128*1);
dga = img_gray_a = img_gray_a_base = (uchar*)malloc((128+DX)*128*2); dga = img_gray_a = img_gray_a_base = (uchar*)malloc((128+dx)*128*2);
drgb = img_rgb = img_rgb_base = (uchar*)malloc((128+DX)*128*3); drgb = img_rgb = img_rgb_base = (uchar*)malloc((128+dx)*128*3);
drgba = img_rgba = img_rgba_base = (uchar*)malloc((128+DX)*128*4); drgba = img_rgba = img_rgba_base = (uchar*)malloc((128+dx)*128*4);
for (y=0; y<128; y++) { for (y=0; y<128; y++) {
for (x=0; x<128; x++) { for (x=0; x<128; x++) {
*drgba++ = *drgb++ = *dga++ = *dg++ = y<<1; *drgba++ = *drgb++ = *dga++ = *dg++ = y<<1;
@ -77,29 +77,29 @@ class ImageTest : public Fl_Group {
*drgba++ = *drgb++ = (127-x)<<1; *drgba++ = *drgb++ = (127-x)<<1;
*drgba++ = *dga++ = x+y; *drgba++ = *dga++ = x+y;
} }
if (DX > 0 && LX != 0) { if (dx > 0 && lx != 0) {
memset(dg, 0,1*DX); dg += 1*DX; memset(dg, 0,1*dx); dg += 1*dx;
memset(dga, 0,2*DX); dga += 2*DX; memset(dga, 0,2*dx); dga += 2*dx;
memset(drgb, 0,3*DX); drgb += 3*DX; memset(drgb, 0,3*dx); drgb += 3*dx;
memset(drgba,0,4*DX); drgba += 4*DX; memset(drgba,0,4*dx); drgba += 4*dx;
} }
} }
if (LX<0) { if (lx<0) {
img_gray += 127*(128+DX); img_gray += 127*(128+dx);
img_gray_a += 127*(128+DX)*2; img_gray_a += 127*(128+dx)*2;
img_rgb += 127*(128+DX)*3; img_rgb += 127*(128+dx)*3;
img_rgba += 127*(128+DX)*4; img_rgba += 127*(128+dx)*4;
} }
if (FLIPH && !IMG ) { if (flip_h && !img ) {
img_gray += 127; img_gray += 127;
img_gray_a += 127*2; img_gray_a += 127*2;
img_rgb += 127*3; img_rgb += 127*3;
img_rgba += 127*4; img_rgba += 127*4;
} }
i_g = new Fl_RGB_Image (img_gray ,128,128,1,LX*(128+DX)); i_g = new Fl_RGB_Image (img_gray ,128,128,1,lx*(128+dx));
i_ga = new Fl_RGB_Image (img_gray_a,128,128,2,LX*(128+DX)*2); i_ga = new Fl_RGB_Image (img_gray_a,128,128,2,lx*(128+dx)*2);
i_rgb = new Fl_RGB_Image (img_rgb, 128,128,3,LX*(128+DX)*3); i_rgb = new Fl_RGB_Image (img_rgb, 128,128,3,lx*(128+dx)*3);
i_rgba = new Fl_RGB_Image (img_rgba, 128,128,4,LX*(128+DX)*4); i_rgba = new Fl_RGB_Image (img_rgba, 128,128,4,lx*(128+dx)*4);
} // build_imgs method ends } // build_imgs method ends
void free_images() { void free_images() {
@ -114,16 +114,16 @@ class ImageTest : public Fl_Group {
} // end of free_images method } // end of free_images method
static void refresh_imgs_CB(Fl_Widget*,void *data) { static void refresh_imgs_CB(Fl_Widget*,void *data) {
ImageTest *it = (ImageTest*)data; Ut_Image_Test* it = (Ut_Image_Test*)data;
it->free_images(); // release the previous images it->free_images(); // release the previous images
// determine the state for the next images // determine the state for the next images
CB = it->ck_CB->value(); cb = it->ck_CB->value();
IMG = it->ck_IMG->value(); img = it->ck_IMG->value();
FLIPH = it->ck_FLIPH->value(); flip_h = it->ck_FLIPH->value();
// read the LX state radio buttons // read the LX state radio buttons
if (it->rb_LXp1->value()) { LX = 1; } if (it->rb_LXp1->value()) { lx = 1; }
else if (it->rb_LXm1->value()) { LX = (-1); } else if (it->rb_LXm1->value()) { lx = (-1); }
else { LX = 0; } else { lx = 0; }
// construct the next images // construct the next images
build_imgs(); build_imgs();
it->redraw(); it->redraw();
@ -132,7 +132,7 @@ class ImageTest : public Fl_Group {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
build_imgs(); build_imgs();
return new ImageTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Image_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} // create method ends } // create method ends
static uchar *img_gray_base; static uchar *img_gray_base;
@ -158,7 +158,9 @@ public:
Fl_Radio_Button *rb_LXp1; Fl_Radio_Button *rb_LXp1;
Fl_Button *refresh; Fl_Button *refresh;
ImageTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Image_Test(int x, int y, int w, int h)
: Fl_Group(x, y, w, h)
{
label("Testing Image Drawing\n\n" label("Testing Image Drawing\n\n"
"This test renders four images, two of them with a checker board\n" "This test renders four images, two of them with a checker board\n"
"visible through the graphics. Color and gray gradients should be\n" "visible through the graphics. Color and gray gradients should be\n"
@ -166,34 +168,46 @@ public:
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX); box(FL_BORDER_BOX);
int cw = 90; int cw = 90;
int ch = 270; int ch = 200;
int cx = x + w - cw - 5; int cx = x + w - cw - 5;
int cy = y + 10; int cy = y + 10;
ctr_grp = new Fl_Group(cx, cy, cw, ch); ctr_grp = new Fl_Group(cx, cy, cw, ch);
ck_CB = new Fl_Check_Button(cx+10, cy+10, cw-20, 30, "CB"); ck_CB = new Fl_Check_Button(cx+10, cy+10, cw-20, 30, "CB");
ck_CB->value(CB); ck_CB->callback(refresh_imgs_CB, (void*)this);
ck_CB->value(cb);
ck_CB->tooltip("1 to show the checker board background for alpha images,\n"
"0 otherwise");
ck_IMG = new Fl_Check_Button(cx+10, cy+40, cw-20, 30, "IMG"); ck_IMG = new Fl_Check_Button(cx+10, cy+40, cw-20, 30, "IMG");
ck_IMG->value(IMG); ck_IMG->callback(refresh_imgs_CB, (void*)this);
ck_IMG->value(img);
ck_IMG->tooltip("1 to use Fl_RGB_Image for drawing images with transparency,\n"
"0 to use fl_draw_image() instead.");
ck_FLIPH = new Fl_Check_Button(cx+10, cy+70, cw-20, 30, "FLIPH"); ck_FLIPH = new Fl_Check_Button(cx+10, cy+70, cw-20, 30, "FLIPH");
ck_FLIPH->value(FLIPH); ck_FLIPH->callback(refresh_imgs_CB, (void*)this);
ck_FLIPH->value(flip_h);
ck_FLIPH->tooltip("1 = Flip image horizontally (only if IMG == 0)\n"
"0 = Draw image normal, w/o horizontal flipping");
Fl_Group *rd_grp = new Fl_Group(cx+10, cy+100, cw-20, 90, "LX"); Fl_Group *rd_grp = new Fl_Group(cx+10, cy+100, cw-20, 90, "LX");
rb_LXp1 = new Fl_Radio_Button(cx+15, cy+105, cw-30, 20, "+1"); rb_LXp1 = new Fl_Radio_Button(cx+15, cy+105, cw-30, 20, "+1");
rb_LXp1->callback(refresh_imgs_CB, (void*)this);
rb_LX0 = new Fl_Radio_Button(cx+15, cy+125, cw-30, 20, "0"); rb_LX0 = new Fl_Radio_Button(cx+15, cy+125, cw-30, 20, "0");
rb_LX0->callback(refresh_imgs_CB, (void*)this);
rb_LX0->tooltip("0 for default: ld() = 0, i.e. ld() defaults (internally) to w()*d()\n"
"+1: ld() = (w() + DX) * d()\n"
"-1 to flip image vertically: ld() = - ((w() + DX) * d())");
rb_LXm1 = new Fl_Radio_Button(cx+15, cy+145, cw-30, 20, "-1"); rb_LXm1 = new Fl_Radio_Button(cx+15, cy+145, cw-30, 20, "-1");
rb_LXm1->callback(refresh_imgs_CB, (void*)this);
rb_LX0->value(1); rb_LX0->value(1);
rd_grp->box(FL_BORDER_BOX); rd_grp->box(FL_BORDER_BOX);
rd_grp->align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_CENTER); rd_grp->align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_CENTER);
rd_grp->end(); rd_grp->end();
refresh = new Fl_Button(cx+10, cy+ch-40, cw-20, 30, "Refresh");
refresh->callback(refresh_imgs_CB, (void*)this);
ctr_grp->box(FL_BORDER_BOX); ctr_grp->box(FL_BORDER_BOX);
ctr_grp->end(); ctr_grp->end();
end(); // make sure this ImageTest group is closed end(); // make sure this ImageTest group is closed
@ -206,15 +220,15 @@ public:
int xx = x()+10, yy = y()+10; int xx = x()+10, yy = y()+10;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130);
if (IMG) { if (img) {
i_rgb->draw(xx+1,yy+1); i_rgb->draw(xx+1,yy+1);
} }
else { else {
if (!FLIPH) { if (!flip_h) {
fl_draw_image(img_rgb, xx+1, yy+1, 128, 128, 3, LX*((128+DX)*3)); fl_draw_image(img_rgb, xx+1, yy+1, 128, 128, 3, lx*((128+dx)*3));
} }
else { else {
fl_draw_image(img_rgb, xx+1, yy+1, 128, 128,-3, LX*((128+DX)*3)); fl_draw_image(img_rgb, xx+1, yy+1, 128, 128,-3, lx*((128+dx)*3));
} }
} }
fl_draw("RGB", xx+134, yy+64); fl_draw("RGB", xx+134, yy+64);
@ -224,19 +238,19 @@ public:
xx = x()+10; yy = y()+10+134; xx = x()+10; yy = y()+10+134;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); // black frame fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); // black frame
fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 128, 128); // white background fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 128, 128); // white background
if (CB) { // checker board if (cb) { // checker board
fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64); fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64);
fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64); fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64);
} }
if (IMG) { if (img) {
i_rgba->draw(xx+1,yy+1); i_rgba->draw(xx+1,yy+1);
} }
else { else {
if (!FLIPH) { if (!flip_h) {
fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4, LX*((128+DX)*4)); fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4, lx*((128+dx)*4));
} }
else { else {
fl_draw_image(img_rgba, xx+1, yy+1, 128, 128,-4, LX*((128+DX)*4)); fl_draw_image(img_rgba, xx+1, yy+1, 128, 128,-4, lx*((128+dx)*4));
} }
} }
fl_color(FL_BLACK); fl_draw("RGBA", xx+134, yy+64); fl_color(FL_BLACK); fl_draw("RGBA", xx+134, yy+64);
@ -245,15 +259,15 @@ public:
xx = x()+10+200; yy = y()+10; xx = x()+10+200; yy = y()+10;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130);
if (IMG) { if (img) {
i_g->draw(xx+1,yy+1); i_g->draw(xx+1,yy+1);
} }
else { else {
if (!FLIPH) { if (!flip_h) {
fl_draw_image(img_gray, xx+1, yy+1, 128, 128, 1, LX*((128+DX)*1)); fl_draw_image(img_gray, xx+1, yy+1, 128, 128, 1, lx*((128+dx)*1));
} }
else { else {
fl_draw_image(img_gray, xx+1, yy+1, 128, 128,-1, LX*((128+DX)*1)); fl_draw_image(img_gray, xx+1, yy+1, 128, 128,-1, lx*((128+dx)*1));
} }
} }
fl_draw("Gray", xx+134, yy+64); fl_draw("Gray", xx+134, yy+64);
@ -263,36 +277,36 @@ public:
xx = x()+10+200; yy = y()+10+134; xx = x()+10+200; yy = y()+10+134;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); // black frame fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130); // black frame
fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 128, 128); // white background fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 128, 128); // white background
if (CB) { // checker board if (cb) { // checker board
fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64); fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64);
fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64); fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64);
} }
if (IMG) { if (img) {
i_ga->draw(xx+1,yy+1); i_ga->draw(xx+1,yy+1);
} }
else { else {
if (!FLIPH) { if (!flip_h) {
fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2, LX*((128+DX)*2)); fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2, lx*((128+dx)*2));
} }
else { else {
fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128,-2, LX*((128+DX)*2)); fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128,-2, lx*((128+dx)*2));
} }
} }
fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64); fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64);
} // draw method end } // draw method end
}; };
uchar *ImageTest::img_gray_base = 0; uchar *Ut_Image_Test::img_gray_base = 0;
uchar *ImageTest::img_gray_a_base = 0; uchar *Ut_Image_Test::img_gray_a_base = 0;
uchar *ImageTest::img_rgb_base = 0; uchar *Ut_Image_Test::img_rgb_base = 0;
uchar *ImageTest::img_rgba_base = 0; uchar *Ut_Image_Test::img_rgba_base = 0;
uchar *ImageTest::img_gray = 0; uchar *Ut_Image_Test::img_gray = 0;
uchar *ImageTest::img_gray_a = 0; uchar *Ut_Image_Test::img_gray_a = 0;
uchar *ImageTest::img_rgb = 0; uchar *Ut_Image_Test::img_rgb = 0;
uchar *ImageTest::img_rgba = 0; uchar *Ut_Image_Test::img_rgba = 0;
Fl_RGB_Image *ImageTest::i_g = 0; Fl_RGB_Image *Ut_Image_Test::i_g = 0;
Fl_RGB_Image *ImageTest::i_ga = 0; Fl_RGB_Image *Ut_Image_Test::i_ga = 0;
Fl_RGB_Image *ImageTest::i_rgb = 0; Fl_RGB_Image *Ut_Image_Test::i_rgb = 0;
Fl_RGB_Image *ImageTest::i_rgba = 0; Fl_RGB_Image *Ut_Image_Test::i_rgba = 0;
UnitTest images(kTestImages, "Drawing Images", ImageTest::create); UnitTest images(UT_TEST_IMAGES, "Drawing Images", Ut_Image_Test::create);

View File

@ -27,10 +27,12 @@
//------- test the point drawing capabilities of this implementation ---------- //------- test the point drawing capabilities of this implementation ----------
// //
class PointTestWin : public Fl_Window { class Ut_Native_Point_Test : public Fl_Window {
public: public:
PointTestWin(int x, int y, int w, int h) : Ut_Native_Point_Test(int x, int y, int w, int h)
Fl_Window(x, y, w, h) { end(); } : Fl_Window(x, y, w, h) {
end();
}
void draw() { void draw() {
int i; int i;
fl_color(FL_WHITE); fl_color(FL_WHITE);
@ -49,10 +51,10 @@ public:
#if HAVE_GL #if HAVE_GL
class GLTestWin : public Fl_Gl_Window { class Ut_GL_Point_Test : public Fl_Gl_Window {
public: public:
GLTestWin(int x, int y, int w, int h) : Ut_GL_Point_Test(int x, int y, int w, int h)
Fl_Gl_Window(x, y, w, h) { : Fl_Gl_Window(x, y, w, h) {
box(FL_FLAT_BOX); box(FL_FLAT_BOX);
end(); end();
} }
@ -131,17 +133,18 @@ public:
#endif #endif
class PointTest : public Fl_Group { class Ut_Point_Test : public Fl_Group {
PointTestWin *align_test_win; Ut_Native_Point_Test *align_test_win;
#if HAVE_GL #if HAVE_GL
GLTestWin *gl_test_win; Ut_GL_Point_Test *gl_test_win;
#endif #endif
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new PointTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Point_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
// 520x365, resizable // 520x365, resizable
} }
PointTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Point_Test(int x, int y, int w, int h)
: Fl_Group(x, y, w, h) {
label("Testing the fl_point call."); label("Testing the fl_point call.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX); box(FL_BORDER_BOX);
@ -179,7 +182,7 @@ public:
// Things to look out for: // Things to look out for:
"If parts of the black frame are clipped by the window and not visible, pixel offsets must be adjusted." "If parts of the black frame are clipped by the window and not visible, pixel offsets must be adjusted."
); );
align_test_win = new PointTestWin(a+24, b+2*24+2*16+9-5, 10, 10); align_test_win = new Ut_Native_Point_Test(a+24, b+2*24+2*16+9-5, 10, 10);
t = new Fl_Box(a, b+3*24+2*16, 18, 18, "4"); t = new Fl_Box(a, b+3*24+2*16, 18, 18, "4");
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW); t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
@ -238,7 +241,7 @@ public:
"If red pixels are visible or black pixels are missing, graphics clipping is misaligned." "If red pixels are visible or black pixels are missing, graphics clipping is misaligned."
); );
gl_test_win = new GLTestWin(a+24+8, b+9-5, 10, 4*24+2*16); gl_test_win = new Ut_GL_Point_Test(a+24+8, b+9-5, 10, 4*24+2*16);
#endif #endif
t = new Fl_Box(x+w-1,y+h-1, 1, 1); t = new Fl_Box(x+w-1,y+h-1, 1, 1);
@ -303,4 +306,4 @@ public:
} }
}; };
UnitTest points(kTestPoints, "Drawing Points", PointTest::create); UnitTest points(UT_TEST_POINTS, "Drawing Points", Ut_Point_Test::create);

View File

@ -44,12 +44,12 @@
#include <FL/Fl_Check_Button.H> #include <FL/Fl_Check_Button.H>
#include <FL/Fl_Radio_Round_Button.H> #include <FL/Fl_Radio_Round_Button.H>
class SchemesTest : public Fl_Group { class Ut_Schemes_Test : public Fl_Group {
Fl_Choice *schemechoice; Fl_Choice *scheme_choice_;
static void SchemeChoice_CB(Fl_Widget*,void *data) { static void scheme_choice_cb(Fl_Widget*,void *data) {
SchemesTest *st = (SchemesTest*)data; Ut_Schemes_Test *st = (Ut_Schemes_Test*)data;
const char *name = st->schemechoice->text(); const char *name = st->scheme_choice_->text();
if ( name ) { if ( name ) {
Fl::scheme(name); // change scheme Fl::scheme(name); // change scheme
st->window()->redraw(); // redraw window st->window()->redraw(); // redraw window
@ -78,25 +78,26 @@ class SchemesTest : public Fl_Group {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new SchemesTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Schemes_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
SchemesTest(int X,int Y,int W,int H) : Fl_Group(X,Y,W,H) { Ut_Schemes_Test(int X,int Y,int W,int H)
schemechoice = new Fl_Choice(X+125,Y,140,25,"FLTK Scheme"); : Fl_Group(X,Y,W,H) {
schemechoice->add("none"); scheme_choice_ = new Fl_Choice(X+125,Y,140,25,"FLTK Scheme");
schemechoice->add("plastic"); scheme_choice_->add("none");
schemechoice->add("gtk+"); scheme_choice_->add("plastic");
schemechoice->add("gleam"); scheme_choice_->add("gtk+");
schemechoice->add("oxy"); scheme_choice_->add("gleam");
schemechoice->value(0); scheme_choice_->add("oxy");
schemechoice->labelfont(FL_HELVETICA_BOLD); scheme_choice_->value(0);
scheme_choice_->labelfont(FL_HELVETICA_BOLD);
const char *name = Fl::scheme(); const char *name = Fl::scheme();
if ( name ) { if ( name ) {
if ( strcmp(name, "plastic") == 0) { schemechoice->value(1); } if ( strcmp(name, "plastic") == 0) { scheme_choice_->value(1); }
else if ( strcmp(name, "gtk+") == 0) { schemechoice->value(2); } else if ( strcmp(name, "gtk+") == 0) { scheme_choice_->value(2); }
else if ( strcmp(name, "gleam") == 0) { schemechoice->value(3); } else if ( strcmp(name, "gleam") == 0) { scheme_choice_->value(3); }
else if ( strcmp(name, "oxy") == 0) { schemechoice->value(4); } else if ( strcmp(name, "oxy") == 0) { scheme_choice_->value(4); }
} }
schemechoice->callback(SchemeChoice_CB, (void*)this); scheme_choice_->callback(scheme_choice_cb, (void*)this);
Fl_Light_Button *active = new Fl_Light_Button(X + 300, Y, 100, 25, "active"); Fl_Light_Button *active = new Fl_Light_Button(X + 300, Y, 100, 25, "active");
active->value(1); active->value(1);
@ -355,4 +356,4 @@ public:
} }
}; };
UnitTest schemestest(kTestSchemes, "Schemes Test", SchemesTest::create); UnitTest schemestest(UT_TEST_SCHEMES, "Schemes Test", Ut_Schemes_Test::create);

View File

@ -27,7 +27,7 @@
// //
// Test new 1.3.x global vs. local scrollbar sizing // Test new 1.3.x global vs. local scrollbar sizing
// //
class MyTable : public Fl_Table { class Ut_Table : public Fl_Table {
// Handle drawing table's cells // Handle drawing table's cells
// Fl_Table calls this function to draw each visible cell in the table. // Fl_Table calls this function to draw each visible cell in the table.
// It's up to us to use FLTK's drawing functions to draw the cells the way we want. // It's up to us to use FLTK's drawing functions to draw the cells the way we want.
@ -57,7 +57,8 @@ class MyTable : public Fl_Table {
// Constructor // Constructor
// Make our data array, and initialize the table options. // Make our data array, and initialize the table options.
// //
MyTable(int X, int Y, int W, int H, const char *L=0) : Fl_Table(X,Y,W,H,L) { Ut_Table(int X, int Y, int W, int H, const char *L=0)
: Fl_Table(X,Y,W,H,L) {
// Rows // Rows
rows(13); // how many rows rows(13); // how many rows
row_height_all(10); // default height of rows row_height_all(10); // default height of rows
@ -66,7 +67,7 @@ class MyTable : public Fl_Table {
col_width_all(10); // default width of columns col_width_all(10); // default width of columns
end(); // end the Fl_Table group end(); // end the Fl_Table group
} }
~MyTable() { } ~Ut_Table() { }
}; };
static const char *phonetics[] = { static const char *phonetics[] = {
@ -76,10 +77,10 @@ static const char *phonetics[] = {
"Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", NULL "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", NULL
}; };
class ScrollBarSizeTest : public Fl_Group { class Ut_Scrollbar_Size_Test : public Fl_Group {
Fl_Browser *brow_a, *brow_b, *brow_c; Fl_Browser *brow_a, *brow_b, *brow_c;
Fl_Tree *tree_a, *tree_b, *tree_c; Fl_Tree *tree_a, *tree_b, *tree_c;
MyTable *table_a,*table_b,*table_c; Ut_Table *table_a,*table_b,*table_c;
Fl_Text_Display *text_a, *text_b, *text_c; Fl_Text_Display *text_a, *text_b, *text_c;
Fl_Browser *makebrowser(int X,int Y,int W,int H,const char*L=0) { Fl_Browser *makebrowser(int X,int Y,int W,int H,const char*L=0) {
@ -102,8 +103,8 @@ class ScrollBarSizeTest : public Fl_Group {
} }
return(b); return(b);
} }
MyTable *maketable(int X,int Y,int W,int H,const char*L=0) { Ut_Table *maketable(int X,int Y,int W,int H,const char*L=0) {
MyTable *mta = new MyTable(X,Y,W,H,L); Ut_Table *mta = new Ut_Table(X,Y,W,H,L);
mta->align(FL_ALIGN_TOP); mta->align(FL_ALIGN_TOP);
mta->end(); mta->end();
return(mta); return(mta);
@ -133,16 +134,17 @@ class ScrollBarSizeTest : public Fl_Group {
in->window()->redraw(); in->window()->redraw();
} }
static void slide_cb(Fl_Widget *w, void *data) { static void slide_cb(Fl_Widget *w, void *data) {
ScrollBarSizeTest *o = (ScrollBarSizeTest*)data; Ut_Scrollbar_Size_Test *o = (Ut_Scrollbar_Size_Test*)data;
o->slide_cb2((Fl_Value_Slider*)w); o->slide_cb2((Fl_Value_Slider*)w);
} }
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return(new ScrollBarSizeTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H)); return(new Ut_Scrollbar_Size_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H));
} }
// CTOR // CTOR
ScrollBarSizeTest(int X, int Y, int W, int H) : Fl_Group(X,Y,W,H) { Ut_Scrollbar_Size_Test(int X, int Y, int W, int H)
: Fl_Group(X,Y,W,H) {
begin(); begin();
// _____________ _______________ // _____________ _______________
// |_____________| |_______________| // |_____________| |_______________|
@ -219,4 +221,4 @@ public:
} }
}; };
UnitTest scrollbarsize(kTestScrollbarsize, "Scrollbar Size", ScrollBarSizeTest::create); UnitTest scrollbarsize(UT_TEST_SCROLLBARSIZE, "Scrollbar Size", Ut_Scrollbar_Size_Test::create);

View File

@ -23,11 +23,11 @@
// //
//------- test the Fl_Simple_Terminal drawing capabilities ---------- //------- test the Fl_Simple_Terminal drawing capabilities ----------
// //
class SimpleTerminal : public Fl_Group { class Ut_Simple_Terminal_Test : public Fl_Group {
Fl_Simple_Terminal *tty1; Fl_Simple_Terminal *tty1;
Fl_Simple_Terminal *tty2; Fl_Simple_Terminal *tty2;
Fl_Simple_Terminal *tty3; Fl_Simple_Terminal *tty3;
void AnsiTestPattern(Fl_Simple_Terminal *tty) { void ansi_test_pattern(Fl_Simple_Terminal *tty) {
tty->append("\033[30mBlack Courier 14\033[0m Normal text\n" tty->append("\033[30mBlack Courier 14\033[0m Normal text\n"
"\033[31mRed Courier 14\033[0m Normal text\n" "\033[31mRed Courier 14\033[0m Normal text\n"
"\033[32mGreen Courier 14\033[0m Normal text\n" "\033[32mGreen Courier 14\033[0m Normal text\n"
@ -50,7 +50,7 @@ class SimpleTerminal : public Fl_Group {
"\033[41mRed\033[42mGreen\033[43mYellow\033[44mBlue\033[45mMagenta\033[46mCyan\033[47mWhite\033[0m - " "\033[41mRed\033[42mGreen\033[43mYellow\033[44mBlue\033[45mMagenta\033[46mCyan\033[47mWhite\033[0m - "
"\033[41mX\033[42mX\033[43mX\033[44mX\033[45mX\033[46mX\033[47mX\033[0m\n"); "\033[41mX\033[42mX\033[43mX\033[44mX\033[45mX\033[46mX\033[47mX\033[0m\n");
} }
void GrayTestPattern(Fl_Simple_Terminal *tty) { void gray_test_pattern(Fl_Simple_Terminal *tty) {
tty->append("Grayscale Test Pattern\n" tty->append("Grayscale Test Pattern\n"
"--------------------------\n" "--------------------------\n"
"\033[0m 100% white Courier 14\n" "\033[0m 100% white Courier 14\n"
@ -65,17 +65,18 @@ class SimpleTerminal : public Fl_Group {
"\033[9m 10% white Courier 14\n" "\033[9m 10% white Courier 14\n"
"\033[0m"); "\033[0m");
} }
static void DateTimer_CB(void *data) { static void date_timer_cb(void *data) {
Fl_Simple_Terminal *tty = (Fl_Simple_Terminal*)data; Fl_Simple_Terminal *tty = (Fl_Simple_Terminal*)data;
time_t lt = time(NULL); time_t lt = time(NULL);
tty->printf("The time and date is now: %s", ctime(&lt)); tty->printf("The time and date is now: %s", ctime(&lt));
Fl::repeat_timeout(3.0, DateTimer_CB, data); Fl::repeat_timeout(3.0, date_timer_cb, data);
} }
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new SimpleTerminal(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Simple_Terminal_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
SimpleTerminal(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Simple_Terminal_Test(int x, int y, int w, int h)
: Fl_Group(x, y, w, h) {
static Fl_Text_Display::Style_Table_Entry my_stable[] = { // 10 entry grayscale static Fl_Text_Display::Style_Table_Entry my_stable[] = { // 10 entry grayscale
// Font Color Font Face Font Size ANSI Sequence // Font Color Font Face Font Size ANSI Sequence
// ---------- ---------------- --------- ------------- // ---------- ---------------- --------- -------------
@ -98,23 +99,23 @@ public:
// TTY1 // TTY1
tty1 = new Fl_Simple_Terminal(x, tty_y1, w, tty_h,"Tty 1: ANSI off"); tty1 = new Fl_Simple_Terminal(x, tty_y1, w, tty_h,"Tty 1: ANSI off");
tty1->ansi(false); tty1->ansi(false);
Fl::add_timeout(0.5, DateTimer_CB, (void*)tty1); Fl::add_timeout(0.5, date_timer_cb, (void*)tty1);
// TTY2 // TTY2
tty2 = new Fl_Simple_Terminal(x, tty_y2, w, tty_h,"Tty 2: ANSI on"); tty2 = new Fl_Simple_Terminal(x, tty_y2, w, tty_h,"Tty 2: ANSI on");
tty2->ansi(true); tty2->ansi(true);
AnsiTestPattern(tty2); ansi_test_pattern(tty2);
Fl::add_timeout(0.5, DateTimer_CB, (void*)tty2); Fl::add_timeout(0.5, date_timer_cb, (void*)tty2);
// TTY3 // TTY3
tty3 = new Fl_Simple_Terminal(x, tty_y3, w, tty_h, "Tty 3: Grayscale Style Table"); tty3 = new Fl_Simple_Terminal(x, tty_y3, w, tty_h, "Tty 3: Grayscale Style Table");
tty3->style_table(my_stable, sizeof(my_stable), 0); tty3->style_table(my_stable, sizeof(my_stable), 0);
tty3->ansi(true); tty3->ansi(true);
GrayTestPattern(tty3); gray_test_pattern(tty3);
Fl::add_timeout(0.5, DateTimer_CB, (void*)tty3); Fl::add_timeout(0.5, date_timer_cb, (void*)tty3);
end(); end();
} }
}; };
UnitTest simple_terminal(kTestSimpleTerminal, "Simple Terminal", SimpleTerminal::create); UnitTest simple_terminal(UT_TEST_SIMPLE_TERMINAL, "Simple Terminal", Ut_Simple_Terminal_Test::create);

View File

@ -22,9 +22,9 @@
// //
// Test symbol rendering // Test symbol rendering
// //
class SymbolTest : public Fl_Widget class Ut_Symbol_Test : public Fl_Widget
{ {
void DrawTextAndBoxes(const char *txt, int X, int Y) { void draw_text_and_boxes(const char *txt, int X, int Y) {
int wo = 0, ho = 0; int wo = 0, ho = 0;
fl_measure(txt, wo, ho, 1); fl_measure(txt, wo, ho, 1);
// Draw fl_measure() rect // Draw fl_measure() rect
@ -46,9 +46,11 @@ class SymbolTest : public Fl_Widget
} }
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new SymbolTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Symbol_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
}
Ut_Symbol_Test(int x, int y, int w, int h)
: Fl_Widget(x, y, w, h) {
} }
SymbolTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
void draw(void) { void draw(void) {
int x0 = x(); // origin is current window position for Fl_Box int x0 = x(); // origin is current window position for Fl_Box
int y0 = y(); int y0 = y();
@ -63,22 +65,22 @@ public:
fl_font(FL_HELVETICA, fsize); fl_font(FL_HELVETICA, fsize);
int xx = x0+10; int xx = x0+10;
int yy = y0+10; int yy = y0+10;
DrawTextAndBoxes("Text" ,xx,yy); yy += fsize+10; // check no symbols draw_text_and_boxes("Text" ,xx,yy); yy += fsize+10; // check no symbols
DrawTextAndBoxes("@->" ,xx,yy); yy += fsize+10; // check symbol alone draw_text_and_boxes("@->" ,xx,yy); yy += fsize+10; // check symbol alone
DrawTextAndBoxes("@-> " ,xx,yy); yy += fsize+10; // check symbol with trailing space draw_text_and_boxes("@-> " ,xx,yy); yy += fsize+10; // check symbol with trailing space
DrawTextAndBoxes("@-> Rt Arrow" ,xx,yy); yy += fsize+10; // check symbol at left edge draw_text_and_boxes("@-> Rt Arrow" ,xx,yy); yy += fsize+10; // check symbol at left edge
DrawTextAndBoxes("Lt Arrow @<-" ,xx,yy); yy += fsize+10; // check symbol at right edge draw_text_and_boxes("Lt Arrow @<-" ,xx,yy); yy += fsize+10; // check symbol at right edge
DrawTextAndBoxes("@-> Rt/Lt @<-" ,xx,yy); yy += fsize+10; // check symbol at lt+rt edges draw_text_and_boxes("@-> Rt/Lt @<-" ,xx,yy); yy += fsize+10; // check symbol at lt+rt edges
DrawTextAndBoxes("@@ At/Lt @<-" ,xx,yy); yy += fsize+10; // check @@ at left, symbol at right draw_text_and_boxes("@@ At/Lt @<-" ,xx,yy); yy += fsize+10; // check @@ at left, symbol at right
DrawTextAndBoxes("@-> Lt/At @@" ,xx,yy); yy += fsize+10; // check symbol at left, @@ at right draw_text_and_boxes("@-> Lt/At @@" ,xx,yy); yy += fsize+10; // check symbol at left, @@ at right
DrawTextAndBoxes("@@ At/At @@" ,xx,yy); yy += fsize+10; // check @@ at left+right draw_text_and_boxes("@@ At/At @@" ,xx,yy); yy += fsize+10; // check @@ at left+right
xx = x0+200; xx = x0+200;
yy = y0+10; yy = y0+10;
DrawTextAndBoxes("Line1\nLine2" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, no symbol draw_text_and_boxes("Line1\nLine2" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, no symbol
DrawTextAndBoxes("@-> Line1\nLine2 @<-" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, lt+rt symbols draw_text_and_boxes("@-> Line1\nLine2 @<-" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, lt+rt symbols
DrawTextAndBoxes("@-> Line1\nLine2\nLine3 @<-",xx,yy); yy += (fsize+10)*3; // check 3 lines, lt+rt symbols draw_text_and_boxes("@-> Line1\nLine2\nLine3 @<-",xx,yy); yy += (fsize+10)*3; // check 3 lines, lt+rt symbols
DrawTextAndBoxes("@@@@" ,xx,yy); yy += (fsize+10); // check abutting @@'s draw_text_and_boxes("@@@@" ,xx,yy); yy += (fsize+10); // check abutting @@'s
DrawTextAndBoxes("@@ @@" ,xx,yy); yy += (fsize+10); // check @@'s with space sep draw_text_and_boxes("@@ @@" ,xx,yy); yy += (fsize+10); // check @@'s with space sep
fl_font(FL_HELVETICA, 14); fl_font(FL_HELVETICA, 14);
fl_color(FL_RED); fl_color(FL_RED);
@ -88,4 +90,4 @@ public:
} }
}; };
UnitTest symbolExtents(kTestSymbol, "Symbol Text", SymbolTest::create); UnitTest symbolExtents(UT_TEST_SYBOL, "Symbol Text", Ut_Symbol_Test::create);

View File

@ -26,11 +26,11 @@ static void cb_base_bt(Fl_Widget *bt, void*) {
bt->parent()->redraw(); bt->parent()->redraw();
} }
// //
class TextExtentsTest : public Fl_Group class Ut_Text_Extents_Test : public Fl_Group
{ {
Fl_Check_Button *base_bt; Fl_Check_Button *base_bt;
void DrawTextAndBoxes(const char *txt, int X, int Y) { void draw_text_and_boxes(const char *txt, int X, int Y) {
int wm = 0, hm = 0, wt = 0, ht = 0; int wm = 0, hm = 0, wt = 0, ht = 0;
int dx, dy; int dx, dy;
// measure text so we can draw the baseline first // measure text so we can draw the baseline first
@ -55,9 +55,9 @@ class TextExtentsTest : public Fl_Group
} }
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new TextExtentsTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Text_Extents_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
TextExtentsTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Text_Extents_Test(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
base_bt = new Fl_Check_Button(x + w - 150, 50, 130, 20, "Show Baseline"); base_bt = new Fl_Check_Button(x + w - 150, 50, 130, 20, "Show Baseline");
base_bt->box(FL_FLAT_BOX); base_bt->box(FL_FLAT_BOX);
base_bt->down_box(FL_DOWN_BOX); base_bt->down_box(FL_DOWN_BOX);
@ -83,12 +83,12 @@ public:
fl_font(FL_HELVETICA, 30); fl_font(FL_HELVETICA, 30);
int xx = x0+55; int xx = x0+55;
int yy = y0+40; int yy = y0+40;
DrawTextAndBoxes("!abcdeABCDE\"#A", xx, yy); yy += 50; // mixed string draw_text_and_boxes("!abcdeABCDE\"#A", xx, yy); yy += 50; // mixed string
DrawTextAndBoxes("oacs", xx, yy); xx += 100; // small glyphs draw_text_and_boxes("oacs", xx, yy); xx += 100; // small glyphs
DrawTextAndBoxes("qjgIPT", xx, yy); yy += 50; xx -= 100; // glyphs with descenders draw_text_and_boxes("qjgIPT", xx, yy); yy += 50; xx -= 100; // glyphs with descenders
DrawTextAndBoxes("````````", xx, yy); yy += 50; // high small glyphs draw_text_and_boxes("````````", xx, yy); yy += 50; // high small glyphs
DrawTextAndBoxes("--------", xx, yy); yy += 50; // mid small glyphs draw_text_and_boxes("--------", xx, yy); yy += 50; // mid small glyphs
DrawTextAndBoxes("________", xx, yy); yy += 50; // low small glyphs draw_text_and_boxes("________", xx, yy); yy += 50; // low small glyphs
fl_font(FL_HELVETICA, 14); fl_font(FL_HELVETICA, 14);
fl_color(FL_RED); fl_draw("fl_measure bounding box in RED", xx, yy); yy += 20; fl_color(FL_RED); fl_draw("fl_measure bounding box in RED", xx, yy); yy += 20;
@ -104,4 +104,4 @@ public:
} }
}; };
UnitTest textExtents(kTestText, "Rendering Text", TextExtentsTest::create); UnitTest textExtents(UT_TEST_TEXT, "Rendering Text", Ut_Text_Extents_Test::create);

View File

@ -45,7 +45,7 @@ static const char *helptext =
"be visible and not touching. All the above should be unaffected " "be visible and not touching. All the above should be unaffected "
"by different font sizes and font settings."; "by different font sizes and font settings.";
class UnicodeBoxTest : public Fl_Group { class Ut_Unicode_Box_Test : public Fl_Group {
Fl_Text_Buffer *textbuffer; Fl_Text_Buffer *textbuffer;
Fl_Text_Display *textdisplay; Fl_Text_Display *textdisplay;
Fl_Multiline_Input *multilineinput; Fl_Multiline_Input *multilineinput;
@ -53,20 +53,20 @@ class UnicodeBoxTest : public Fl_Group {
Fl_Hor_Value_Slider *fontsize_slider; Fl_Hor_Value_Slider *fontsize_slider;
// Font choice callback // Font choice callback
void FontChoice_CB2() { void font_choice_cb2() {
switch ( font_choice->value() ) { switch ( font_choice->value() ) {
case 0: textdisplay->textfont(FL_COURIER); break; case 0: textdisplay->textfont(FL_COURIER); break;
case 1: textdisplay->textfont(FL_SCREEN); break; case 1: textdisplay->textfont(FL_SCREEN); break;
} }
parent()->redraw(); parent()->redraw();
} }
static void FontChoice_CB(Fl_Widget*, void *userdata) { static void foant_choice_cb(Fl_Widget*, void *userdata) {
UnicodeBoxTest *o = (UnicodeBoxTest*)userdata; Ut_Unicode_Box_Test *o = (Ut_Unicode_Box_Test*)userdata;
o->FontChoice_CB2(); o->font_choice_cb2();
} }
// Slider callback - apply new font size to widgets // Slider callback - apply new font size to widgets
void FontSizeSlider_CB2() { void font_size_slider_cb2() {
// Get font size from slider value, apply to widgets // Get font size from slider value, apply to widgets
int fontsize = (int)fontsize_slider->value(); int fontsize = (int)fontsize_slider->value();
textdisplay->textsize(fontsize); textdisplay->textsize(fontsize);
@ -74,17 +74,17 @@ class UnicodeBoxTest : public Fl_Group {
multilineinput->position(0); // keep scrolled to top multilineinput->position(0); // keep scrolled to top
parent()->redraw(); parent()->redraw();
} }
static void FontSizeSlider_CB(Fl_Widget*, void *userdata) { static void font_size_slider_cb(Fl_Widget*, void *userdata) {
UnicodeBoxTest *o = (UnicodeBoxTest*)userdata; Ut_Unicode_Box_Test *o = (Ut_Unicode_Box_Test*)userdata;
o->FontSizeSlider_CB2(); o->font_size_slider_cb2();
} }
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new UnicodeBoxTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Unicode_Box_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
UnicodeBoxTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { Ut_Unicode_Box_Test(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
// Fl_Text_Display // Fl_Text_Display
textbuffer = new Fl_Text_Buffer(); textbuffer = new Fl_Text_Buffer();
textbuffer->text(utf8_box_test); textbuffer->text(utf8_box_test);
@ -104,16 +104,16 @@ public:
font_choice->add("FL_COURIER"); font_choice->add("FL_COURIER");
font_choice->add("FL_SCREEN"); font_choice->add("FL_SCREEN");
font_choice->value(0); font_choice->value(0);
font_choice->callback(FontChoice_CB, (Fl_Widget*)this); font_choice->callback(foant_choice_cb, (Fl_Widget*)this);
// Font size slider // Font size slider
fontsize_slider = new Fl_Hor_Value_Slider(x+150, y+h-50, 200, 25, "Font size"); fontsize_slider = new Fl_Hor_Value_Slider(x+150, y+h-50, 200, 25, "Font size");
fontsize_slider->align(FL_ALIGN_LEFT); fontsize_slider->align(FL_ALIGN_LEFT);
fontsize_slider->range(1.0, 50.0); fontsize_slider->range(1.0, 50.0);
fontsize_slider->step(1.0); fontsize_slider->step(1.0);
fontsize_slider->value(14.0); fontsize_slider->value(14.0);
fontsize_slider->callback(FontSizeSlider_CB, (Fl_Widget*)this); fontsize_slider->callback(font_size_slider_cb, (Fl_Widget*)this);
end(); end();
} }
}; };
UnitTest unicode_font_test(kUnicodeBoxTest, "Unicode Boxes", UnicodeBoxTest::create); UnitTest unicode_font_test(UT_TEST_UNICODE, "Unicode Boxes", Ut_Unicode_Box_Test::create);

View File

@ -22,12 +22,12 @@
// //
//------- test viewport clipping ---------- //------- test viewport clipping ----------
// //
class ViewportTest : public Fl_Box { class Ut_Viewport_Test : public Fl_Box {
public: public:
static Fl_Widget *create() { static Fl_Widget *create() {
return new ViewportTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H); return new Ut_Viewport_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
} }
ViewportTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { Ut_Viewport_Test(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("Testing Viewport Alignment\n\n" label("Testing Viewport Alignment\n\n"
"Only green lines should be visible.\n" "Only green lines should be visible.\n"
"If red lines are visible in the corners of this window,\n" "If red lines are visible in the corners of this window,\n"
@ -40,12 +40,12 @@ public:
} }
void show() { void show() {
Fl_Box::show(); Fl_Box::show();
mainwin->testAlignment(1); mainwin->test_alignment(1);
} }
void hide() { void hide() {
Fl_Box::hide(); Fl_Box::hide();
mainwin->testAlignment(0); mainwin->test_alignment(0);
} }
}; };
UnitTest viewport(kTestViewport, "Viewport Test", ViewportTest::create); UnitTest viewport(UT_TEST_VIEWPORT, "Viewport Test", Ut_Viewport_Test::create);

View File

@ -31,99 +31,99 @@
#include <FL/Fl_Help_View.H> #include <FL/Fl_Help_View.H>
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/fl_draw.H> // fl_text_extents() #include <FL/fl_draw.H> // fl_text_extents()
#include <FL/fl_string_functions.h> // fl_strdup() #include <FL/fl_string_functions.h> // fl_strdup()
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
class MainWindow *mainwin = 0; class Ut_Main_Window *mainwin = NULL;
class Fl_Hold_Browser *browser = 0; class Fl_Hold_Browser *browser = NULL;
UnitTest::UnitTest(int index, const char *label, Fl_Widget* (*create)()) : int UnitTest::num_tests_ = 0;
fWidget(0L) UnitTest *UnitTest::test_list_[200] = { 0 };
UnitTest::UnitTest(int index, const char* label, Fl_Widget* (*create)())
: widget_(0L)
{ {
fLabel = fl_strdup(label); label_ = fl_strdup(label);
fCreate = create; create_ = create;
add(index, this); add(index, this);
} }
UnitTest::~UnitTest() { UnitTest::~UnitTest() {
delete fWidget; delete widget_;
free(fLabel); free(label_);
} }
const char *UnitTest::label() { const char *UnitTest::label() {
return fLabel; return label_;
} }
void UnitTest::create() { void UnitTest::create() {
fWidget = fCreate(); widget_ = create_();
if (fWidget) fWidget->hide(); if (widget_) widget_->hide();
} }
void UnitTest::show() { void UnitTest::show() {
if (fWidget) fWidget->show(); if (widget_) widget_->show();
} }
void UnitTest::hide() { void UnitTest::hide() {
if (fWidget) fWidget->hide(); if (widget_) widget_->hide();
} }
void UnitTest::add(int index, UnitTest *t) { void UnitTest::add(int index, UnitTest* t) {
fTest[index] = t; test_list_[index] = t;
if (index>=nTest) if (index >= num_tests_)
nTest = index+1; num_tests_ = index+1;
} }
int UnitTest::nTest = 0; Ut_Main_Window::Ut_Main_Window(int w, int h, const char *l)
UnitTest *UnitTest::fTest[200] = { 0 }; : Fl_Double_Window(w, h, l),
draw_alignment_test_(0)
MainWindow::MainWindow(int w, int h, const char *l) :
Fl_Double_Window(w, h, l),
fTestAlignment(0)
{ } { }
void MainWindow::drawAlignmentIndicators() { void Ut_Main_Window::draw_alignment_indicators() {
const int sze = 16; const int SZE = 16;
// top left corner // top left corner
fl_color(FL_GREEN); fl_yxline(0, sze, 0, sze); fl_color(FL_GREEN); fl_yxline(0, SZE, 0, SZE);
fl_color(FL_RED); fl_yxline(-1, sze, -1, 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_WHITE); fl_rectf(3, 3, SZE-2, SZE-2);
fl_color(FL_BLACK); fl_rect(3, 3, sze-2, sze-2); fl_color(FL_BLACK); fl_rect(3, 3, SZE-2, SZE-2);
// bottom left corner // bottom left corner
fl_color(FL_GREEN); fl_yxline(0, h()-sze-1, h()-1, sze); 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_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_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); fl_color(FL_BLACK); fl_rect(3, h()-SZE-1, SZE-2, SZE-2);
// bottom right corner // bottom right corner
fl_color(FL_GREEN); fl_yxline(w()-1, h()-sze-1, h()-1, w()-sze-1); 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_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_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); fl_color(FL_BLACK); fl_rect(w()-SZE-1, h()-SZE-1, SZE-2, SZE-2);
// top right corner // top right corner
fl_color(FL_GREEN); fl_yxline(w()-1, sze, 0, w()-sze-1); 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_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_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); fl_color(FL_BLACK); fl_rect(w()-SZE-1, 3, SZE-2, SZE-2);
} }
void MainWindow::draw() { void Ut_Main_Window::draw() {
Fl_Double_Window::draw(); Fl_Double_Window::draw();
if (fTestAlignment) { if (draw_alignment_test_) {
drawAlignmentIndicators(); draw_alignment_indicators();
} }
} }
void MainWindow::testAlignment(int v) { void Ut_Main_Window::test_alignment(int v) {
fTestAlignment = v; draw_alignment_test_ = v;
redraw(); redraw();
} }
//------- include the various unit tests as inline code ------- //------- include the various unit tests as inline code -------
// callback whenever the browser value changes // callback whenever the browser value changes
void Browser_CB(Fl_Widget*, void*) { void UT_BROWSER_CB(Fl_Widget*, void*) {
for ( int t=1; t<=browser->size(); t++ ) { for ( int t=1; t<=browser->size(); t++ ) {
UnitTest *ti = (UnitTest*)browser->data(t); UnitTest* ti = (UnitTest*)browser->data(t);
if ( browser->selected(t) ) { if ( browser->selected(t) ) {
ti->show(); ti->show();
} else { } else {
@ -135,22 +135,22 @@ void Browser_CB(Fl_Widget*, void*) {
// This is the main call. It creates the window and adds all previously // This is the main call. It creates the window and adds all previously
// registered tests to the browser widget. // registered tests to the browser widget.
int main(int argc, char **argv) { int main(int argc, char** argv) {
Fl::args(argc,argv); Fl::args(argc, argv);
Fl::get_system_colors(); Fl::get_system_colors();
Fl::scheme(Fl::scheme()); // init scheme before instantiating tests Fl::scheme(Fl::scheme()); // init scheme before instantiating tests
Fl::visual(FL_RGB); Fl::visual(FL_RGB);
Fl::use_high_res_GL(1); Fl::use_high_res_GL(1);
mainwin = new MainWindow(MAINWIN_W, MAINWIN_H, "FLTK Unit Tests"); mainwin = new Ut_Main_Window(UT_MAINWIN_W, UT_MAINWIN_H, "FLTK Unit Tests");
mainwin->size_range(MAINWIN_W, MAINWIN_H); mainwin->size_range(UT_MAINWIN_W, UT_MAINWIN_H);
browser = new Fl_Hold_Browser(BROWSER_X, BROWSER_Y, BROWSER_W, BROWSER_H, "Unit Tests"); browser = new Fl_Hold_Browser(UT_BROWSER_X, UT_BROWSER_Y, UT_BROWSER_W, UT_BROWSER_H, "Unit Tests");
browser->align(FL_ALIGN_TOP|FL_ALIGN_LEFT); browser->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
browser->when(FL_WHEN_CHANGED); browser->when(FL_WHEN_CHANGED);
browser->callback(Browser_CB); browser->callback(UT_BROWSER_CB);
int i, n = UnitTest::numTest(); int i, n = UnitTest::num_tests();
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
UnitTest *t = UnitTest::test(i); UnitTest* t = UnitTest::test(i);
if (t) { if (t) {
mainwin->begin(); mainwin->begin();
t->create(); t->create();
@ -160,9 +160,9 @@ int main(int argc, char **argv) {
} }
mainwin->resizable(mainwin); mainwin->resizable(mainwin);
mainwin->show(argc,argv); mainwin->show(argc, argv);
// Select first test in browser, and show that test. // Select first test in browser, and show that test.
browser->select(kTestAbout+1); browser->select(UT_TEST_ABOUT+1);
Browser_CB(browser,0); UT_BROWSER_CB(browser, 0);
return(Fl::run()); return Fl::run();
} }

View File

@ -21,36 +21,36 @@
#include <FL/Fl_Double_Window.H> #include <FL/Fl_Double_Window.H>
// WINDOW/WIDGET SIZES // WINDOW/WIDGET SIZES
#define MAINWIN_W 700 // main window w() const int UT_MAINWIN_W = 700; // main window w()
#define MAINWIN_H 400 // main window h() const int UT_MAINWIN_H = 400; // main window h()
#define BROWSER_X 10 // browser x() const int UT_BROWSER_X = 10; // browser x()
#define BROWSER_Y 25 // browser y() const int UT_BROWSER_Y = 25; // browser y()
#define BROWSER_W 150 // browser w() const int UT_BROWSER_W = 150; // browser w()
#define BROWSER_H MAINWIN_H-35 // browser h() const int UT_BROWSER_H = (UT_MAINWIN_H-35); // browser h()
#define TESTAREA_X (BROWSER_W + 20) // test area x() const int UT_TESTAREA_X = (UT_BROWSER_W + 20); // test area x()
#define TESTAREA_Y 25 // test area y() const int UT_TESTAREA_Y = 25; // test area y()
#define TESTAREA_W (MAINWIN_W - BROWSER_W - 30) // test area w() const int UT_TESTAREA_W = (UT_MAINWIN_W - UT_BROWSER_W - 30); // test area w()
#define TESTAREA_H BROWSER_H // test area h() const int UT_TESTAREA_H = UT_BROWSER_H; // test area h()
typedef void (*UnitTestCallback)(const char*, class Fl_Group*); typedef void (*UnitTestCallback)(const char*, class Fl_Group*);
extern class MainWindow *mainwin; extern class Ut_Main_Window* mainwin;
extern class Fl_Hold_Browser *browser; extern class Fl_Hold_Browser* browser;
enum { enum {
kTestAbout = 0, UT_TEST_ABOUT = 0,
kTestPoints, UT_TEST_POINTS,
kTestFastShapes, UT_TEST_FAST_SHAPES,
kTestCircles, UT_TEST_CIRCLES,
kTestComplexShapes, UT_TEST_COMPLEX_SHAPES,
kTestText, UT_TEST_TEXT,
kUnicodeBoxTest, UT_TEST_UNICODE,
kTestSymbol, UT_TEST_SYBOL,
kTestImages, UT_TEST_IMAGES,
kTestViewport, UT_TEST_VIEWPORT,
kTestScrollbarsize, UT_TEST_SCROLLBARSIZE,
kTestSchemes, UT_TEST_SCHEMES,
kTestSimpleTerminal UT_TEST_SIMPLE_TERMINAL
}; };
// This class helps to automatically register a new test with the unittest app. // This class helps to automatically register a new test with the unittest app.
@ -59,30 +59,31 @@ class UnitTest {
public: public:
UnitTest(int index, const char *label, Fl_Widget* (*create)()); UnitTest(int index, const char *label, Fl_Widget* (*create)());
~UnitTest(); ~UnitTest();
const char *label(); const char* label();
void create(); void create();
void show(); void show();
void hide(); void hide();
static int numTest() { return nTest; } static int num_tests() { return num_tests_; }
static UnitTest *test(int i) { return fTest[i]; } static UnitTest* test(int i) { return test_list_[i]; }
private: private:
char *fLabel; char* label_;
Fl_Widget *(*fCreate)(); Fl_Widget* (*create_)();
Fl_Widget *fWidget; Fl_Widget* widget_;
static void add(int index, UnitTest *t); static void add(int index, UnitTest* t);
static int nTest; static int num_tests_;
static UnitTest *fTest[]; static UnitTest* test_list_[];
}; };
// The main window needs an additional drawing feature in order to support // The main window needs an additional drawing feature in order to support
// the viewport alignment test. // the viewport alignment test.
class MainWindow : public Fl_Double_Window { class Ut_Main_Window : public Fl_Double_Window {
public: public:
MainWindow(int w, int h, const char *l=0L); Ut_Main_Window(int w, int h, const char *l=0L);
void drawAlignmentIndicators(); void draw_alignment_indicators();
void draw(); void draw();
void testAlignment(int v); void test_alignment(int v);
int fTestAlignment; private:
int draw_alignment_test_;
}; };
#endif #endif