2022-12-11 21:18:06 +03:00
|
|
|
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
|
2022-12-17 15:16:57 +03:00
|
|
|
for your test (e.g. Ut_Test_Foo).
|
2022-12-11 21:18:06 +03:00
|
|
|
|
|
|
|
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
|
2022-12-17 15:16:57 +03:00
|
|
|
// Your test must do its work within the UT_TESTAREA_XYWH area.
|
2022-12-11 21:18:06 +03:00
|
|
|
//
|
2022-12-17 15:16:57 +03:00
|
|
|
class Ut_Test_Foo : public Fl_Group {
|
2022-12-11 21:18:06 +03:00
|
|
|
public:
|
|
|
|
static Fl_Widget *create() {
|
2022-12-17 15:16:57 +03:00
|
|
|
return new Ut_Test_Foo(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
|
2022-12-11 21:18:06 +03:00
|
|
|
}
|
2022-12-17 15:16:57 +03:00
|
|
|
Ut_Test_Foo(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { .. }
|
2022-12-11 21:18:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create an instance of your class and register it with the main app
|
2022-12-17 15:16:57 +03:00
|
|
|
UnitTest testfoo(UT_TEST_FOO, "My foo tester", Ut_Test_Foo::create);
|
2022-12-11 21:18:06 +03:00
|
|
|
|
|
|
|
* * *
|
|
|
|
|
|
|
|
Note that the last line in the above is what "registers" your new test
|
|
|
|
with the unittests main application:
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
UnitTest testfoo(UT_TEST_FOO, "My foo tester", Ut_Test_Foo::create);
|
|
|
|
------- ----------- ------------- -------------------
|
|
|
|
| | | |
|
|
|
|
| | | Your class's static create() method
|
|
|
|
| | |
|
|
|
|
| | Text name for your test that shows up in unittests browser
|
2022-12-11 21:18:06 +03:00
|
|
|
| |
|
2022-12-17 15:16:57 +03:00
|
|
|
| This will be defined as an enum constant in the next step
|
2022-12-11 21:18:06 +03:00
|
|
|
|
|
|
|
|
The global instance name for your test.
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
3) Add an entry anywhere to the enum {} at the top of the unittests.h file. Example:
|
2022-12-11 21:18:06 +03:00
|
|
|
|
|
|
|
enum {
|
2022-12-17 15:16:57 +03:00
|
|
|
UT_TEST_ABOUT = 0,
|
|
|
|
UT_TEST_POINTS,
|
2022-12-11 21:18:06 +03:00
|
|
|
...
|
2022-12-17 15:16:57 +03:00
|
|
|
UT_TEST_FOO, <-- ADD YOUR TEST CLASS NAME IN ALL CAPS
|
2022-12-11 21:18:06 +03:00
|
|
|
...
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
----------------------
|
2022-12-17 15:16:57 +03:00
|
|
|
UT_TESTAREA_X, Y, W, and H will be the position and size of the Group,
|
2022-12-11 21:18:06 +03:00
|
|
|
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.
|