aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/test
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-12-23 10:01:52 +0100
committermarha <marha@users.sourceforge.net>2011-12-23 10:01:52 +0100
commite22891346b85a7db40dec7260a100f90b451cbc8 (patch)
treea7dd2d6757253947bcc821abbf68fd24d3301e89 /xorg-server/test
parentabacebe06d9f3d2fe1b7d256bd86cddbfa592a85 (diff)
downloadvcxsrv-e22891346b85a7db40dec7260a100f90b451cbc8.tar.gz
vcxsrv-e22891346b85a7db40dec7260a100f90b451cbc8.tar.bz2
vcxsrv-e22891346b85a7db40dec7260a100f90b451cbc8.zip
git mesa pixman xserver xkeyboard-config update 24 dec 2011
Diffstat (limited to 'xorg-server/test')
-rw-r--r--xorg-server/test/Makefile.am3
-rw-r--r--xorg-server/test/input.c17
-rw-r--r--xorg-server/test/touch.c270
-rw-r--r--xorg-server/test/xi2/protocol-eventconvert.c104
-rw-r--r--xorg-server/test/xi2/protocol-xipassivegrabdevice.c2
-rw-r--r--xorg-server/test/xi2/protocol-xiselectevents.c38
6 files changed, 412 insertions, 22 deletions
diff --git a/xorg-server/test/Makefile.am b/xorg-server/test/Makefile.am
index 48393d39a..ba8932c5d 100644
--- a/xorg-server/test/Makefile.am
+++ b/xorg-server/test/Makefile.am
@@ -1,6 +1,6 @@
if ENABLE_UNIT_TESTS
SUBDIRS= .
-noinst_PROGRAMS = list string
+noinst_PROGRAMS = list string touch
if XORG
# Tests that require at least some DDX functions in order to fully link
# For now, requires xf86 ddx, could be adjusted to use another
@@ -35,6 +35,7 @@ list_LDADD=$(TEST_LDADD)
misc_LDADD=$(TEST_LDADD)
fixes_LDADD=$(TEST_LDADD)
xfree86_LDADD=$(TEST_LDADD)
+touch_LDADD=$(TEST_LDADD)
libxservertest_la_LIBADD = $(XSERVER_LIBS)
if XORG
diff --git a/xorg-server/test/input.c b/xorg-server/test/input.c
index d27b3f0c0..576cd8531 100644
--- a/xorg-server/test/input.c
+++ b/xorg-server/test/input.c
@@ -161,22 +161,31 @@ static void dix_check_grab_values(void)
rc = CheckGrabValues(&client, &param);
assert(rc == Success);
- param.this_device_mode = GrabModeAsync + 1;
+ param.this_device_mode = XIGrabModeTouch;
+ rc = CheckGrabValues(&client, &param);
+ assert(rc == Success);
+
+ param.this_device_mode = XIGrabModeTouch + 1;
rc = CheckGrabValues(&client, &param);
assert(rc == BadValue);
assert(client.errorValue == param.this_device_mode);
- assert(client.errorValue == GrabModeAsync + 1);
+ assert(client.errorValue == XIGrabModeTouch + 1);
param.this_device_mode = GrabModeSync;
param.other_devices_mode = GrabModeAsync;
rc = CheckGrabValues(&client, &param);
+
+ param.this_device_mode = GrabModeSync;
+ param.other_devices_mode = XIGrabModeTouch;
+ rc = CheckGrabValues(&client, &param);
+ assert(rc == Success);
assert(rc == Success);
- param.other_devices_mode = GrabModeAsync + 1;
+ param.other_devices_mode = XIGrabModeTouch + 1;
rc = CheckGrabValues(&client, &param);
assert(rc == BadValue);
assert(client.errorValue == param.other_devices_mode);
- assert(client.errorValue == GrabModeAsync + 1);
+ assert(client.errorValue == XIGrabModeTouch + 1);
param.other_devices_mode = GrabModeSync;
diff --git a/xorg-server/test/touch.c b/xorg-server/test/touch.c
new file mode 100644
index 000000000..88955cbc1
--- /dev/null
+++ b/xorg-server/test/touch.c
@@ -0,0 +1,270 @@
+/**
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+#include "inputstr.h"
+#include "assert.h"
+#include "scrnintstr.h"
+
+static void touch_grow_queue(void)
+{
+ DeviceIntRec dev;
+ ValuatorClassRec val;
+ TouchClassRec touch;
+ size_t size, new_size;
+ int i;
+
+ memset(&dev, 0, sizeof(dev));
+ dev.id = 2;
+ dev.valuator = &val;
+ val.numAxes = 5;
+ dev.touch = &touch;
+ inputInfo.devices = &dev;
+
+ size = 5;
+
+ dev.last.num_touches = size;
+ dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
+ assert(dev.last.touches);
+ for (i = 0; i < size; i++) {
+ dev.last.touches[i].active = TRUE;
+ dev.last.touches[i].ddx_id = i;
+ dev.last.touches[i].client_id = i * 2;
+ }
+
+ /* no more space, should've scheduled a workproc */
+ assert(TouchBeginDDXTouch(&dev, 1234) == NULL);
+ ProcessWorkQueue();
+
+ new_size = size + size/2 + 1;
+ assert(dev.last.num_touches == new_size);
+
+ /* make sure we haven't touched those */
+ for (i = 0; i < size; i++) {
+ DDXTouchPointInfoPtr t = &dev.last.touches[i];
+ assert(t->active == TRUE);
+ assert(t->ddx_id == i);
+ assert(t->client_id == i * 2);
+ }
+
+ /* make sure those are zero-initialized */
+ for (i = size; i < new_size; i++) {
+ DDXTouchPointInfoPtr t = &dev.last.touches[i];
+ assert(t->active == FALSE);
+ assert(t->client_id == 0);
+ assert(t->ddx_id == 0);
+ }
+}
+
+static void touch_find_ddxid(void)
+{
+ DeviceIntRec dev;
+ DDXTouchPointInfoPtr ti;
+ ValuatorClassRec val;
+ TouchClassRec touch;
+ int size = 5;
+ int i;
+
+ memset(&dev, 0, sizeof(dev));
+ dev.id = 2;
+ dev.valuator = &val;
+ val.numAxes = 5;
+ dev.touch = &touch;
+ dev.last.num_touches = size;
+ dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
+ inputInfo.devices = &dev;
+ assert(dev.last.touches);
+
+
+ dev.last.touches[0].active = TRUE;
+ dev.last.touches[0].ddx_id = 10;
+ dev.last.touches[0].client_id = 20;
+
+
+ /* existing */
+ ti = TouchFindByDDXID(&dev, 10, FALSE);
+ assert(ti == &dev.last.touches[0]);
+
+ /* non-existing */
+ ti = TouchFindByDDXID(&dev, 20, FALSE);
+ assert(ti == NULL);
+
+ /* Non-active */
+ dev.last.touches[0].active = FALSE;
+ ti = TouchFindByDDXID(&dev, 10, FALSE);
+ assert(ti == NULL);
+
+ /* create on number 2*/
+ dev.last.touches[0].active = TRUE;
+
+ ti = TouchFindByDDXID(&dev, 20, TRUE);
+ assert(ti == &dev.last.touches[1]);
+ assert(ti->active);
+ assert(ti->ddx_id == 20);
+
+ /* set all to active */
+ for (i = 0; i < size; i++)
+ dev.last.touches[i].active = TRUE;
+
+ /* Try to create more, fail */
+ ti = TouchFindByDDXID(&dev, 30, TRUE);
+ assert(ti == NULL);
+ ti = TouchFindByDDXID(&dev, 30, TRUE);
+ assert(ti == NULL);
+ /* make sure we haven't resized, we're in the signal handler */
+ assert(dev.last.num_touches == size);
+
+ /* stop one touchpoint, try to create, succeed */
+ dev.last.touches[2].active = FALSE;
+ ti = TouchFindByDDXID(&dev, 30, TRUE);
+ assert(ti == &dev.last.touches[2]);
+ /* but still grow anyway */
+ ProcessWorkQueue();
+ ti = TouchFindByDDXID(&dev, 40, TRUE);
+ assert(ti == &dev.last.touches[size]);
+}
+
+static void touch_begin_ddxtouch(void)
+{
+ DeviceIntRec dev;
+ DDXTouchPointInfoPtr ti;
+ ValuatorClassRec val;
+ TouchClassRec touch;
+ int ddx_id = 123;
+ unsigned int last_client_id = 0;
+ int size = 5;
+
+ memset(&dev, 0, sizeof(dev));
+ dev.id = 2;
+ dev.valuator = &val;
+ val.numAxes = 5;
+ touch.mode = XIDirectTouch;
+ dev.touch = &touch;
+ dev.last.num_touches = size;
+ dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
+ inputInfo.devices = &dev;
+ assert(dev.last.touches);
+
+ ti = TouchBeginDDXTouch(&dev, ddx_id);
+ assert(ti);
+ assert(ti->ddx_id == ddx_id);
+ /* client_id == ddx_id can happen in real life, but not in this test */
+ assert(ti->client_id != ddx_id);
+ assert(ti->active);
+ assert(ti->client_id > last_client_id);
+ assert(ti->emulate_pointer);
+ last_client_id = ti->client_id;
+
+ ddx_id += 10;
+ ti = TouchBeginDDXTouch(&dev, ddx_id);
+ assert(ti);
+ assert(ti->ddx_id == ddx_id);
+ /* client_id == ddx_id can happen in real life, but not in this test */
+ assert(ti->client_id != ddx_id);
+ assert(ti->active);
+ assert(ti->client_id > last_client_id);
+ assert(!ti->emulate_pointer);
+ last_client_id = ti->client_id;
+}
+
+static void touch_begin_touch(void)
+{
+ DeviceIntRec dev;
+ TouchClassRec touch;
+ ValuatorClassRec val;
+ TouchPointInfoPtr ti;
+ int touchid = 12434;
+ int sourceid = 23;
+ SpriteInfoRec sprite;
+ ScreenRec screen;
+
+ screenInfo.screens[0] = &screen;
+
+ memset(&dev, 0, sizeof(dev));
+ dev.id = 2;
+
+ memset(&sprite, 0, sizeof(sprite));
+ dev.spriteInfo = &sprite;
+
+ memset(&touch, 0, sizeof(touch));
+ touch.num_touches = 0;
+
+ memset(&val, 0, sizeof(val));
+ dev.valuator = &val;
+ val.numAxes = 2;
+
+ ti = TouchBeginTouch(&dev, sourceid, touchid, TRUE);
+ assert(!ti);
+
+ dev.touch = &touch;
+ ti = TouchBeginTouch(&dev, sourceid, touchid, TRUE);
+ assert(ti);
+ assert(ti->client_id == touchid);
+ assert(ti->active);
+ assert(ti->sourceid == sourceid);
+ assert(ti->emulate_pointer);
+
+ assert(touch.num_touches == 1);
+}
+
+static void touch_init(void)
+{
+ DeviceIntRec dev;
+ Atom labels[2] = {0};
+ int rc;
+ SpriteInfoRec sprite;
+ ScreenRec screen;
+
+ screenInfo.screens[0] = &screen;
+
+ memset(&dev, 0, sizeof(dev));
+
+ memset(&sprite, 0, sizeof(sprite));
+ dev.spriteInfo = &sprite;
+
+ InitAtoms();
+ rc = InitTouchClassDeviceStruct(&dev, 1, XIDirectTouch, 2);
+ assert(rc == FALSE);
+
+ InitValuatorClassDeviceStruct(&dev, 2, labels, 10, Absolute);
+ rc = InitTouchClassDeviceStruct(&dev, 1, XIDirectTouch, 2);
+ assert(rc == TRUE);
+ assert(dev.touch);
+}
+
+
+
+int main(int argc, char** argv)
+{
+ touch_grow_queue();
+ touch_find_ddxid();
+ touch_begin_ddxtouch();
+ touch_init();
+ touch_begin_touch();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-eventconvert.c b/xorg-server/test/xi2/protocol-eventconvert.c
index e2037f911..faa9f407a 100644
--- a/xorg-server/test/xi2/protocol-eventconvert.c
+++ b/xorg-server/test/xi2/protocol-eventconvert.c
@@ -193,7 +193,6 @@ static void test_convert_XIRawEvent(void)
memset(&in, 0, sizeof(in));
- printf("Testing all event types\n");
in.header = ET_Internal;
in.type = ET_RawMotion;
test_XIRawEvent(&in);
@@ -214,7 +213,6 @@ static void test_convert_XIRawEvent(void)
in.type = ET_RawButtonRelease;
test_XIRawEvent(&in);
- printf("Testing details and other fields\n");
in.detail.button = 1L;
test_XIRawEvent(&in);
in.detail.button = 1L << 8;
@@ -246,7 +244,6 @@ static void test_convert_XIRawEvent(void)
in.deviceid = ~0 & 0xFF;
test_XIRawEvent(&in);
- printf("Testing valuator masks\n");
for (i = 0; i < MAX_VALUATORS; i++)
{
XISetMask(in.valuators.mask, i);
@@ -432,7 +429,6 @@ static void test_convert_XIDeviceEvent(void)
memset(&in, 0, sizeof(in));
- printf("Testing simple field values\n");
in.header = ET_Internal;
in.type = ET_Motion;
in.length = sizeof(DeviceEvent);
@@ -456,7 +452,6 @@ static void test_convert_XIDeviceEvent(void)
test_XIDeviceEvent(&in);
- printf("Testing field ranges\n");
/* 32 bit */
in.detail.button = 1L;
test_XIDeviceEvent(&in);
@@ -604,7 +599,6 @@ static void test_convert_XIDeviceEvent(void)
in.mods.effective = ~0 & 0xFF;
test_XIDeviceEvent(&in);
- printf("Testing button masks\n");
for (i = 0; i < sizeof(in.buttons) * 8; i++)
{
XISetMask(in.buttons, i);
@@ -618,7 +612,6 @@ static void test_convert_XIDeviceEvent(void)
test_XIDeviceEvent(&in);
}
- printf("Testing valuator masks\n");
for (i = 0; i < MAX_VALUATORS; i++)
{
XISetMask(in.valuators.mask, i);
@@ -799,7 +792,6 @@ static void test_convert_XIDeviceChangedEvent(void)
DeviceChangedEvent in;
int i;
- printf("Testing simple field values\n");
memset(&in, 0, sizeof(in));
in.header = ET_Internal;
in.type = ET_DeviceChanged;
@@ -923,12 +915,108 @@ static void test_convert_XIDeviceChangedEvent(void)
}
}
+static void
+test_values_XITouchOwnershipEvent(TouchOwnershipEvent *in,
+ xXITouchOwnershipEvent *out,
+ BOOL swap)
+{
+ if (swap)
+ {
+ swaps(&out->sequenceNumber);
+ swapl(&out->length);
+ swaps(&out->evtype);
+ swaps(&out->deviceid);
+ swaps(&out->sourceid);
+ swapl(&out->time);
+ swapl(&out->touchid);
+ swapl(&out->root);
+ swapl(&out->event);
+ swapl(&out->child);
+ swapl(&out->time);
+ }
+
+ assert(out->type == GenericEvent);
+ assert(out->extension == 0); /* IReqCode defaults to 0 */
+ assert(out->evtype == GetXI2Type(in->type));
+ assert(out->time == in->time);
+ assert(out->deviceid == in->deviceid);
+ assert(out->sourceid == in->sourceid);
+ assert(out->touchid == in->touchid);
+ assert(out->flags == in->reason);
+}
+
+static void
+test_XITouchOwnershipEvent(TouchOwnershipEvent *in)
+{
+ xXITouchOwnershipEvent *out, *swapped;
+ int rc;
+
+ rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
+ assert(rc == Success);
+
+ test_values_XITouchOwnershipEvent(in, out, FALSE);
+
+ swapped = calloc(1, sizeof(xEvent) + out->length * 4);
+ XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped);
+ test_values_XITouchOwnershipEvent(in, swapped, TRUE);
+ free(out);
+ free(swapped);
+}
+
+static void
+test_convert_XITouchOwnershipEvent(void)
+{
+ TouchOwnershipEvent in;
+ long i;
+
+ memset(&in, 0, sizeof(in));
+ in.header = ET_Internal;
+ in.type = ET_TouchOwnership;
+ in.length = sizeof(in);
+ in.time = 0;
+ in.deviceid = 1;
+ in.sourceid = 2;
+ in.touchid = 0;
+ in.reason = 0;
+ in.resource = 0;
+ in.flags = 0;
+
+ test_XITouchOwnershipEvent(&in);
+
+ in.flags = XIAcceptTouch;
+ test_XITouchOwnershipEvent(&in);
+
+ in.flags = XIRejectTouch;
+ test_XITouchOwnershipEvent(&in);
+
+ for (i = 1; i <= 0xFFFF; i <<= 1)
+ {
+ in.deviceid = i;
+ test_XITouchOwnershipEvent(&in);
+ }
+
+ for (i = 1; i <= 0xFFFF; i <<= 1)
+ {
+ in.sourceid = i;
+ test_XITouchOwnershipEvent(&in);
+ }
+
+ for (i = 1; ; i <<= 1)
+ {
+ in.touchid = i;
+ test_XITouchOwnershipEvent(&in);
+ if (i == (1 << 31))
+ break;
+ }
+}
+
int main(int argc, char** argv)
{
test_convert_XIRawEvent();
test_convert_XIFocusEvent();
test_convert_XIDeviceEvent();
test_convert_XIDeviceChangedEvent();
+ test_convert_XITouchOwnershipEvent();
return 0;
}
diff --git a/xorg-server/test/xi2/protocol-xipassivegrabdevice.c b/xorg-server/test/xi2/protocol-xipassivegrabdevice.c
index 89ffc3d29..b405556be 100644
--- a/xorg-server/test/xi2/protocol-xipassivegrabdevice.c
+++ b/xorg-server/test/xi2/protocol-xipassivegrabdevice.c
@@ -180,7 +180,7 @@ static void test_XIPassiveGrabDevice(void)
request->deviceid = XIAllMasterDevices;
printf("Testing invalid grab types\n");
- for (i = XIGrabtypeFocusIn + 1; i < 0xFF; i++)
+ for (i = XIGrabtypeTouchBegin + 1; i < 0xFF; i++)
{
request->grab_type = i;
request_XIPassiveGrabDevice(&client_request, request, BadValue, request->grab_type);
diff --git a/xorg-server/test/xi2/protocol-xiselectevents.c b/xorg-server/test/xi2/protocol-xiselectevents.c
index 4eaf839fa..0390858b1 100644
--- a/xorg-server/test/xi2/protocol-xiselectevents.c
+++ b/xorg-server/test/xi2/protocol-xiselectevents.c
@@ -125,6 +125,28 @@ static void request_XISelectEvent(xXISelectEventsReq *req, int error)
assert(rc == error);
}
+static void _set_bit(unsigned char *bits, int bit)
+{
+ SetBit(bits, bit);
+ if (bit >= XI_TouchBegin && bit <= XI_TouchOwnership)
+ {
+ SetBit(bits, XI_TouchBegin);
+ SetBit(bits, XI_TouchUpdate);
+ SetBit(bits, XI_TouchEnd);
+ }
+}
+
+static void _clear_bit(unsigned char *bits, int bit)
+{
+ ClearBit(bits, bit);
+ if (bit >= XI_TouchBegin && bit <= XI_TouchOwnership)
+ {
+ ClearBit(bits, XI_TouchBegin);
+ ClearBit(bits, XI_TouchUpdate);
+ ClearBit(bits, XI_TouchEnd);
+ }
+}
+
static void request_XISelectEvents_masks(xXISelectEventsReq *req)
{
int i, j;
@@ -157,9 +179,9 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
memset(bits, 0, mask->mask_len * 4);
for (j = 0; j <= XI2LASTEVENT; j++)
{
- SetBit(bits, j);
+ _set_bit(bits, j);
request_XISelectEvent(req, Success);
- ClearBit(bits, j);
+ _clear_bit(bits, j);
}
/* Test 2:
@@ -173,7 +195,7 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
for (j = 0; j <= XI2LASTEVENT; j++)
{
- SetBit(bits, j);
+ _set_bit(bits, j);
request_XISelectEvent(req, Success);
}
@@ -187,9 +209,9 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
for (j = XI2LASTEVENT + 1; j < mask->mask_len * 4; j++)
{
- SetBit(bits, j);
+ _set_bit(bits, j);
request_XISelectEvent(req, BadValue);
- ClearBit(bits, j);
+ _clear_bit(bits, j);
}
/* Test 4:
@@ -200,7 +222,7 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
memset(bits, 0, mask->mask_len * 4);
for (j = 0; j <= XI2LASTEVENT; j++)
{
- SetBit(bits, j);
+ _set_bit(bits, j);
request_XISelectEvent(req, Success);
}
@@ -227,8 +249,8 @@ static void request_XISelectEvents_masks(xXISelectEventsReq *req)
mask->mask_len = (nmasks + 3)/4;
memset(bits, 0, mask->mask_len * 4);
for (j = 0; j <= XI2LASTEVENT; j++)
- SetBit(bits, j);
- ClearBit(bits, XI_HierarchyChanged);
+ _set_bit(bits, j);
+ _clear_bit(bits, XI_HierarchyChanged);
for (j = 1; j < 6; j++)
{
mask->deviceid = j;