summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-05 18:23:40 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-05 18:25:17 -0700
commitfa88ecdc13adb07cbad6f0420cbbd1657bbb33b1 (patch)
tree0f4073be8da0a2a911c3e1b4e7a9fe1e5644045e /tests
parent58e6058462aa0de727ac887d414c18bdab02ac74 (diff)
Add libX11/XkbGetMap test (doesn't work yet)
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/libX11/Makefile.am1
-rw-r--r--tests/libX11/XkbGetMap.c109
2 files changed, 110 insertions, 0 deletions
diff --git a/tests/libX11/Makefile.am b/tests/libX11/Makefile.am
index ecc470d..44d6559 100644
--- a/tests/libX11/Makefile.am
+++ b/tests/libX11/Makefile.am
@@ -28,6 +28,7 @@ noinst_PROGRAMS += XListFontsWithInfo
noinst_PROGRAMS += XListHosts
noinst_PROGRAMS += XQueryFont
noinst_PROGRAMS += XkbGetDeviceInfo
+noinst_PROGRAMS += XkbGetMap
noinst_HEADERS = xhiv-Xkb.h
diff --git a/tests/libX11/XkbGetMap.c b/tests/libX11/XkbGetMap.c
new file mode 100644
index 0000000..e0715df
--- /dev/null
+++ b/tests/libX11/XkbGetMap.c
@@ -0,0 +1,109 @@
+/*
+ * 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 "xhiv-Xkb.h"
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XKBproto.h>
+#include <assert.h>
+#include <stdio.h>
+
+#define MY_XKB_EXT_CODE 200
+
+static void
+testOverflowFields(void)
+{
+ /* Test overflow of .firstKeySym + .nKeySyms > .maxKeyCode */
+ const xkbGetMapReply rep1 = {
+ .type = X_Reply,
+ .length = 1024,
+ .minKeyCode = 1,
+ .maxKeyCode = 2,
+ .firstKeySym = 128,
+ .totalSyms = 128,
+ .nKeySyms = 128,
+ };
+ xhiv_response response1 = {
+ .next = &xkb_use_response,
+ .reqType = MY_XKB_EXT_CODE,
+ .reqMinor = X_kbGetMap,
+ .sequence = 101,
+ .length = (SIZEOF(xkbGetMapReply) >> 2),
+ .response_data = &rep1,
+ .response_datalen = sizeof(rep1)
+ };
+ /* Test overflow of .firstKeyAct + .nKeyActs > .maxKeyCode */
+ const xkbGetMapReply rep2 = {
+ .type = X_Reply,
+ .length = 1024,
+ .minKeyCode = 1,
+ .maxKeyCode = 2,
+ .firstKeyAct = 128,
+ .totalActs = 128,
+ .nKeyActs = 128,
+ };
+ xhiv_response response2 = {
+ .next = &response1,
+ .reqType = MY_XKB_EXT_CODE,
+ .reqMinor = X_kbGetMap,
+ .sequence = 102,
+ .length = (SIZEOF(xkbGetMapReply) >> 2),
+ .response_data = &rep2,
+ .response_datalen = sizeof(rep2)
+ };
+ Display *dpy = XhivOpenDisplay(&response2);
+ XkbDescPtr desc;
+
+ /* set sequence to known value so that later calls match by sequence num */
+ XhivSequenceSync(dpy, 100);
+
+ printf("XkbGetMap: overflow test - firstKeySym\n");
+ desc = XkbGetMap(dpy, XkbXI_AllFeaturesMask, XkbUseCoreKbd);
+ /* Which function to use to free ? */
+ assert(desc == NULL);
+
+ printf("XkbGetMap: overflow test - firstKeyAct\n");
+ desc = XkbGetMap(dpy, XkbXI_AllFeaturesMask, XkbUseCoreKbd);
+ /* Which function to use to free ? */
+ assert(desc == NULL);
+
+ XhivCloseDisplay(dpy);
+}
+
+int
+main(int argc, char **argv)
+{
+#if 0
+ testOverflowFields();
+ printf("XkbGetMap: all tests passed\n");
+ return 0;
+#else
+ printf("XkbGetMap: untested\n");
+ return 77;
+#endif
+}