From d5ffd663f59d76d7d0b28359c5f5c6048c955b0f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 11 Dec 2012 13:12:26 +1000 Subject: 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 --- tests/common/helpers.cpp | 14 ++++++++++++++ tests/common/helpers.h | 9 +++++++++ 2 files changed, 23 insertions(+) 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 -- cgit v1.2.3