From bcae4e257dc349db4dfa721c4771c1f8530fb13a Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Fri, 18 Mar 2011 17:57:34 +0100 Subject: added tests/testRectangleUtil.cc --- src/tests/Makefile.am | 4 ++- src/tests/testRectangleUtil.cc | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/tests/testRectangleUtil.cc 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= \ testKeys \ testDemandAttention \ testFullscreen \ - testStringUtil + testStringUtil \ + testRectangleUtil testTexture_SOURCES = texturetest.cc testFont_SOURCES = testFont.cc @@ -17,6 +18,7 @@ testDemandAttention_SOURCES = testDemandAttention.cc #testResource_SOURCES = Resourcetest.cc testFullscreen_SOURCES = fullscreentest.cc testStringUtil_SOURCES = StringUtiltest.cc +testRectangleUtil_SOURCES = testRectangleUtil.cc LDADD=../FbTk/libFbTk.a 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 @@ +#include "RectangleUtil.hh" + +#include + +struct Rect { + + int x() const { return m_x; } + int y() const { return m_y; } + int width() const { return m_width; } + int height() const { return m_height; } + + int m_x, m_y, m_width, m_height; +}; + + + + +int test_insideBorder() { + + printf("testing RectangleUtil::insideBorder()\n"); + + struct _t { + struct Rect rect; + int x; + int y; + int bw; + int truth; + }; + + _t tests[] = { + { { 0, 0, 10, 10 }, 0, 0, 2, false }, // on the (outer) edge + { { 0, 0, 10, 10 }, 1, 1, 2, false }, // on the (inner) edge + { { 0, 0, 10, 10 }, 5, 5, 2, true }, // really inside + { { 0, 0, 10, 10 }, -5, 0, 2, false }, // somewhere outside + { { 0, 0, 10, 10 }, 20, 20, 2, false } // outside for sure + }; + + int i; + for (i = 0; i < sizeof(tests)/sizeof(_t); ++i) { + const _t& t = tests[i]; + int result = RectangleUtil::insideBorder(t.rect, t.x, t.y, t.bw); + + printf(" %d: is (%02d|%02d) inside [%d %d]-[%d %d] with border %d: %s, %s\n", + i, + t.x, t.y, + t.rect.x(), t.rect.y(), + t.rect.x() + (int)t.rect.width(), + t.rect.y() + (int)t.rect.height(), + t.bw, + result ? "yes" : "no", result == t.truth ? "ok" : "failed"); + } + + printf("done.\n"); + + return 0; +} + + + + +int main(int argc, char **argv) { + + test_insideBorder(); + + return 0; +} -- cgit v0.11.2