aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2011-03-18 16:57:34 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2011-03-18 16:57:34 (GMT)
commitbcae4e257dc349db4dfa721c4771c1f8530fb13a (patch)
tree316c1d0fd608875b4b9cbd34066796fdd2ee5d8d /src/tests
parent7658d2c56d24a18d61a9ac2c14ef1ff0fd55d3bf (diff)
downloadfluxbox_paul-bcae4e257dc349db4dfa721c4771c1f8530fb13a.zip
fluxbox_paul-bcae4e257dc349db4dfa721c4771c1f8530fb13a.tar.bz2
added tests/testRectangleUtil.cc
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am4
-rw-r--r--src/tests/testRectangleUtil.cc66
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
12testTexture_SOURCES = texturetest.cc 13testTexture_SOURCES = texturetest.cc
13testFont_SOURCES = testFont.cc 14testFont_SOURCES = testFont.cc
@@ -17,6 +18,7 @@ testDemandAttention_SOURCES = testDemandAttention.cc
17#testResource_SOURCES = Resourcetest.cc 18#testResource_SOURCES = Resourcetest.cc
18testFullscreen_SOURCES = fullscreentest.cc 19testFullscreen_SOURCES = fullscreentest.cc
19testStringUtil_SOURCES = StringUtiltest.cc 20testStringUtil_SOURCES = StringUtiltest.cc
21testRectangleUtil_SOURCES = testRectangleUtil.cc
20 22
21LDADD=../FbTk/libFbTk.a 23LDADD=../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
5struct 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
18int 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
61int main(int argc, char **argv) {
62
63 test_insideBorder();
64
65 return 0;
66}