summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-01 17:41:34 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-01 18:11:09 -0700
commitc4e255dc08c8caee1c0b0bffbe75d5e8a372ee56 (patch)
tree3c906e2c10444516d6fd9e75cc6d57f66b7fc9b4 /tests
parent384a32923590df0b58aa7b862ca894f36e3eb502 (diff)
Add libxcb/xcb_read_packet test
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/libxcb/Makefile.am31
-rw-r--r--tests/libxcb/xcb_read_packet.c70
3 files changed, 105 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6adcb01..3b41f5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,3 +23,7 @@
SUBDIRS = libX11
SUBDIRS += libXi
+
+if HAVE_XCB
+SUBDIRS += libxcb
+endif
diff --git a/tests/libxcb/Makefile.am b/tests/libxcb/Makefile.am
new file mode 100644
index 0000000..31c77f4
--- /dev/null
+++ b/tests/libxcb/Makefile.am
@@ -0,0 +1,31 @@
+#
+# 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 = xcb_read_packet
+
+AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)/include
+AM_CFLAGS = $(CWARNFLAGS) $(LIBXCB_CFLAGS)
+LDADD = -L$(top_builddir)/src -lXhiv $(LIBXCB_LIBS)
+
+TESTS = $(noinst_PROGRAMS)
+
diff --git a/tests/libxcb/xcb_read_packet.c b/tests/libxcb/xcb_read_packet.c
new file mode 100644
index 0000000..2a92ba7
--- /dev/null
+++ b/tests/libxcb/xcb_read_packet.c
@@ -0,0 +1,70 @@
+/*
+ * 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 <xcb/xcb.h>
+#include <xcb/xproto.h>
+#include <assert.h>
+#include <stdio.h>
+#include <limits.h>
+
+/* Tests the basic packet reading code in libxcb's xcb_in.c */
+
+static void
+testOverflowFields(void)
+{
+ const xcb_get_motion_events_reply_t rep1 = {
+ .response_type = XCB_GET_MOTION_EVENTS,
+ .length = (UINT_MAX / 4) + 12,
+ .events_len = (UINT_MAX / 2) + 6
+ };
+ xhiv_response response1 = {
+ .reqType = XCB_GET_MOTION_EVENTS,
+ .reqMinor = XHIV_REQ_IGNORE,
+ .sequence = XHIV_SEQ_IGNORE,
+ .length = (sizeof(rep1) >> 2) + rep1.length,
+ .response_data = &rep1,
+ .response_datalen = sizeof(rep1)
+ };
+ xcb_connection_t *conn = xhiv_connect(&response1);
+ xcb_get_motion_events_cookie_t cookie;
+ xcb_get_motion_events_reply_t *rep;
+
+ printf("xcb read_packet: overflow reply length test\n");
+ cookie = xcb_get_motion_events (conn, 0, 0, 0);
+ rep = xcb_get_motion_events_reply(conn, cookie, NULL);
+ assert(rep == NULL);
+
+ xhiv_disconnect(conn, xhiv_conn_error_allowed);
+}
+
+int
+main(int argc, char **argv)
+{
+ testOverflowFields();
+ printf("xcb read_packet: all tests passed\n");
+ return 0;
+}