all repos — fluxbox @ bcae4e257dc349db4dfa721c4771c1f8530fb13a

custom fork of the fluxbox windowmanager

added tests/testRectangleUtil.cc
Mathias Gumz akira at fluxbox dot org
commit

bcae4e257dc349db4dfa721c4771c1f8530fb13a

parent

7658d2c56d24a18d61a9ac2c14ef1ff0fd55d3bf

2 files changed, 69 insertions(+), 1 deletions(-)

jump to
M src/tests/Makefile.amsrc/tests/Makefile.am

@@ -7,7 +7,8 @@ testSignals \

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
A src/tests/testRectangleUtil.cc

@@ -0,0 +1,66 @@

+#include "RectangleUtil.hh" + +#include <cstdio> + +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<Rect>(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; +}