summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/Makefile2
-rw-r--r--test/README-unittests.txt97
-rw-r--r--test/unittest_text.cxx2
-rw-r--r--test/unittest_unicode.cxx106
-rw-r--r--test/unittest_unicode_utf8.h14
-rw-r--r--test/unittests.cxx2
-rw-r--r--test/unittests.h1
8 files changed, 224 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index cfc189168..910ccd876 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -156,6 +156,7 @@ SET (UNITTEST_SRCS
unittest_fast_shapes.cxx
unittest_circles.cxx
unittest_text.cxx
+ unittest_unicode.cxx
unittest_symbol.cxx
unittest_images.cxx
unittest_viewport.cxx
diff --git a/test/Makefile b/test/Makefile
index 4b4f5691e..3b9afa5eb 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -24,6 +24,7 @@ CPPUNITTEST = \
unittest_fast_shapes.cxx \
unittest_circles.cxx \
unittest_text.cxx \
+ unittest_unicode.cxx \
unittest_symbol.cxx \
unittest_images.cxx \
unittest_viewport.cxx \
@@ -39,6 +40,7 @@ OBJUNITTEST = \
unittest_fast_shapes.o \
unittest_circles.o \
unittest_text.o \
+ unittest_unicode.o \
unittest_symbol.o \
unittest_images.o \
unittest_viewport.o \
diff --git a/test/README-unittests.txt b/test/README-unittests.txt
new file mode 100644
index 000000000..763d2b422
--- /dev/null
+++ b/test/README-unittests.txt
@@ -0,0 +1,97 @@
+HOW TO CREATE A NEW UNIT TEST
+-----------------------------
+
+ 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
+ for your test (e.g. TestFoo).
+
+ The following should be a good starting template for the new file:
+
+ * * *
+
+ // ..standard fltk src header goes here..
+
+ #include "unittests.h" // Needed for UnitTest class and enum constant
+
+ // Widgets this test will use
+ #include <FL/Fl.H>
+ #include <FL/Fl_Group.H>
+
+ // Your class to do the test
+ // Your test must do its work within the TESTAREA_XYWH area.
+ //
+ class TestFoo : public Fl_Group {
+ public:
+ static Fl_Widget *create() {
+ return new TestFoo(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
+ }
+ TestFoo(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
+ UnitTest testfoo(kTestFoo, "My foo tester", TestFoo::create);
+
+ * * *
+
+ Note that the last line in the above is what "registers" your new test
+ with the unittests main application:
+
+ UnitTest testfoo(kTestFoo, "My foo tester", TestFoo::create);
+ ------- -------- ------------- ---------------
+ | | | |
+ | | | Your class's static create() method
+ | | |
+ | | 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)
+ |
+ The global instance name for your test.
+
+ 3) Take the 'k' name you used above, e.g. kTestFoo, and add it to the enum {}
+ at the top of the unittests.h file. Example:
+
+ enum {
+ kTestAbout = 0,
+ kTestPoints,
+ ...
+ kTestFoo, <-- ADD YOUR TEST CLASS WITH THE 'k' PREFIX
+ ...
+ };
+
+ 4) Add your new unittest_xxx.cxx file to:
+
+ a) test/CMakeLists.txt -- cmake needs this
+ b) test/Makefile -- configure needs this (?)
+
+ You should then be able to use cmake to create a build directory that
+ builds with your new test. e.g.
+
+ mkdir build
+ cmake ..
+
+ ..and from there, you should be able to go through the common
+ edit/make/run development cycle:
+
+ make -j 4 <-- should build bin/test/unittests with your test
+ bin/test/unittests <-- run unittests to check your work
+
+ 5) That's it!
+
+GENERAL TEST PRACTICES
+----------------------
+ 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
+ that area.
+
+ Try to include documentation that briefly recommends to the other devs
+ what this test does and what to watch out for. If docs won't fit into
+ the test area, either add a "?" button, or use a tooltip().
+
+TEST REGISTRATION NOTES
+-----------------------
+ The mechanism of using an enum and the UnitTest instance allows us
+ to ignore a test by simply not linking it (e.g. by choice with cmake).
+ No changes to the source code are needed. The enumeration still needs
+ an entry for everything that *may* be linked, even if it is not.
diff --git a/test/unittest_text.cxx b/test/unittest_text.cxx
index c1f5a9aef..544bb9950 100644
--- a/test/unittest_text.cxx
+++ b/test/unittest_text.cxx
@@ -104,4 +104,4 @@ public:
}
};
-UnitTest textExtents(kTestText, "Rendering text", TextExtentsTest::create);
+UnitTest textExtents(kTestText, "Rendering Text", TextExtentsTest::create);
diff --git a/test/unittest_unicode.cxx b/test/unittest_unicode.cxx
new file mode 100644
index 000000000..65cec32e5
--- /dev/null
+++ b/test/unittest_unicode.cxx
@@ -0,0 +1,106 @@
+//
+// Unit tests for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2022 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// https://www.fltk.org/COPYING.php
+//
+// Please see the following page on how to report bugs and issues:
+//
+// https://www.fltk.org/bugs.php
+//
+
+#include "unittests.h"
+
+#include <FL/Fl.H>
+#include <FL/Fl_Group.H>
+#include <FL/Fl_Text_Display.H>
+#include <FL/Fl_Multiline_Input.H>
+#include <FL/Fl_Choice.H>
+#include <FL/Fl_Hor_Value_Slider.H>
+#include <FL/fl_draw.H>
+
+#include "unittest_unicode_utf8.h" // defines utf8_box_test[]
+static const char *helptext =
+ "In this test, ideally the box's lines should all be touching "
+ "without white space between. Underbar and overbars should both "
+ "be visible and not touching. All the above should be unaffected "
+ "by different font sizes and font settings.";
+
+
+class UnicodeBoxTest : public Fl_Group {
+ Fl_Text_Buffer *textbuffer;
+ Fl_Text_Display *textdisplay;
+ Fl_Multiline_Input *multilineinput;
+ Fl_Choice *font_choice;
+ Fl_Hor_Value_Slider *fontsize_slider;
+
+ // Font choice callback
+ void FontChoice_CB2() {
+ switch ( font_choice->value() ) {
+ case 0: textdisplay->textfont(FL_COURIER); break;
+ case 1: textdisplay->textfont(FL_SCREEN); break;
+ }
+ parent()->redraw();
+ }
+ static void FontChoice_CB(Fl_Widget*, void *userdata) {
+ UnicodeBoxTest *o = (UnicodeBoxTest*)userdata;
+ o->FontChoice_CB2();
+ }
+
+ // Slider callback - apply new font size to widgets
+ void FontSizeSlider_CB2() {
+ // Get font size from slider value, apply to widgets
+ int fontsize = (int)fontsize_slider->value();
+ textdisplay->textsize(fontsize);
+ multilineinput->textsize(fontsize);
+ multilineinput->position(0); // keep scrolled to top
+ parent()->redraw();
+ }
+ static void FontSizeSlider_CB(Fl_Widget*, void *userdata) {
+ UnicodeBoxTest *o = (UnicodeBoxTest*)userdata;
+ o->FontSizeSlider_CB2();
+ }
+
+public:
+ static Fl_Widget *create() {
+ return new UnicodeBoxTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
+ }
+
+ UnicodeBoxTest(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
+ // Fl_Text_Display
+ textbuffer = new Fl_Text_Buffer();
+ textbuffer->text(utf8_box_test);
+ textdisplay = new Fl_Text_Display(x+5, y+20, 250, 250, "Fl_Text_Display");
+ textdisplay->textfont(FL_COURIER);
+ textdisplay->buffer(textbuffer);
+ textdisplay->tooltip(helptext);
+ // Fl_Multiline_Input
+ multilineinput = new Fl_Multiline_Input(x+250+15, y+20, 250, 250, "Fl_Multiline_Input");
+ multilineinput->align(FL_ALIGN_CENTER|FL_ALIGN_TOP);
+ multilineinput->textfont(FL_COURIER);
+ multilineinput->value(utf8_box_test);
+ multilineinput->tooltip(helptext);
+ // Font choice
+ // Fonts must be fixed width to work correctly..
+ font_choice = new Fl_Choice(x+150, y+h-80, 200, 25, "Font face");
+ font_choice->add("FL_COURIER");
+ font_choice->add("FL_SCREEN");
+ font_choice->value(0);
+ font_choice->callback(FontChoice_CB, (Fl_Widget*)this);
+ // Font size slider
+ fontsize_slider = new Fl_Hor_Value_Slider(x+150, y+h-50, 200, 25, "Font size");
+ fontsize_slider->align(FL_ALIGN_LEFT);
+ fontsize_slider->range(1.0, 50.0);
+ fontsize_slider->step(1.0);
+ fontsize_slider->value(14.0);
+ fontsize_slider->callback(FontSizeSlider_CB, (Fl_Widget*)this);
+ end();
+ }
+};
+
+UnitTest unicode_font_test(kUnicodeBoxTest, "Unicode Boxes", UnicodeBoxTest::create);
diff --git a/test/unittest_unicode_utf8.h b/test/unittest_unicode_utf8.h
new file mode 100644
index 000000000..d2504fb76
--- /dev/null
+++ b/test/unittest_unicode_utf8.h
@@ -0,0 +1,14 @@
+// FLTK DEVS: utf-8 encoding must be enabled to edit this file.
+
+static const char *utf8_box_test =
+ "╳╳ ██ ▏▏┏━━┓ ╔══╗ ╔═╦═╗ ██████\n"
+ "╳╳ ██ ▏▏┃ ┃ ║ ║ ╠═╬═╣ ██ ██\n"
+ "╳╳ ██ ▏▏┗━━┛ ╚══╝ ╚═╩═╝ ██████\n"
+ "\n"
+ "underbar: ______\n"
+ " overbar: ‾‾‾‾‾‾\n"
+ "\n"
+ "underbar/overbar alternate:\n"
+ "\n"
+ "___‾‾‾___‾‾‾___‾‾‾___‾‾‾___\n"
+ "‾‾‾___‾‾‾___‾‾‾___‾‾‾___‾‾‾\n";
diff --git a/test/unittests.cxx b/test/unittests.cxx
index c7f36fc6a..fcbfe5b9e 100644
--- a/test/unittests.cxx
+++ b/test/unittests.cxx
@@ -21,6 +21,8 @@
// v1.0 - Submit for svn
// v1.1 - Matthias seperated all tests into multiple source files for hopefully easier handling
+// NOTE: See README-unittests.txt for how to add new tests.
+
#include "unittests.h"
#include <FL/Fl.H>
diff --git a/test/unittests.h b/test/unittests.h
index 78b095cad..6b870df6d 100644
--- a/test/unittests.h
+++ b/test/unittests.h
@@ -44,6 +44,7 @@ enum {
kTestCircles,
kTestComplexShapes,
kTestText,
+ kUnicodeBoxTest,
kTestSymbol,
kTestImages,
kTestViewport,