diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/Makefile.am | 4 | ||||
-rw-r--r-- | src/tests/testRectangleUtil.cc | 66 |
2 files changed, 69 insertions, 1 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 85d42cf..1b82135 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am | |||
@@ -7,7 +7,8 @@ noinst_PROGRAMS= \ | |||
7 | testKeys \ | 7 | testKeys \ |
8 | testDemandAttention \ | 8 | testDemandAttention \ |
9 | testFullscreen \ | 9 | testFullscreen \ |
10 | testStringUtil | 10 | testStringUtil \ |
11 | testRectangleUtil | ||
11 | 12 | ||
12 | testTexture_SOURCES = texturetest.cc | 13 | testTexture_SOURCES = texturetest.cc |
13 | testFont_SOURCES = testFont.cc | 14 | testFont_SOURCES = testFont.cc |
@@ -17,6 +18,7 @@ testDemandAttention_SOURCES = testDemandAttention.cc | |||
17 | #testResource_SOURCES = Resourcetest.cc | 18 | #testResource_SOURCES = Resourcetest.cc |
18 | testFullscreen_SOURCES = fullscreentest.cc | 19 | testFullscreen_SOURCES = fullscreentest.cc |
19 | testStringUtil_SOURCES = StringUtiltest.cc | 20 | testStringUtil_SOURCES = StringUtiltest.cc |
21 | testRectangleUtil_SOURCES = testRectangleUtil.cc | ||
20 | 22 | ||
21 | LDADD=../FbTk/libFbTk.a | 23 | LDADD=../FbTk/libFbTk.a |
22 | 24 | ||
diff --git a/src/tests/testRectangleUtil.cc b/src/tests/testRectangleUtil.cc new file mode 100644 index 0000000..f10b6af --- /dev/null +++ b/src/tests/testRectangleUtil.cc | |||
@@ -0,0 +1,66 @@ | |||
1 | #include "RectangleUtil.hh" | ||
2 | |||
3 | #include <cstdio> | ||
4 | |||
5 | struct Rect { | ||
6 | |||
7 | int x() const { return m_x; } | ||
8 | int y() const { return m_y; } | ||
9 | int width() const { return m_width; } | ||
10 | int height() const { return m_height; } | ||
11 | |||
12 | int m_x, m_y, m_width, m_height; | ||
13 | }; | ||
14 | |||
15 | |||
16 | |||
17 | |||
18 | int test_insideBorder() { | ||
19 | |||
20 | printf("testing RectangleUtil::insideBorder()\n"); | ||
21 | |||
22 | struct _t { | ||
23 | struct Rect rect; | ||
24 | int x; | ||
25 | int y; | ||
26 | int bw; | ||
27 | int truth; | ||
28 | }; | ||
29 | |||
30 | _t tests[] = { | ||
31 | { { 0, 0, 10, 10 }, 0, 0, 2, false }, // on the (outer) edge | ||
32 | { { 0, 0, 10, 10 }, 1, 1, 2, false }, // on the (inner) edge | ||
33 | { { 0, 0, 10, 10 }, 5, 5, 2, true }, // really inside | ||
34 | { { 0, 0, 10, 10 }, -5, 0, 2, false }, // somewhere outside | ||
35 | { { 0, 0, 10, 10 }, 20, 20, 2, false } // outside for sure | ||
36 | }; | ||
37 | |||
38 | int i; | ||
39 | for (i = 0; i < sizeof(tests)/sizeof(_t); ++i) { | ||
40 | const _t& t = tests[i]; | ||
41 | int result = RectangleUtil::insideBorder<Rect>(t.rect, t.x, t.y, t.bw); | ||
42 | |||
43 | printf(" %d: is (%02d|%02d) inside [%d %d]-[%d %d] with border %d: %s, %s\n", | ||
44 | i, | ||
45 | t.x, t.y, | ||
46 | t.rect.x(), t.rect.y(), | ||
47 | t.rect.x() + (int)t.rect.width(), | ||
48 | t.rect.y() + (int)t.rect.height(), | ||
49 | t.bw, | ||
50 | result ? "yes" : "no", result == t.truth ? "ok" : "failed"); | ||
51 | } | ||
52 | |||
53 | printf("done.\n"); | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | |||
59 | |||
60 | |||
61 | int main(int argc, char **argv) { | ||
62 | |||
63 | test_insideBorder(); | ||
64 | |||
65 | return 0; | ||
66 | } | ||