diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-12-11 13:12:26 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-12-11 13:45:09 +1000 |
commit | d5ffd663f59d76d7d0b28359c5f5c6048c955b0f (patch) | |
tree | 684c1300334636a1b69dd15977151d2242498cbb | |
parent | 6fbce6bd99979aded3d221200f19dbbb085aa55c (diff) |
common/helpers: add NoEventsPending
Little helper to print the first event on the wire if we don't actually
expect any to be there.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | tests/common/helpers.cpp | 14 | ||||
-rw-r--r-- | tests/common/helpers.h | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/common/helpers.cpp b/tests/common/helpers.cpp index d6f1d95..357e12c 100644 --- a/tests/common/helpers.cpp +++ b/tests/common/helpers.cpp @@ -232,3 +232,17 @@ Window CreateWindow(Display *dpy, Window parent, XSync(dpy, False); return win; } + +bool NoEventPending(::Display *dpy) +{ + XSync(dpy, False); + if (XPending(dpy)) { + XEvent ev; + XPeekEvent(dpy, &ev); + std::stringstream ss; + EXPECT_EQ(XPending(dpy), 0) << "Event type " << ev.type << " (extension " << + ev.xcookie.extension << " evtype " << ev.xcookie.evtype << ")"; + } + + return XPending(dpy) == 0; +} diff --git a/tests/common/helpers.h b/tests/common/helpers.h index 7ad714b..74e74b2 100644 --- a/tests/common/helpers.h +++ b/tests/common/helpers.h @@ -133,5 +133,14 @@ Window CreateWindow(Display *dpy, Window parent = None, int x = 0, int y = 0, int width = -1, int height = -1); +/** + * Check if there are any events on the wire and if so, print information + * about the first one. + * + * Typical usage: ASSERT_TRUE(NoEventPending(dpy)) + * + * @return true if the event queue is empty, false otherwise + */ +bool NoEventPending(Display *dpy); #endif |