[PATCH xserver 17/17] Test: Input: Add touch tests
Daniel Stone
daniel at fooishbar.org
Tue Dec 28 09:58:08 PST 2010
Add tests for:
* checking basic functionality of TouchCreate, FindTouchPoint, and
FinishTouchPoint
* ensuring all touch event types match each other in
GrabMatchesSecond
* ensuring all touch events are selected together, or not at all, in
XISelectEvents (this test authored by Chase Douglas)
* ensuring EventToXI2 is predictable between runs
* validating TouchBegin, TouchMotion and TouchEnd protocol
conversion
Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
test/input.c | 117 +++++++++++++++++++++++++++++++++++-
test/xi2/protocol-eventconvert.c | 54 ++++++++++++++++
test/xi2/protocol-xiselectevents.c | 44 +++++++++++++
3 files changed, 214 insertions(+), 1 deletions(-)
diff --git a/test/input.c b/test/input.c
index e443f75..b59391f 100644
--- a/test/input.c
+++ b/test/input.c
@@ -277,6 +277,9 @@ static void dix_event_to_core_conversion(void)
dix_event_to_core_fail(ET_DeviceChanged, BadImplementation);
dix_event_to_core_fail(ET_ProximityIn, BadMatch);
dix_event_to_core_fail(ET_ProximityOut, BadMatch);
+ dix_event_to_core_fail(ET_TouchBegin, BadMatch);
+ dix_event_to_core_fail(ET_TouchMotion, BadMatch);
+ dix_event_to_core_fail(ET_TouchEnd, BadMatch);
dix_event_to_core(ET_KeyPress);
dix_event_to_core(ET_KeyRelease);
@@ -285,6 +288,34 @@ static void dix_event_to_core_conversion(void)
dix_event_to_core(ET_Motion);
}
+static void dix_event_to_xi2_conversion(void)
+{
+ DeviceEvent ev;
+ xXIDeviceEvent *xi2, *xi2_flags;
+ int rc;
+
+ memset(&ev, 0, sizeof(ev));
+
+ ev.header = 0xFF;
+ ev.length = sizeof(DeviceEvent);
+ ev.type = ET_TouchBegin;
+
+ rc = EventToXI2((InternalEvent*)&ev, (xEvent**)&xi2);
+ g_assert(rc == Success);
+ g_assert(xi2->type == GenericEvent);
+ g_assert(xi2->evtype == XI_TouchBegin);
+ g_assert(xi2->flags == 0);
+
+ ev.flags = XITouchOwner;
+ rc = EventToXI2((InternalEvent*)&ev, (xEvent**)&xi2_flags);
+ g_assert(rc == Success);
+ g_assert(xi2_flags->type == GenericEvent);
+ g_assert(xi2_flags->evtype == XI_TouchBegin);
+ g_assert(xi2_flags->flags == XITouchOwner);
+ xi2_flags->flags = 0;
+ g_assert(memcmp(xi2, xi2_flags, sizeof(*xi2)) == 0);
+}
+
static void xi2_struct_sizes(void)
{
#define compare(req) \
@@ -674,6 +705,20 @@ static void dix_grab_matching(void)
g_assert(rc == TRUE);
rc = GrabMatchesSecond(&b, &a, FALSE);
g_assert(rc == TRUE);
+
+ /* A TouchMotion/TouchEnd grab must match a TouchBegin grab. */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.type = XI_TouchBegin;
+ b.type = XI_TouchMotion;
+ a.detail.exact = 0;
+ b.detail.exact = 0;
+ a.modifiersDetail.exact = 0;
+ b.modifiersDetail.exact = 0;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ g_assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ g_assert(rc == TRUE);
}
static void test_bits_to_byte(int i)
@@ -1060,6 +1105,73 @@ static void include_bit_test_macros(void)
}
}
+static void touch_create(void)
+{
+ DeviceIntRec dev;
+ TouchClassRec touch;
+ TouchPointInfoRec touches[2];
+ int touchid;
+
+ memset(&dev, 0, sizeof(dev));
+ memset(&touch, 0, sizeof(touch));
+ memset(touches, 0, sizeof(*touches) * 2);
+ touch.num_touches = 2;
+ touch.touches = touches;
+ dev.touch = &touch;
+ touchid = CreateTouchPoint(&dev, 0xdeadbeef);
+ g_assert(touchid >= 0);
+ g_assert(touch.touches[touchid].active == TRUE);
+ g_assert(touch.touches[touchid].id == 0xdeadbeef);
+ g_assert(touch.touches[touchid].pending_finish == 0);
+ g_assert(touch.touches[touchid].num_listeners == 0);
+ g_assert(touch.touches[touchid].num_grabs == 0);
+ g_assert(touch.touches[touchid].sprite.spriteTraceGood == 0);
+}
+
+static void touch_find_point(void)
+{
+ DeviceIntRec dev;
+ TouchClassRec touch;
+ TouchPointInfoRec touches[2];
+ int create_id, find_id;
+
+ memset(&dev, 0, sizeof(dev));
+ memset(&touch, 0, sizeof(touch));
+ memset(touches, 0, sizeof(*touches) * 2);
+ touch.num_touches = 2;
+ touch.touches = touches;
+ dev.touch = &touch;
+ create_id = CreateTouchPoint(&dev, 0xdeadbeef);
+ g_assert(create_id >= 0);
+ find_id = FindTouchPoint(&dev, 0xdeadbeef);
+ g_assert(create_id == find_id);
+ g_assert(touch.touches[find_id].active == TRUE);
+ g_assert(touch.touches[find_id].id == 0xdeadbeef);
+}
+
+static void touch_finish(void)
+{
+ DeviceIntRec dev;
+ TouchClassRec touch;
+ TouchPointInfoRec touches[2];
+ int touchid;
+
+ memset(&dev, 0, sizeof(dev));
+ memset(&touch, 0, sizeof(touch));
+ memset(touches, 0, sizeof(*touches) * 2);
+ touch.num_touches = 2;
+ touch.touches = touches;
+ dev.touch = &touch;
+ touchid = CreateTouchPoint(&dev, 0xdeadbeef);
+ g_assert(touchid >= 0);
+ FinishTouchPoint(&dev, 0xdeadbeef);
+ g_assert(touch.touches[touchid].active == FALSE);
+ g_assert(touch.touches[touchid].pending_finish == 0);
+ g_assert(touch.touches[touchid].num_listeners == 0);
+ g_assert(touch.touches[touchid].num_grabs == 0);
+ g_assert(touch.touches[touchid].sprite.spriteTraceGood == 0);
+}
+
int main(int argc, char** argv)
{
g_test_init(&argc, &argv,NULL);
@@ -1069,6 +1181,7 @@ int main(int argc, char** argv)
g_test_add_func("/dix/input/attributes", dix_input_attributes);
g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
+ g_test_add_func("/dix/input/event-xi2-conversion", dix_event_to_xi2_conversion);
g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
@@ -1076,7 +1189,9 @@ int main(int argc, char** argv)
g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
-
+ g_test_add_func("/dix/input/touch-create", touch_create);
+ g_test_add_func("/dix/input/touch-find-point", touch_find_point);
+ g_test_add_func("/dix/input/touch-finish", touch_finish);
return g_test_run();
}
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 0478c33..6c9595a 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -311,6 +311,18 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
g_assert(out->sourceid == in->sourceid);
switch (in->type) {
+ case ET_TouchMotion:
+ flagmask = (XITouchOwnerAccepted | XITouchPendingFinish);
+ /* fallthrough */
+ case ET_TouchBegin:
+ case ET_TouchEnd:
+ flagmask |= XITouchOwner;
+ break;
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ case ET_Motion:
+ flagmask = XITouchPointer;
+ break;
case ET_KeyPress:
flagmask = XIKeyRepeat;
break;
@@ -636,6 +648,47 @@ static void test_convert_XIDeviceEvent(void)
}
}
+static void test_convert_XITouch(void)
+{
+ DeviceEvent in;
+
+ memset(&in, 0, sizeof(in));
+
+ g_test_message("Testing TouchBegin");
+ in.header = ET_Internal;
+ in.type = ET_TouchBegin;
+ in.length = sizeof(DeviceEvent);
+ in.time = 0;
+ in.deviceid = 1;
+ in.sourceid = 2;
+ in.root = 3;
+ in.root_x = 4;
+ in.root_x_frac = 5;
+ in.root_y = 6;
+ in.root_y_frac = 7;
+ in.detail.button = 8;
+ in.mods.base = 9;
+ in.mods.latched = 10;
+ in.mods.locked = 11;
+ in.mods.effective = 11;
+ in.group.base = 12;
+ in.group.latched = 13;
+ in.group.locked = 14;
+ in.group.effective = 15;
+ in.flags = XITouchOwner;
+ test_XIDeviceEvent(&in);
+
+ g_test_message("Testing TouchMotion");
+ in.type = ET_TouchMotion;
+ in.flags = XITouchOwnerAccepted;
+ test_XIDeviceEvent(&in);
+
+ g_test_message("Testing TouchEnd");
+ in.type = ET_TouchEnd;
+ in.flags = 0;
+ test_XIDeviceEvent(&in);
+}
+
static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
xXIDeviceChangedEvent *out,
BOOL swap)
@@ -912,6 +965,7 @@ int main(int argc, char** argv)
g_test_add_func("/xi2/eventconvert/XIFocusEvent", test_convert_XIFocusEvent);
g_test_add_func("/xi2/eventconvert/XIDeviceEvent", test_convert_XIDeviceEvent);
g_test_add_func("/xi2/eventconvert/XIDeviceChangedEvent", test_convert_XIDeviceChangedEvent);
+ g_test_add_func("/xi2/eventconvert/XITouch", test_convert_XITouch);
return g_test_run();
}
diff --git a/test/xi2/protocol-xiselectevents.c b/test/xi2/protocol-xiselectevents.c
index f951a14..6fa97a0 100644
--- a/test/xi2/protocol-xiselectevents.c
+++ b/test/xi2/protocol-xiselectevents.c
@@ -159,7 +159,18 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
memset(bits, 0, mask->mask_len * 4);
for (j = 0; j <= XI2LASTEVENT; j++)
{
+ /* Can't select for these events alone */
+ if (j == XI_TouchMotion || j == XI_TouchEnd)
+ continue;
+
SetBit(bits, j);
+
+ /* Must select for all touch events at once */
+ if (j == XI_TouchBegin) {
+ SetBit(bits, XI_TouchMotion);
+ SetBit(bits, XI_TouchEnd);
+ }
+
request_XISelectEvent(req, Success);
ClearBit(bits, j);
}
@@ -175,7 +186,18 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
for (j = 0; j <= XI2LASTEVENT; j++)
{
+ /* Can't select for these events alone */
+ if (j == XI_TouchMotion || j == XI_TouchEnd)
+ continue;
+
SetBit(bits, j);
+
+ /* Must select for all touch events at once */
+ if (j == XI_TouchBegin) {
+ SetBit(bits, XI_TouchMotion);
+ SetBit(bits, XI_TouchEnd);
+ }
+
request_XISelectEvent(req, Success);
}
@@ -189,7 +211,18 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
for (j = XI2LASTEVENT + 1; j < mask->mask_len * 4; j++)
{
+ /* Can't select for these events alone */
+ if (j == XI_TouchMotion || j == XI_TouchEnd)
+ continue;
+
SetBit(bits, j);
+
+ /* Must select for all touch events at once */
+ if (j == XI_TouchBegin) {
+ SetBit(bits, XI_TouchMotion);
+ SetBit(bits, XI_TouchEnd);
+ }
+
request_XISelectEvent(req, BadValue);
ClearBit(bits, j);
}
@@ -202,7 +235,18 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
memset(bits, 0, mask->mask_len * 4);
for (j = 0; j <= XI2LASTEVENT; j++)
{
+ /* Can't select for these events alone */
+ if (j == XI_TouchMotion || j == XI_TouchEnd)
+ continue;
+
SetBit(bits, j);
+
+ /* Must select for all touch events at once */
+ if (j == XI_TouchBegin) {
+ SetBit(bits, XI_TouchMotion);
+ SetBit(bits, XI_TouchEnd);
+ }
+
request_XISelectEvent(req, Success);
}
--
1.7.2.3
More information about the xorg-devel
mailing list