[PATCH 05/10] test/integration: use new static calls for WaitFor*

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 2 23:59:22 PDT 2012


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/integration/xi2.cpp |  172 ++--------------------------------------------
 1 file changed, 5 insertions(+), 167 deletions(-)

diff --git a/test/integration/xi2.cpp b/test/integration/xi2.cpp
index 1cbbe05..5dcf831 100644
--- a/test/integration/xi2.cpp
+++ b/test/integration/xi2.cpp
@@ -5,168 +5,6 @@
 #include <X11/extensions/XInput.h>
 #include <X11/extensions/XInput2.h>
 
-namespace {
-
-/**
- * Wait for an event on the X connection.
- *
- * @param [in] display The X display connection
- * @param [in] timeout The timeout in milliseconds
- *
- * @return Whether an event is available
- */
-bool WaitForEvent(::Display *display, time_t timeout = 1000)
-{
-    fd_set fds;
-    FD_ZERO(&fds);
-
-    int display_fd = ConnectionNumber(display);
-
-    XSync(display, False);
-
-    if (XPending(display))
-        return true;
-    else {
-        FD_SET(display_fd, &fds);
-
-        struct timeval timeval = {
-            static_cast<time_t>(timeout / 1000),
-            static_cast<time_t>(timeout % 1000),
-        };
-
-        int ret;
-        if (timeout)
-            ret = select(display_fd + 1, &fds, NULL, NULL, &timeval);
-        else
-            ret = select(display_fd + 1, &fds, NULL, NULL, NULL);
-
-        if (ret < 0)
-            throw std::runtime_error("Failed to select on X fd");
-
-        if (ret == 0)
-            return false;
-
-        return XPending(display);
-    }
-}
-
-/**
- * Wait for an event of a specific type on the X connection.
- *
- * All events preceding the matching event are discarded. If no event was found
- * before the timeout expires, all events in the queue will have been discarded.
- *
- * @param [in] display   The X display connection
- * @param [in] type      The X core protocol event type
- * @param [in] extension The X extension opcode of a generic event, or -1 for
- *                       any generic event
- * @param [in] evtype    The X extension event type of a generic event, or -1
- *                       for any event of the given extension
- * @param [in] timeout   The timeout in milliseconds
- *
- * @return Whether an event is available
- */
-bool WaitForEventOfType(::Display *display, int type, int extension, int evtype,
-                        time_t timeout = 1000)
-{
-    while (WaitForEvent(display)) {
-        XEvent event;
-        if (!XPeekEvent(display, &event))
-            throw std::runtime_error("Failed to peek X event");
-
-        if (event.type != type) {
-            if (XNextEvent(display, &event) != Success)
-                throw std::runtime_error("Failed to remove X event");
-            continue;
-        }
-
-        if (event.type != GenericEvent || extension == -1)
-            return true;
-
-        XGenericEvent *generic_event = reinterpret_cast<XGenericEvent*>(&event);
-
-        if (generic_event->extension != extension) {
-            if (XNextEvent(display, &event) != Success)
-                throw std::runtime_error("Failed to remove X event");
-            continue;
-        }
-
-        if (evtype == -1 || generic_event->evtype == evtype)
-            return true;
-
-        if (XNextEvent(display, &event) != Success)
-            throw std::runtime_error("Failed to remove X event");
-    }
-}
-
-/**
- * Wait for a specific device to be added to the server.
- *
- * @param [in] display The X display connection
- * @param [in] name    The name of the device to wait for
- * @param [in] timeout The timeout in milliseconds
- *
- * @return Whether the device was added
- */
-bool WaitForDevice(::Display *display, const std::string &name,
-                   time_t timeout = 1000)
-{
-    int opcode;
-    int event_start;
-    int error_start;
-
-    if (!XQueryExtension(display, "XInputExtension", &opcode, &event_start,
-                         &error_start))
-        throw std::runtime_error("Failed to query XInput extension");
-
-    while (WaitForEventOfType(display, GenericEvent, opcode,
-                              XI_HierarchyChanged)) {
-        XEvent event;
-        if (XNextEvent(display, &event) != Success)
-            throw std::runtime_error("Failed to get X event");
-
-        XGenericEventCookie *xcookie =
-            reinterpret_cast<XGenericEventCookie*>(&event.xcookie);
-        if (!XGetEventData(display, xcookie))
-            throw std::runtime_error("Failed to get X event data");
-
-        XIHierarchyEvent *hierarchy_event =
-            reinterpret_cast<XIHierarchyEvent*>(xcookie->data);
-
-        if (!(hierarchy_event->flags & XIDeviceEnabled)) {
-            XFreeEventData(display, xcookie);
-            continue;
-        }
-
-        bool device_found = false;
-        for (int i = 0; i < hierarchy_event->num_info; i++) {
-            if (!(hierarchy_event->info[i].flags & XIDeviceEnabled))
-                continue;
-
-            int num_devices;
-            XIDeviceInfo *device_info =
-                XIQueryDevice(display, hierarchy_event->info[i].deviceid,
-                              &num_devices);
-            if (num_devices != 1 || !device_info)
-                throw std::runtime_error("Failed to query device");
-
-            if (name.compare(device_info[0].name) == 0) {
-                device_found = true;
-                break;
-            }
-        }
-
-        XFreeEventData(display, xcookie);
-
-        if (device_found)
-            return true;
-    }
-
-    return false;
-}
-
-}
-
 /**
  * A test fixture for testing the XInput 2.x extension.
  *
@@ -233,13 +71,13 @@ TEST_P(XInput2Test, XIQueryPointerTouchscreen)
       return;
     }
 
-    ASSERT_TRUE(WaitForDevice(Display(),
+    ASSERT_TRUE(xorg::testing::XServer::WaitForDevice(Display(),
                               "N-Trig MultiTouch (Virtual Test Device)"));
 
     device->Play(
         TEST_ROOT_DIR "recordings/ntrig_dell_xt2/touch_1_begin.record");
 
-    ASSERT_TRUE(WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
+    ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
                                    XI_ButtonPress));
 
     XEvent event;
@@ -318,13 +156,13 @@ TEST_P(XInput2Test, DisableDeviceEndTouches)
       return;
     }
 
-    ASSERT_TRUE(WaitForDevice(Display(),
+    ASSERT_TRUE(xorg::testing::XServer::WaitForDevice(Display(),
                               "N-Trig MultiTouch (Virtual Test Device)"));
 
     device->Play(
         TEST_ROOT_DIR "recordings/ntrig_dell_xt2/touch_1_begin.record");
 
-    ASSERT_TRUE(WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
+    ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
                                    XI_TouchBegin));
 
     XEvent event;
@@ -349,7 +187,7 @@ TEST_P(XInput2Test, DisableDeviceEndTouches)
     XCloseDevice(Display(), xdevice);
     XFlush(Display());
 
-    ASSERT_TRUE(WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
+    ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
                                    XI_TouchEnd));
 }
 
-- 
1.7.10.4



More information about the xorg-devel mailing list