summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-27 17:04:58 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-28 12:12:30 -0700
commit86bd3d63c1a4741f40bb09de1fe7deb519319985 (patch)
tree71aec258be65f07e89405661f4c7636adbcb4a6e /tests
parentd1b93507a6db55242a3d12ad485695bbb5399977 (diff)
Add libXi/XGetDeviceButtonMapping test
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/libXi/Makefile.am34
-rw-r--r--tests/libXi/XGetDeviceButtonMapping.c117
-rw-r--r--tests/libXi/xhiv-Xi.h99
4 files changed, 251 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a0fa803..6adcb01 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,3 +22,4 @@
#
SUBDIRS = libX11
+SUBDIRS += libXi
diff --git a/tests/libXi/Makefile.am b/tests/libXi/Makefile.am
new file mode 100644
index 0000000..8c33efa
--- /dev/null
+++ b/tests/libXi/Makefile.am
@@ -0,0 +1,34 @@
+#
+# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+#
+# 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.
+#
+
+noinst_PROGRAMS = XGetDeviceButtonMapping
+
+noinst_HEADERS = xhiv-Xi.h
+
+AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)/include
+AM_CFLAGS = $(CWARNFLAGS) $(LIBXI_CFLAGS)
+LDADD = -L$(top_builddir)/src -lXhiv $(LIBXI_LIBS)
+# ../../src/xstrans.o ../../src/server.o ../../src/xlib_client.o
+
+TESTS = $(noinst_PROGRAMS)
+
diff --git a/tests/libXi/XGetDeviceButtonMapping.c b/tests/libXi/XGetDeviceButtonMapping.c
new file mode 100644
index 0000000..dd625f3
--- /dev/null
+++ b/tests/libXi/XGetDeviceButtonMapping.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ *
+ * 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_CONFIG_H
+# include "config.h"
+#endif
+
+#include "xhiv.h"
+#include <X11/Xlib.h>
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XIproto.h>
+#include "xhiv-Xi.h"
+#include <assert.h>
+#include <stdio.h>
+
+
+
+static void
+testOverflowFields(void)
+{
+ const xGetDeviceButtonMappingReply rep1 = {
+ .repType = X_Reply,
+ .RepType = X_GetDeviceButtonMapping,
+ .nElts = 255,
+ .length = 256 >> 2
+ };
+ const xGetDeviceButtonMappingReply rep2 = {
+ .repType = X_Reply,
+ .RepType = X_GetDeviceButtonMapping,
+ .nElts = 255,
+ .length = 1024
+ };
+ xhiv_response response2 = {
+ .next = &xi_opendev_response,
+ .reqType = MY_XI_EXT_CODE,
+ .reqMinor = X_GetDeviceButtonMapping,
+ .sequence = 102,
+ .length = rep2.length + (sizeof(rep2) >> 2),
+ .response_data = &rep2,
+ .response_datalen = sizeof(rep2)
+ };
+ xhiv_response response1 = {
+ .next = &response2,
+ .reqType = MY_XI_EXT_CODE,
+ .reqMinor = X_GetDeviceButtonMapping,
+ .sequence = 101,
+ .length = rep1.length + (sizeof(rep1) >> 2),
+ .response_data = &rep1,
+ .response_datalen = sizeof(rep1)
+ };
+ Display *dpy = XhivOpenDisplay(&response1);
+ XDevice *device;
+ int status;
+ unsigned char map[260];
+
+ device = XOpenDevice(dpy, MY_DEFAULT_DEVICE);
+ assert(device != NULL);
+ assert(device != (XDevice *) NoSuchExtension);
+
+ /* set sequence to known value so that later calls match by sequence num */
+ XhivSequenceSync(dpy, 100);
+
+ printf("XGetDeviceButtonMapping: overflow caller buffer test\n");
+ map[16] = 0xde;
+ map[17] = 0xad;
+ map[18] = 0xbe;
+ map[19] = 0xef;
+ status = XGetDeviceButtonMapping(dpy, device, map, 16);
+ assert(status == 255);
+ assert(map[16] == 0xde);
+ assert(map[17] == 0xad);
+ assert(map[18] == 0xbe);
+ assert(map[19] == 0xef);
+
+ /* libXi had a hardcoded 256 char buffer it assumed the server wouldn't
+ overflow */
+ printf("XGetDeviceButtonMapping: overflow library buffer test\n");
+ map[256] = 0xde;
+ map[257] = 0xad;
+ map[258] = 0xbe;
+ map[259] = 0xef;
+ status = XGetDeviceButtonMapping(dpy, device, map, 256);
+ assert(status == 0);
+ assert(map[256] == 0xde);
+ assert(map[257] == 0xad);
+ assert(map[258] == 0xbe);
+ assert(map[259] == 0xef);
+
+ XhivCloseDisplay(dpy);
+}
+
+int
+main(int argc, char **argv)
+{
+ testOverflowFields();
+ printf("XGetDeviceButtonMapping: all tests passed\n");
+ return 0;
+}
diff --git a/tests/libXi/xhiv-Xi.h b/tests/libXi/xhiv-Xi.h
new file mode 100644
index 0000000..6b0f077
--- /dev/null
+++ b/tests/libXi/xhiv-Xi.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ *
+ * 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_CONFIG_H
+# include "config.h"
+#endif
+
+#include "xhiv.h"
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+
+/* Common definitions for Xinput extension tests */
+
+#define MY_XI_EXT_CODE 218
+
+/* Report that Xi is present */
+static const xQueryExtensionReply xi_qext_reply = {
+ .type = X_Reply,
+ .length = 0,
+ .present = xTrue,
+ .major_opcode = MY_XI_EXT_CODE,
+ .first_event = 100,
+ .first_error = 150
+};
+static xhiv_response xi_qext_response = {
+ .next = NULL,
+ .reqType = X_QueryExtension,
+ .reqMinor = XHIV_REQ_IGNORE,
+ .sequence = XHIV_SEQ_MATCHDATA,
+ .match_data = INAME,
+ .length = (SIZEOF(xQueryExtensionReply) >> 2),
+ .response_data = &xi_qext_reply,
+ .response_datalen = sizeof(xi_qext_reply)
+};
+
+/* Report default Xinput 1.x version */
+#ifndef MY_XI_MAJOR_VERSION
+# define MY_XI_MAJOR_VERSION 1
+#endif
+
+#ifndef MY_XI_MINOR_VERSION
+# define MY_XI_MINOR_VERSION 5
+#endif
+
+static const xGetExtensionVersionReply xi_vers_reply = {
+ .repType = X_Reply,
+ .RepType = X_GetExtensionVersion,
+ .length = 0,
+ .major_version = MY_XI_MAJOR_VERSION,
+ .minor_version = MY_XI_MINOR_VERSION,
+ .present = xTrue
+};
+static xhiv_response xi_vers_response = {
+ .next = &xi_qext_response,
+ .reqType = MY_XI_EXT_CODE,
+ .reqMinor = X_GetExtensionVersion,
+ .sequence = XHIV_SEQ_IGNORE,
+ .length = (SIZEOF(xQueryExtensionReply) >> 2),
+ .response_data = &xi_vers_reply,
+ .response_datalen = sizeof(xi_vers_reply)
+};
+
+
+/* Provide a simple default device for XOpenDevice */
+#define MY_DEFAULT_DEVICE 1
+static const xOpenDeviceReply xi_opendev_reply = {
+ .repType = X_Reply,
+ .RepType = X_OpenDevice,
+ .length = sizeof(xInputClassInfo),
+ .num_classes = 1
+};
+static xhiv_response xi_opendev_response = {
+ .next = &xi_vers_response,
+ .reqType = MY_XI_EXT_CODE,
+ .reqMinor = X_OpenDevice,
+ .sequence = XHIV_SEQ_IGNORE,
+ .length = (SIZEOF(xOpenDeviceReply) >> 2) + sizeof(xInputClassInfo),
+ .response_data = &xi_opendev_reply,
+ .response_datalen = sizeof(xi_opendev_reply)
+};