Backported FLTK 1.3 unit tests to FLTK 1.1 as far as possible.

Missing tests: scrollbar size and text extents.
These tests would require some new features of FLTK 1.3.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@8610 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2011-04-20 13:45:35 +00:00
parent d91c285921
commit c45fa0f1d8
8 changed files with 789 additions and 248 deletions

69
test/unittest_about.cxx Executable file
View File

@ -0,0 +1,69 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Help_View.H>
//
//------- Introduction to FLTK drawing test -------
//
class About : public Fl_Help_View {
public:
static Fl_Widget *create() {
return new About(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
About(int x, int y, int w, int h) : Fl_Help_View(x, y, w, h) {
value(
"<htmL><body><h2>About Unit Testing...</h2>\n"
"The Unit Testing application can be used to verify correct graphics rendering "
"on the current platform. The core developer team uses this program to make sure that the "
"FLTK user experience is identical on all supported graphics systems."
"<h3>the UI Designer</h3>\n"
"<p>Designing a good user interface is an art. Widgets must be selected and carefully positioned "
"to create a consistent look and feel for the user. Text must fit into given boxes and graphic "
"elements must be correctly aligned. A good UI library will give consistent results on any "
"supported platform and render all graphics in the way the UI designer intended.</p>\n"
"<p>FLTK supports a large collection of platforms and graphics drivers. This unit testing "
"application contains modules which will test rendering and alignment for most "
"FLTK core graphics functions.</p>\n"
"<h3>the Developer</h3>\n"
"<p>Unittest is also a great help when implementing new graphics drivers. The tests are sorted "
"in the same order in which a new graphics driver could be implemented. Most tests rely "
"on the previous test to function correctly, so sticking to the given order is a good idea.</p>\n"
"<h3>Conventions</h3>\n"
"<p>Two layers of graphics are drawn for most tests. The lower layer contains "
"red and green pixels. The upper layer contains black pixels. The test is rendered correctly "
"if all red pixels are covered, but none of the green pixels. The top graphics layer can be "
"switched on and off.</p>"
"</body></html>");
}
};
UnitTest about("About...", About::create);
//
// End of "$Id$".
//

99
test/unittest_circles.cxx Executable file
View File

@ -0,0 +1,99 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
//
//------- test the circle drawing capabilities of this implementation ----------
//
class CircleTest : public Fl_Box {
public:
static Fl_Widget *create() {
return new CircleTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
CircleTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("testing int drawing of circles and ovals (fl_arc, fl_pie)\n"
"No red lines should be visible. "
"If you see bright red pixels, the circle drawing alignment is off. "
"If you see dark red pixels, your system supports anti-aliasing "
"which should be of no concern. "
"The green rectangles should not be overwritten by circle drawings.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void draw() {
Fl_Box::draw();
int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
// test fl_arc for full circles
fl_color(FL_GREEN); fl_rect(a+ 9, b+ 9, 33, 33);
fl_color(FL_RED); fl_xyline(a+24, b+10, a+27); fl_xyline(a+24, b+40, a+27);
fl_yxline(a+10, b+24, b+27); fl_yxline(a+40, b+24, b+27);
fl_color(FL_BLACK); fl_arc(a+10, b+10, 31, 31, 0.0, 360.0);
// test fl_arc segmet 1
fl_color(FL_GREEN); fl_rect(a+54, b+ 4, 43, 43);
fl_rect(a+54, b+4, 18, 18); fl_rect(a+79, b+29, 18, 18);
fl_color(FL_RED); fl_point(a+55, b+30); fl_point(a+70, b+45);
fl_point(a+80, b+5); fl_point(a+95, b+20);
fl_color(FL_BLACK); fl_arc(a+65, b+ 5, 31, 31, -35.0, 125.0);
// test fl_arc segmet 2
fl_color(FL_BLACK); fl_arc(a+55, b+15, 31, 31, 145.0, 305.0);
// test fl_pie for full circles
fl_color(FL_RED); fl_xyline(a+24, b+60, a+27); fl_xyline(a+24, b+90, a+27);
fl_yxline(a+10, b+74, b+77); fl_yxline(a+40, b+74, b+77);
fl_color(FL_GREEN); fl_rect(a+ 9, b+59, 33, 33);
fl_color(FL_BLACK); fl_pie(a+10, b+60, 31, 31, 0.0, 360.0);
// test fl_pie segmet 1
fl_color(FL_GREEN); fl_rect(a+54, b+54, 43, 43);
fl_rect(a+54, b+54, 18, 18); fl_rect(a+79, b+79, 18, 18);
fl_point(a+79, b+71); fl_point(a+71, b+79);
fl_color(FL_RED); fl_point(a+55, b+80); fl_point(a+70, b+95);
fl_point(a+80, b+55); fl_point(a+95, b+70);
fl_point(a+81, b+69); fl_point(a+69, b+81);
fl_color(FL_BLACK); fl_pie(a+65, b+55, 31, 31, -30.0, 120.0);
// test fl_pie segmet 2
fl_color(FL_BLACK); fl_pie(a+55, b+65, 31, 31, 150.0, 300.0);
//---- oval testing (horizontal squish)
a +=120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
fl_color(FL_GREEN);
fl_rect(a+19, b+9, 63, 33); fl_rect(a+19, b+59, 63, 33);
fl_color(FL_BLACK);
fl_arc(a+20, b+10, 61, 31, 0, 360); fl_pie(a+20, b+60, 61, 31, 0, 360);
//---- oval testing (horizontal squish)
a += 120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
fl_color(FL_GREEN);
fl_rect(a+9, b+19, 33, 63); fl_rect(a+59, b+19, 33, 63);
fl_color(FL_BLACK);
fl_arc(a+10, b+20, 31, 61, 0, 360); fl_pie(a+60, b+20, 31, 61, 0, 360);
}
};
UnitTest circle("circles and arcs", CircleTest::create);
//
// End of "$Id$"
//

177
test/unittest_images.cxx Executable file
View File

@ -0,0 +1,177 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
// Note: currently (March 2010) fl_draw_image() supports transparency with
// alpha channel only on Apple (Mac OS X), but Fl_RGB_Image->draw()
// supports transparency on all platforms !
//
//------- test the image drawing capabilities of this implementation ----------
//
// Some parameters for fine tuning for developers - their
// default values ought to be: CB=1, DX=0, LX=0, IMG=1
#define CB (1) // 1 to show the checker board background for alpha images, 0 otherwise
#define DX (0) // additional (undefined (0)) pixels per line, must be >= 0
// ignored (irrelevant), if LX == 0 (see below)
#define LX (0) // 0 for default: ld() = 0, i.e. ld() defaults (internally) to w()*d()
// +1: ld() = (w() + DX) * d()
// -1 to flip image vertically: ld() = - ((w() + DX) * d())
#define IMG (1) // 1 to use Fl_RGB_Image for drawing images,
// 0 to use fl_draw_image() instead.
// Note: as of April 2011, only 1 (Fl_RGB_Image) works correctly with alpha
// channel, 0 (fl_draw_image()) ignores the alpha channel (FLTK 1.3.0).
// There are plans to support alpha in fl_draw_image() in FLTK 1.3.x,
// but not in FLTK 1.1.x .
class ImageTest : public Fl_Box {
public:
static Fl_Widget *create() {
int x, y;
uchar *dg, *dga, *drgb, *drgba;
dg = img_gray = (uchar*)malloc((128+DX)*128*1);
dga = img_gray_a = (uchar*)malloc((128+DX)*128*2);
drgb = img_rgb = (uchar*)malloc((128+DX)*128*3);
drgba = img_rgba = (uchar*)malloc((128+DX)*128*4);
for (y=0; y<128; y++) {
for (x=0; x<128; x++) {
*drgba++ = *drgb++ = *dga++ = *dg++ = y<<1;
*drgba++ = *drgb++ = x<<1;
*drgba++ = *drgb++ = (127-x)<<1;
*drgba++ = *dga++ = x+y;
}
if (DX > 0 && LX != 0) {
memset(dg, 0,1*DX); dg += 1*DX;
memset(dga, 0,2*DX); dga += 2*DX;
memset(drgb, 0,3*DX); drgb += 3*DX;
memset(drgba,0,4*DX); drgba += 4*DX;
}
}
if (LX<0) {
img_gray += 127*(128+DX);
img_gray_a += 127*(128+DX)*2;
img_rgb += 127*(128+DX)*3;
img_rgba += 127*(128+DX)*4;
}
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_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);
return new ImageTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
static uchar *img_gray;
static uchar *img_gray_a;
static uchar *img_rgb;
static uchar *img_rgba;
static Fl_RGB_Image *i_g;
static Fl_RGB_Image *i_ga;
static Fl_RGB_Image *i_rgb;
static Fl_RGB_Image *i_rgba;
ImageTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("Testing Image Drawing\n\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. This does not test any image formats such as JPEG.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void draw() {
Fl_Box::draw();
// top left: RGB
int xx = x()+10, yy = y()+10;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130);
#if IMG
i_rgb->draw(xx+1,yy+1);
#else
fl_draw_image(img_rgb, xx+1, yy+1, 128, 128, 3, LX*((128+DX)*3));
#endif
fl_draw("RGB", xx+134, yy+64);
// bottom left: RGBA
xx = x()+10; yy = y()+10+134;
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
#if CB // checker board
fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64);
fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64);
#endif
#if IMG
i_rgba->draw(xx+1,yy+1);
#else
fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4, LX*((128+DX)*4));
#endif
fl_color(FL_BLACK); fl_draw("RGBA", xx+134, yy+64);
// top right: Gray
xx = x()+10+200; yy = y()+10;
fl_color(FL_BLACK); fl_rect(xx, yy, 130, 130);
#if IMG
i_g->draw(xx+1,yy+1);
#else
fl_draw_image(img_gray, xx+1, yy+1, 128, 128, 1, LX*((128+DX)*1));
#endif
fl_draw("Gray", xx+134, yy+64);
// bottom right: Gray+Alpha
xx = x()+10+200; yy = y()+10+134;
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
#if CB // checker board
fl_color(FL_BLACK); fl_rectf(xx+65, yy+1, 64, 64);
fl_color(FL_BLACK); fl_rectf(xx+1, yy+65, 64, 64);
#endif
#if IMG
i_ga->draw(xx+1,yy+1);
#else
fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2, LX*((128+DX)*2));
#endif
fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64);
}
};
uchar *ImageTest::img_gray = 0;
uchar *ImageTest::img_gray_a = 0;
uchar *ImageTest::img_rgb = 0;
uchar *ImageTest::img_rgba = 0;
Fl_RGB_Image *ImageTest::i_g = 0;
Fl_RGB_Image *ImageTest::i_ga = 0;
Fl_RGB_Image *ImageTest::i_rgb = 0;
Fl_RGB_Image *ImageTest::i_rgba = 0;
UnitTest images("drawing images", ImageTest::create);
//
// End of "$Id$"
//

75
test/unittest_lines.cxx Executable file
View File

@ -0,0 +1,75 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
//
//------- test the line drawing capabilities of this implementation ----------
//
class LineTest : public Fl_Box {
public:
static Fl_Widget *create() {
return new LineTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
LineTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("testing the integer based fl_line calls\n"
"No red pixels should be visible.\n"
"If you see bright red pixels, the line drawing alignment is off,\n"
"or the last pixel in a line does not get drawn.\n"
"If you see dark red pixels, anti-aliasing must be switched off.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void draw() {
Fl_Box::draw();
int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
// testing fl_xyline(x, y, x1)
fl_color(FL_RED); fl_point(a+10, b+10); fl_point(a+20, b+10);
fl_color(FL_BLACK); fl_xyline(a+10, b+10, a+20);
// testing fl_xyline(x, y, x1, y2);
fl_color(FL_RED); fl_point(a+10, b+20); fl_point(a+20, b+20);
fl_point(a+20, b+30);
fl_color(FL_BLACK); fl_xyline(a+10, b+20, a+20, b+30);
// testing fl_xyline(x, y, x1, y2, x3);
fl_color(FL_RED); fl_point(a+10, b+40); fl_point(a+20, b+40);
fl_point(a+20, b+50); fl_point(a+30, b+50);
fl_color(FL_BLACK); fl_xyline(a+10, b+40, a+20, b+50, a+30);
//+++ add testing for the fl_yxline commands!
// testing fl_loop(x,y, x,y, x,y, x, y)
fl_color(FL_RED); fl_point(a+60, b+60); fl_point(a+90, b+60);
fl_point(a+60, b+90); fl_point(a+90, b+90);
fl_color(FL_BLACK);
fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90);
}
};
UnitTest lines("drawing lines", LineTest::create);
//
// End of "$Id$"
//

69
test/unittest_points.cxx Executable file
View File

@ -0,0 +1,69 @@
//
// "$Id$:
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
//
//------- test the point drawing capabilities of this implementation ----------
//
class PointTest : public Fl_Box {
public:
static Fl_Widget *create() {
return new PointTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
PointTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("testing the fl_point call\n"
"You should see four pixels each in black, red, green and blue. "
"Make sure that pixels are not anti-aliased (blurred across multiple pixels)!");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void draw() {
Fl_Box::draw();
int a = x()+10, b = y()+10;
fl_color(FL_WHITE); fl_rectf(a, b, 90, 90);
fl_color(FL_BLACK); fl_rect(a, b, 90, 90);
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_RED); a = x()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_GREEN); a = x()+10; b = y()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_BLUE); a = x()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
}
};
UnitTest points("drawing points", PointTest::create);
//
// End of "$Id$"
//

66
test/unittest_rects.cxx Executable file
View File

@ -0,0 +1,66 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H> // fl_text_extents()
//
//------- test the rectangle drawing capabilities of this implementation ----------
//
class RectTest : public Fl_Box {
public:
static Fl_Widget *create() {
return new RectTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
RectTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("testing the fl_rect call\n"
"No red pixels should be visible. "
"If you see bright red lines, or if parts of the green frames are hidden, "
"the rect drawing alignment is off.");
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void draw() {
Fl_Box::draw();
int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
// testing fl_rect() with positive size
fl_color(FL_RED); fl_loop(a+10, b+10, a+40, b+10, a+40, b+40, a+10, b+40);
fl_color(FL_GREEN); fl_loop(a+ 9, b+ 9, a+41, b+ 9, a+41, b+41, a+ 9, b+41);
fl_color(FL_GREEN); fl_loop(a+11, b+11, a+39, b+11, a+39, b+39, a+11, b+39);
fl_color(FL_BLACK); fl_rect(a+10, b+10, 31, 31);
// testing fl_rect() with positive size
fl_color(FL_RED); fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90);
fl_color(FL_GREEN); fl_loop(a+59, b+59, a+91, b+59, a+91, b+91, a+59, b+91);
fl_color(FL_BLACK); fl_rectf(a+60, b+60, 31, 31);
}
};
UnitTest rects("rectangles", RectTest::create);
//
// End of "$Id$"
//

76
test/unittest_viewport.cxx Executable file
View File

@ -0,0 +1,76 @@
//
// "$Id$"
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2011 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
//
//------- test viewport clipping ----------
//
class ViewportTest : public Fl_Box {
public:
static Fl_Widget *create() {
return new ViewportTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
}
ViewportTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
label("Testing Viewport Alignment\n\n"
"Only green lines should be visible.\n"
"If red lines are visible in the corners of this window,\n"
"your viewport alignment and clipping is off.\n"
"If there is a space between the green lines and the window border,\n"
"the viewport is off, but some clipping may be working.\n"
"Also, your window size may be off to begin with.");
align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_WRAP);
box(FL_BORDER_BOX);
}
void show() {
Fl_Box::show();
mainwin->testAlignment(1);
}
void hide() {
Fl_Box::hide();
mainwin->testAlignment(0);
}
#if (FL_MAJOR_VERSION==1) && (FL_MINOR_VERSION==1)
// show() and hide() are not virtual in FLTK 1.1, hence we must use handle()...
int handle(int e) {
if (e == FL_SHOW)
mainwin->testAlignment(1);
else if (e == FL_HIDE)
mainwin->testAlignment(0);
else
return Fl_Box::handle(e);
return 1;
}
#endif
};
UnitTest viewport("viewport test", ViewportTest::create);
//
// End of "$Id$
//

View File

@ -3,7 +3,7 @@
//
// Unit tests for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
// Copyright 1998-2011 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -24,275 +24,185 @@
//
// http://www.fltk.org/str.php
//
// Fltk unit tests
// v0.1 - Greg combines Matthias + Ian's tests
// v0.2 - Ian's 02/12/09 fixes applied
// v0.3 - Fixes to circle desc, augmented extent tests, fixed indents, added show(argc,argv)
// v1.0 - Submit for svn
// v1.1 - Matthias separated all tests into multiple source files for hopefully easier handling
// v1.1 - Albrecht reordered tests, backported FLTK 1.3 tests to FLTK 1.1 as far as possible
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Hold_Browser.H>
#include <FL/Fl_Help_View.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <FL/fl_draw.H> // fl_text_extents()
Fl_Window *win = 0;
#include <stdlib.h> // malloc, free
#include <string.h> // strdup, ...
int point_test_ix, line_test_ix, rect_test_ix, viewport_test_ix, circle_test_ix;
// 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()
void changePageCB(Fl_Widget*, void *ixvp) {
long ix = (long)ixvp;
long i = 0, n = win->children();
for ( ; i<n; i++)
win->child(i)->hide();
if (ix>=n || ix<0) ix = n-1;
win->child(ix)->show();
}
typedef void (*UnitTestCallback)(const char*,Fl_Group*);
void newButton(int x, int y, int w, int h, const char *l, int ix, const char *tt) {
Fl_Button *b = new Fl_Button(x, y, w, h, l);
b->tooltip(tt);
b->callback(changePageCB, (void*)ix);
}
class MainWindow *mainwin = 0;
Fl_Hold_Browser *browser = 0;
void createMenuPage() {
Fl_Group *page, *g;
page = new Fl_Group(0, 0, 600, 600);
g = new Fl_Group(100, 20, 460, 26, "drawing:");
g->align(FL_ALIGN_LEFT);
newButton(100+2, 22, 22, 22, "1", point_test_ix, "Testing pixel drawing");
newButton(125+2, 22, 22, 22, "2", line_test_ix, "Testing fl_line");
newButton(150+2, 22, 22, 22, "3", rect_test_ix, "Testing fl_rect");
newButton(175+2, 22, 22, 22, "4", viewport_test_ix, "Testing viewport alignment");
newButton(200+2, 22, 22, 22, "5", circle_test_ix, "Testing circle and oval drawing");
g->end();
page->end();
}
Fl_Group *beginTestPage(const char *l) {
int ix = win->children();
Fl_Group *g = new Fl_Group(0, 0, win->w(), win->h());
g->box(FL_FLAT_BOX);
g->hide();
newButton(20, 20, 20, 20, "M", -1, "Return to main menu");
newButton(20, 40, 20, 20, "@<", ix-1, "previous test");
newButton(20, 60, 20, 20, "@>", ix+1, "next test");
Fl_Box *bx = new Fl_Box(60, 20, win->w()-80, 100, l);
bx->box(FL_ENGRAVED_BOX);
bx->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
return g;
}
//------- test the point drawing capabilities of this implementation ----------
class PointTest : public Fl_Widget {
public: PointTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
void draw() {
int a = x(), b = y();
fl_color(FL_BLACK);
fl_rect(x(), y(), w(), h());
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_RED); a = x()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_GREEN); a = x(); b = y()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
fl_color(FL_BLUE); a = x()+70;
fl_point(a+10, b+10); fl_point(a+20, b+20);
fl_point(a+10, b+20); fl_point(a+20, b+10);
// 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 = strdup(label);
fCreate = create;
add(this);
}
};
void fl_point_test() {
point_test_ix = win->children();
Fl_Group *page = beginTestPage(
"testing the fl_point call\n"
"You should see four pixels each in black, red, green and blue. "
"Make sure that pixels are not anti-aliased (blured across multiple pixels)!"
);
new PointTest(20, 140, 100, 100);
page->end();
}
//------- test the line drawing capabilities of this implementation ----------
class LineTest : public Fl_Widget {
public: LineTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
void draw() {
int a = x(), b = y(); fl_color(FL_BLACK); fl_rect(a, b, w(), h());
// testing fl_xyline(x, y, x1)
fl_color(FL_RED); fl_point(a+10, b+10); fl_point(a+20, b+10);
fl_color(FL_BLACK); fl_xyline(a+10, b+10, a+20);
// testing fl_xyline(x, y, x1, y2);
fl_color(FL_RED); fl_point(a+10, b+20); fl_point(a+20, b+20);
fl_point(a+20, b+30);
fl_color(FL_BLACK); fl_xyline(a+10, b+20, a+20, b+30);
// testing fl_xyline(x, y, x1, y2, x3);
fl_color(FL_RED); fl_point(a+10, b+40); fl_point(a+20, b+40);
fl_point(a+20, b+50); fl_point(a+30, b+50);
fl_color(FL_BLACK); fl_xyline(a+10, b+40, a+20, b+50, a+30);
//+++ add testing for the fl_yxline commands!
// testing fl_loop(x,y, x,y, x,y, x, y)
fl_color(FL_RED); fl_point(a+60, b+60); fl_point(a+90, b+60);
fl_point(a+60, b+90); fl_point(a+90, b+90);
fl_color(FL_BLACK);
fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90);
~UnitTest() {
delete fWidget;
free(fLabel);
}
};
void fl_line_test() {
line_test_ix = win->children();
Fl_Group *page = beginTestPage(
"testing the integer based fl_line calls\n"
"No red pixels should be visible. "
"If you see bright red pixels, the line drawing alignment is off, "
"or the last pixel in a line does not get drawn. "
"If you see dark red pixels, anti-aliasing must be switched off."
);
new LineTest(20, 140, 100, 100);
page->end();
}
//------- test the line drawing capabilities of this implementation ----------
class RectTest : public Fl_Widget {
public: RectTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
void draw() {
int a = x(), b = y(); fl_color(FL_BLACK); fl_rect(a, b, w(), h());
// testing fl_rect() with positive size
fl_color(FL_RED); fl_loop(a+10, b+10, a+40, b+10, a+40, b+40, a+10, b+40);
fl_color(FL_GREEN); fl_loop(a+ 9, b+ 9, a+41, b+ 9, a+41, b+41, a+ 9, b+41);
fl_color(FL_GREEN); fl_loop(a+11, b+11, a+39, b+11, a+39, b+39, a+11, b+39);
fl_color(FL_BLACK); fl_rect(a+10, b+10, 31, 31);
// testing fl_rect() with positive size
fl_color(FL_RED); fl_loop(a+60, b+60, a+90, b+60, a+90, b+90, a+60, b+90);
fl_color(FL_GREEN); fl_loop(a+59, b+59, a+91, b+59, a+91, b+91, a+59, b+91);
fl_color(FL_BLACK); fl_rectf(a+60, b+60, 31, 31);
const char *label() {
return fLabel;
}
};
void fl_rect_test() {
rect_test_ix = win->children();
Fl_Group *page = beginTestPage(
"testing the fl_rect call\n"
"No red pixels should be visible. "
"If you see bright red lines, or if parts of the green frames are hidden, "
"the rect drawing alignment is off. "
);
new RectTest(20, 140, 100, 100);
page->end();
}
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;
//------- test the line drawing capabilities of this implementation ----------
class ViewportTest : public Fl_Widget {
int pos;
public: ViewportTest(int x, int y, int w, int h, int p) : Fl_Widget(x, y, w, h),
pos(p) {}
static void add(UnitTest *t) {
fTest[nTest] = t;
nTest++;
}
static int nTest;
static UnitTest *fTest[200];
};
int UnitTest::nTest = 0;
UnitTest *UnitTest::fTest[];
// 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() {
if (pos&1) {
fl_color(FL_RED); fl_yxline(x()+w(), y(), y()+h());
fl_color(FL_GREEN); fl_yxline(x()+w()-1, y(), y()+h());
} else {
fl_color(FL_RED); fl_yxline(x()-1, y(), y()+h());
fl_color(FL_GREEN); fl_yxline(x(), y(), y()+h());
Fl_Double_Window::draw();
if (fTestAlignment) {
drawAlignmentIndicators();
}
if (pos&2) {
fl_color(FL_RED); fl_xyline(x(), y()+h(), x()+w());
fl_color(FL_GREEN); fl_xyline(x(), y()+h()-1, x()+w());
}
void testAlignment(int v) {
fTestAlignment = v;
redraw();
}
int fTestAlignment;
};
//------- include the various unit tests as inline code -------
#include "unittest_about.cxx"
#include "unittest_points.cxx"
#include "unittest_lines.cxx"
#include "unittest_rects.cxx"
#include "unittest_viewport.cxx"
#include "unittest_circles.cxx"
#include "unittest_images.cxx"
// callback whenever the browser value changes
void Browser_CB(Fl_Widget*, void*) {
for ( int t=1; t<=browser->size(); t++ ) {
UnitTest *ti = (UnitTest*)browser->data(t);
if ( browser->selected(t) ) {
ti->show();
} else {
fl_color(FL_RED); fl_xyline(x(), y()-1, x()+w());
fl_color(FL_GREEN); fl_xyline(x(), y(), x()+w());
ti->hide();
}
fl_color(FL_BLACK);
fl_loop(x()+3, y()+3, x()+w()-4, y()+3, x()+w()-4, y()+h()-4, x()+3, y()+h()-4);
}
};
void fl_viewport_test() {
viewport_test_ix = win->children();
Fl_Group *page = beginTestPage(
"testing viewport alignment\n"
"Only green lines should be visible. "
"If red lines are visible in the corners of this window, "
"your viewport alignment and clipping is off. "
"If there is a space between the green lines and the window border, "
"the viewport is off, but some clipping may be working. "
"Also, your window size may be off to begin with."
);
new ViewportTest(0, 0, 20, 20, 0);
new ViewportTest(page->w()-20, 0, 20, 20, 1);
new ViewportTest(0, page->h()-20, 20, 20, 2);
new ViewportTest(page->w()-20,page->h()-20, 20, 20, 3);
page->end();
}
//------- test the circle drawing capabilities of this implementation ----------
class CircleTest : public Fl_Widget {
public: CircleTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
void draw() {
int a = x(), b = y(); fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
// test fl_arc for full circles
fl_color(FL_GREEN); fl_rect(a+ 9, b+ 9, 33, 33);
fl_color(FL_RED); fl_xyline(a+24, b+10, a+27); fl_xyline(a+24, b+40, a+27);
fl_yxline(a+10, b+24, b+27); fl_yxline(a+40, b+24, b+27);
fl_color(FL_BLACK); fl_arc(a+10, b+10, 31, 31, 0.0, 360.0);
// test fl_arc segmet 1
fl_color(FL_GREEN); fl_rect(a+54, b+ 4, 43, 43);
fl_rect(a+54, b+4, 18, 18); fl_rect(a+79, b+29, 18, 18);
fl_color(FL_RED); fl_point(a+55, b+30); fl_point(a+70, b+45);
fl_point(a+80, b+5); fl_point(a+95, b+20);
fl_color(FL_BLACK); fl_arc(a+65, b+ 5, 31, 31, -35.0, 125.0);
// test fl_arc segmet 2
fl_color(FL_BLACK); fl_arc(a+55, b+15, 31, 31, 145.0, 305.0);
// test fl_pie for full circles
fl_color(FL_RED); fl_xyline(a+24, b+60, a+27); fl_xyline(a+24, b+90, a+27);
fl_yxline(a+10, b+74, b+77); fl_yxline(a+40, b+74, b+77);
fl_color(FL_GREEN); fl_rect(a+ 9, b+59, 33, 33);
fl_color(FL_BLACK); fl_pie(a+10, b+60, 31, 31, 0.0, 360.0);
// test fl_pie segmet 1
fl_color(FL_GREEN); fl_rect(a+54, b+54, 43, 43);
fl_rect(a+54, b+54, 18, 18); fl_rect(a+79, b+79, 18, 18);
fl_point(a+79, b+71); fl_point(a+71, b+79);
fl_color(FL_RED); fl_point(a+55, b+80); fl_point(a+70, b+95);
fl_point(a+80, b+55); fl_point(a+95, b+70);
fl_point(a+81, b+69); fl_point(a+69, b+81);
fl_color(FL_BLACK); fl_pie(a+65, b+55, 31, 31, -30.0, 120.0);
// test fl_pie segmet 2
fl_color(FL_BLACK); fl_pie(a+55, b+65, 31, 31, 150.0, 300.0);
//---- oval testing (horizontal squish)
a = x()+120; b = y(); fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
fl_color(FL_GREEN);
fl_rect(a+19, b+9, 63, 33); fl_rect(a+19, b+59, 63, 33);
fl_color(FL_BLACK);
fl_arc(a+20, b+10, 61, 31, 0, 360); fl_pie(a+20, b+60, 61, 31, 0, 360);
//---- oval testing (horizontal squish)
a = x()+240; b = y(); fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
fl_color(FL_GREEN);
fl_rect(a+9, b+19, 33, 63); fl_rect(a+59, b+19, 33, 63);
fl_color(FL_BLACK);
fl_arc(a+10, b+20, 31, 61, 0, 360); fl_pie(a+60, b+20, 31, 61, 0, 360);
}
};
void fl_circle_test() {
circle_test_ix = win->children();
Fl_Group *page = beginTestPage(
"testing int drawing of circles and ovals (fl_arc, fl_pie)\n"
"No red lines should be visible. "
"If you see bright red pixels, the circle drawing alignment is off. "
"If you see dark red pixels, your syste supports anti-aliasing "
"which should be of no concern. "
"The green rectangles should not be touched by circle drawings."
);
new CircleTest(20, 140, 340, 100);
page->end();
}
// this is the main call. It creates the window and adds all previously
// registered tests to the browser widget.
int main(int argc, char **argv) {
win = new Fl_Window(600, 600, "Unit Tests for FLTK");
// --- list all tests
fl_point_test();
fl_line_test();
fl_rect_test();
fl_viewport_test();
fl_circle_test();
// --- last page is the menu
createMenuPage();
win->end();
win->show(argc, argv);
return Fl::run();
}
Fl::args(argc,argv);
Fl::visual(FL_RGB);
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);
browser->when(FL_WHEN_CHANGED);
browser->callback(Browser_CB);
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);
}
/////
mainwin->resizable(mainwin);
mainwin->show(argc,argv);
// Select first test in browser, and show that test.
browser->select(1);
Browser_CB(browser,0);
return(Fl::run());
}
//
// End of "$Id$".