summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-01 21:34:46 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-01 21:35:26 -0700
commite185ab594031eb208bb35f52034d5af028986373 (patch)
tree5c6c59f98e596a7ee3f0117dbc6ee537e2293656
parente7749f41060b8f49c938a880ecfa51d0a9764d02 (diff)
Add libXext/XcupStoreColors test (partially working)
Successfully gets error return from new code, but tends to get IOErrors, not overflow, from old code. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--tests/libXext/Makefile.am1
-rw-r--r--tests/libXext/XcupStoreColors.c113
2 files changed, 114 insertions, 0 deletions
diff --git a/tests/libXext/Makefile.am b/tests/libXext/Makefile.am
index 9ee453d..9799bc0 100644
--- a/tests/libXext/Makefile.am
+++ b/tests/libXext/Makefile.am
@@ -22,6 +22,7 @@
#
noinst_PROGRAMS = XcupGetReservedColormapEntries
+noinst_PROGRAMS += XcupStoreColors
AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)/include
AM_CFLAGS = $(CWARNFLAGS) $(LIBXEXT_CFLAGS)
diff --git a/tests/libXext/XcupStoreColors.c b/tests/libXext/XcupStoreColors.c
new file mode 100644
index 0000000..b5d2ec7
--- /dev/null
+++ b/tests/libXext/XcupStoreColors.c
@@ -0,0 +1,113 @@
+/*
+ * 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/Xproto.h>
+#include <X11/extensions/Xcup.h>
+#include <X11/extensions/cupproto.h>
+#include <assert.h>
+#include <stdio.h>
+#include <limits.h>
+
+#define MY_CUP_EXT_CODE 202
+
+static void
+testOverflowFields(void)
+{
+ /* Report that CUP is present */
+ const xQueryExtensionReply cupqext_reply = {
+ .type = X_Reply,
+ .length = 0,
+ .present = xTrue,
+ .major_opcode = MY_CUP_EXT_CODE,
+ .first_event = 100,
+ .first_error = 150
+ };
+ xhiv_response cupqext_response = {
+ .next = NULL,
+ .reqType = X_QueryExtension,
+ .reqMinor = XHIV_REQ_IGNORE,
+ .sequence = XHIV_SEQ_MATCHDATA,
+ .match_data = XCUPNAME,
+ .length = (SIZEOF(xQueryExtensionReply) >> 2),
+ .response_data = &cupqext_reply,
+ .response_datalen = sizeof(cupqext_reply)
+ };
+
+ const xXcupQueryVersionReply cupvers_reply = {
+ .type = X_Reply,
+ .length = 0,
+ .server_major_version = XCUP_MAJOR_VERSION,
+ .server_minor_version = XCUP_MINOR_VERSION
+ };
+ xhiv_response cupvers_response = {
+ .next = &cupqext_response,
+ .reqType = MY_CUP_EXT_CODE,
+ .reqMinor = X_XcupQueryVersion,
+ .sequence = XHIV_SEQ_IGNORE,
+ .length = (SIZEOF(xQueryExtensionReply) >> 2),
+ .response_data = &cupvers_reply,
+ .response_datalen = sizeof(cupvers_reply)
+ };
+
+ const xXcupStoreColorsReply rep1 = {
+ .type = X_Reply,
+ .pad1 = X_XcupStoreColors,
+ /* XXX: need to find right number to trigger bug but not XIOError */
+ .length = (INT_MAX / 12),
+ };
+ xhiv_response response1 = {
+ .next = &cupvers_response,
+ .reqType = MY_CUP_EXT_CODE,
+ .reqMinor = X_XcupStoreColors,
+ .sequence = XHIV_SEQ_IGNORE,
+ .length = (sizeof(rep1) >> 2) + rep1.length,
+ .response_data = &rep1,
+ .response_datalen = sizeof(rep1)
+ };
+ Display *dpy = XhivOpenDisplay(&response1);
+ XColor colors_in_out[257];
+ int ncolors = 257, status;
+ int major = XCUP_MAJOR_VERSION, minor = XCUP_MINOR_VERSION;
+
+ status = XcupQueryVersion(dpy, &major, &minor);
+ assert(status == True);
+
+ printf("XcupStoreColors: overflow number of entries test\n");
+ status = XcupStoreColors(dpy, 0xdeadbeef, colors_in_out, ncolors);
+ assert(status == False);
+
+ XhivCloseDisplay(dpy);
+}
+
+int
+main(int argc, char **argv)
+{
+ testOverflowFields();
+ printf("XcupStoreColors: all tests passed\n");
+ return 0;
+}