1
/*****************************************************************************
3
* utouch-frame - Touch Frame Library
5
* Copyright (C) 2011 Canonical Ltd.
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation, either version 3 of the License, or (at your
10
* option) any later version.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
20
****************************************************************************/
22
#include "x11/fixture.h"
25
#include <X11/extensions/XInput2.h>
27
#include "utouch/frame.h"
28
#include "utouch/frame_x11.h"
30
void utouch::frame::x11::testing::Test::SetUp() {
31
ASSERT_NO_FATAL_FAILURE(xorg::testing::Test::SetUp());
33
Window root = DefaultRootWindow(Display());
36
mask.mask_len = XIMaskLen(XI_LASTEVENT);
37
mask.mask = reinterpret_cast<unsigned char*>(calloc(mask.mask_len,
40
mask.deviceid = XIAllDevices;
41
XISetMask(mask.mask, XI_HierarchyChanged);
42
ASSERT_EQ(Success, XISelectEvents(Display(), root, &mask, 1));
43
XIClearMask(mask.mask, XI_HierarchyChanged);
46
mask.deviceid = XIAllMasterDevices;
47
XISetMask(mask.mask, XI_TouchBegin);
48
XISetMask(mask.mask, XI_TouchUpdate);
49
XISetMask(mask.mask, XI_TouchUpdateUnowned);
50
XISetMask(mask.mask, XI_TouchEnd);
51
XISetMask(mask.mask, XI_TouchOwnership);
53
XIGrabModifiers mods = { XIAnyModifier, 0 };
55
ASSERT_EQ(Success, XIGrabTouchBegin(Display(), XIAllMasterDevices, root, 0,
60
UFStatus status = frame_x11_new(Display(), &handle_);
61
ASSERT_EQ(UFStatusSuccess, status);
62
ASSERT_TRUE(handle_ != NULL);
65
void utouch::frame::x11::testing::Test::PumpEvents(uint64_t timeout) {
69
int display_fd = ConnectionNumber(Display());
70
int frame_fd = frame_get_fd(handle_);
71
int nfds = display_fd > frame_fd ? display_fd + 1: frame_fd + 1;
76
if (!XPending(Display())) {
77
FD_SET(display_fd, &set);
78
FD_SET(frame_fd, &set);
80
struct timeval timeval = { timeout / 1000, timeout % 1000 };
84
ret = select(nfds, &set, NULL, NULL, &timeval);
86
ret = select(nfds, &set, NULL, NULL, NULL);
88
ASSERT_GE(ret, 0) << "Failed to select on FDs";
94
if (XPending(Display()) || FD_ISSET(display_fd, &set)) {
95
while (XPending(Display())) {
98
XNextEvent(Display(), &event);
100
if (event.type != GenericEvent)
103
XGenericEventCookie* xcookie = &event.xcookie;
104
ASSERT_NE(0, XGetEventData(Display(), xcookie)) <<
105
"Failed to get X generic event data";
107
ASSERT_EQ(UFStatusSuccess,
108
frame_x11_process_event(handle_, xcookie)) <<
109
"Failed to process X event";
111
XFreeEventData(Display(), xcookie);
115
if (FD_ISSET(frame_fd, &set)) {
116
ProcessFrameEvents();
121
void utouch::frame::x11::testing::Test::TearDown() {
122
frame_x11_delete(handle_);
123
xorg::testing::Test::TearDown();