diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-05-04 23:11:36 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-05-05 18:25:17 -0700 |
commit | 5912e92e875592215185ba5a06995f4bdeafa33f (patch) | |
tree | e14472bdcba59bbf6f23bba64e8845a6592cde56 /tests | |
parent | a45d8b5a8972b4e15dd99b3bc25775b969760f88 (diff) |
Add libXrandr/XRRGetOutputProperty test
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/libXrandr/Makefile.am | 33 | ||||
-rw-r--r-- | tests/libXrandr/XRRGetOutputProperty.c | 93 | ||||
-rw-r--r-- | tests/libXrandr/xhiv-Xrandr.h | 79 |
4 files changed, 206 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index b77f247..8a55a6f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,6 +25,7 @@ SUBDIRS = libX11 SUBDIRS += libXext SUBDIRS += libXi SUBDIRS += libXinerama +SUBDIRS += libXrandr if HAVE_XCB SUBDIRS += libxcb diff --git a/tests/libXrandr/Makefile.am b/tests/libXrandr/Makefile.am new file mode 100644 index 0000000..3be9ea4 --- /dev/null +++ b/tests/libXrandr/Makefile.am @@ -0,0 +1,33 @@ +# +# 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 = XRRGetOutputProperty + +noinst_HEADERS = xhiv-Xrandr.h + +AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)/include +AM_CFLAGS = $(CWARNFLAGS) $(LIBXRANDR_CFLAGS) +LDADD = -L$(top_builddir)/src -lXhiv $(LIBXRANDR_LIBS) + +TESTS = $(noinst_PROGRAMS) + diff --git a/tests/libXrandr/XRRGetOutputProperty.c b/tests/libXrandr/XRRGetOutputProperty.c new file mode 100644 index 0000000..339eb56 --- /dev/null +++ b/tests/libXrandr/XRRGetOutputProperty.c @@ -0,0 +1,93 @@ +/* + * 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/Xatom.h> +#include "xhiv-Xrandr.h" +#include <assert.h> +#include <stdio.h> +#include <limits.h> + +static void +testOverflowFields(void) +{ + const xRRGetOutputPropertyReply rep1 = { + .type = X_Reply, + .length = 32, + .propertyType = XA_ATOM, + .nItems = (UINT_MAX / 4) + 2, + .format = 32, + }; + xhiv_response response1 = { + .next = &xrandr_vers_response, + .reqType = MY_XRANDR_EXT_CODE, + .reqMinor = X_RRGetOutputProperty, + .sequence = XHIV_SEQ_IGNORE, + .length = (sizeof(rep1) >> 2) + rep1.length, + .response_data = &rep1, + .response_datalen = sizeof(rep1) + }; + Display *dpy = XhivOpenDisplay(&response1); + int major = MY_XRANDR_MAJOR_VERSION; + int minor = MY_XRANDR_MINOR_VERSION; + int status; + Atom type_return; + int format_return; + unsigned long num_items_return, bytes_after_return; + unsigned char *data = NULL; + + status = XRRQueryVersion(dpy, &major, &minor); + assert(status != 0); + + printf("XRRGetOutputProperty: overflow number of items test\n"); + status = XRRGetOutputProperty(dpy, + /* output */ 0, /* property */ 0, + /* offset */ 0, /* length */ 0, + /* delete_property */ False, + /* pending */ False, + /* type */ XA_ATOM, + &type_return, &format_return, + &num_items_return, &bytes_after_return, + &data); + XFree(data); + assert(status != Success); + assert(data == NULL); + assert(type_return == None); + assert(format_return == 0); + assert(num_items_return == 0); + assert(bytes_after_return == 0); + + XhivCloseDisplay(dpy); +} + +int +main(int argc, char **argv) +{ + testOverflowFields(); + printf("XRRGetOutputProperty: all tests passed\n"); + return 0; +} diff --git a/tests/libXrandr/xhiv-Xrandr.h b/tests/libXrandr/xhiv-Xrandr.h new file mode 100644 index 0000000..78fecd2 --- /dev/null +++ b/tests/libXrandr/xhiv-Xrandr.h @@ -0,0 +1,79 @@ +/* + * 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/Xproto.h> +#include <X11/extensions/Xrandr.h> +#include <X11/extensions/randrproto.h> + +/* Common definitions for RANDR extension tests */ + +#define MY_XRANDR_EXT_CODE 220 + +/* Report that RANDR is present */ +static const xQueryExtensionReply xrandr_qext_reply = { + .type = X_Reply, + .length = 0, + .present = xTrue, + .major_opcode = MY_XRANDR_EXT_CODE, + .first_event = 100, + .first_error = 150 +}; +static xhiv_response xrandr_qext_response = { + .next = NULL, + .reqType = X_QueryExtension, + .reqMinor = XHIV_REQ_IGNORE, + .sequence = XHIV_SEQ_MATCHDATA, + .match_data = RANDR_NAME, + .length = (SIZEOF(xQueryExtensionReply) >> 2), + .response_data = &xrandr_qext_reply, + .response_datalen = sizeof(xrandr_qext_reply) +}; + +/* Report current RANDR version 1.4 by default */ +#ifndef MY_XRANDR_MAJOR_VERSION +# define MY_XRANDR_MAJOR_VERSION 1 +#endif + +#ifndef MY_XRANDR_MINOR_VERSION +# define MY_XRANDR_MINOR_VERSION 4 +#endif + +static const xRRQueryVersionReply xrandr_vers_reply = { + .type = X_Reply, + .length = 0, + .majorVersion = MY_XRANDR_MAJOR_VERSION, + .minorVersion = MY_XRANDR_MINOR_VERSION +}; +static xhiv_response xrandr_vers_response = { + .next = &xrandr_qext_response, + .reqType = MY_XRANDR_EXT_CODE, + .reqMinor = X_RRQueryVersion, + .sequence = XHIV_SEQ_IGNORE, + .length = (SIZEOF(xRRQueryVersionReply) >> 2), + .response_data = &xrandr_vers_reply, + .response_datalen = sizeof(xrandr_vers_reply) +}; |