/* Compile with cc -o testcase-13522 testcase-13522.c -lXi -lX11 */ /************************************************************************* Major portions lifted from libXi sources, which are covered by: Copyright 1989, 1998 The Open Group Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice 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 OPEN GROUP 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. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. Copyright 1989 by Hewlett-Packard Company, Palo Alto, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *************************************************************************/ #include #include #include #include #include #include #include #include typedef struct _XExtDisplayInfo { struct _XExtDisplayInfo *next; /* keep a linked list */ Display *display; /* which display this is */ XExtCodes *codes; /* the extension protocol codes */ XPointer data; /* extra data for extension to use */ } XExtDisplayInfo; extern XExtDisplayInfo * XInput_find_display(Display*); extern int _XDefaultError(Display *dpy, XErrorEvent *event); static int myXErrorCallback(Display *dpy, XErrorEvent *event) { if (event->error_code == BadLength) { printf("TEST PASSED: illegal call returned BadLength\n"); XCloseDisplay(dpy); exit(0); } else { return _XDefaultError(dpy, event); } } static int testChangeDeviceDontPropagateList(Display *dpy, Window window) { xChangeDeviceDontPropagateListReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing ChangeDeviceDontPropagateList...\n"); GetReq(ChangeDeviceDontPropagateList, req); req->reqType = info->codes->major_opcode; req->ReqType = X_ChangeDeviceDontPropagateList; req->window = window; req->count = 0xffff; req->mode = AddToList; SyncHandle(); return (Success); } static int testChangeDeviceKeyMapping(Display *dpy, Window window) { xChangeDeviceKeyMappingReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing ChangeDeviceKeyMapping...\n"); GetReq(ChangeDeviceKeyMapping,req); req->reqType = info->codes->major_opcode; req->ReqType = X_ChangeDeviceKeyMapping; req->deviceid = 0; req->firstKeyCode = 0x10; req->keyCodes = 0xff; req->keySymsPerKeyCode = 0xff; SyncHandle(); return (Success); } static int testGrabDevice(Display *dpy, Window window) { xGrabDeviceReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing GrabDevice...\n"); GetReq(GrabDevice,req); req->reqType = info->codes->major_opcode; req->ReqType = X_GrabDevice; req->deviceid = 0; req->grabWindow = window; req->ownerEvents = 0; req->event_count = 0xffff; req->this_device_mode = 0; req->other_devices_mode = 0; SyncHandle(); return (Success); } static int testGrabDeviceButton(Display *dpy, Window window) { xGrabDeviceButtonReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing GrabDeviceButton...\n"); GetReq(GrabDeviceButton,req); req->reqType = info->codes->major_opcode; req->ReqType = X_GrabDeviceButton; req->grabbed_device = 0; req->button = 0; req->modifiers = 0; req->modifier_device = UseXKeyboard; req->grabWindow = window; req->ownerEvents = 0; req->event_count = 0xffff; req->this_device_mode = 0; req->other_devices_mode = 0; SyncHandle(); return (Success); } static int testGrabDeviceKey(Display *dpy, Window window) { xGrabDeviceKeyReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing GrabDeviceKey...\n"); GetReq(GrabDeviceKey,req); req->reqType = info->codes->major_opcode; req->ReqType = X_GrabDeviceKey; req->grabbed_device = 0; req->key = 0; req->modifiers = 0; req->modifier_device = UseXKeyboard; req->grabWindow = window; req->ownerEvents = 0; req->event_count = 0xffff; req->this_device_mode = 0; req->other_devices_mode = 0; SyncHandle(); return (Success); } static int testSelectExtensionEvent(Display *dpy, Window window) { xSelectExtensionEventReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing SelectExtensionEvent...\n"); GetReq(SelectExtensionEvent,req); req->reqType = info->codes->major_opcode; req->ReqType = X_SelectExtensionEvent; req->window = window; req->count = 0xffff; SyncHandle(); return (Success); } static int testSendExtensionEvent(Display *dpy, Window window) { xSendExtensionEventReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); printf("Testing SendExtensionEvent...\n"); GetReq(SendExtensionEvent, req); req->reqType = info->codes->major_opcode; req->ReqType = X_SendExtensionEvent; req->deviceid = 0; req->destination = 0; req->propagate = 0; req->count = 0xffff; req->num_events = 0; SyncHandle(); return (Success); } void usage (char *progname) { fprintf(stderr, "Usage: %s -\n" " -1 : Test ChangeDeviceDontPropagateList\n" " -2 : Test ChangeDeviceKeyMapping\n" " -3 : Test GrabDevice\n" " -4 : Test GrabDeviceButton\n" " -5 : Test GrabDeviceKey\n" " -6 : Test SelectExtensionEvent\n" " -7 : Test SendExtensionEvent\n", progname); exit(2); } int main(int argc, char **argv) { int testno; int result = 0; Display *dpy; Window win; int reqcode, major, minor; if (argc != 2) { usage(argv[0]); } dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Can't open display %s\n", XDisplayName(NULL)); exit(1); } if (XQueryExtension(dpy, INAME, &reqcode, &major, &minor) != 1) { printf("%s Extension NOT present on display - cannot test\n", INAME); return 1; } win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 100, 100, 0, BlackPixel(dpy,0), WhitePixel(dpy,0)); XSync(dpy, False); XSetErrorHandler(myXErrorCallback); testno = abs(atoi(argv[1])); switch (testno) { case 1: result = testChangeDeviceDontPropagateList(dpy, win); break; case 2: result = testChangeDeviceKeyMapping(dpy, win); break; case 3: result = testGrabDevice(dpy, win); break; case 4: result = testGrabDeviceButton(dpy, win); break; case 5: result = testGrabDeviceKey(dpy, win); break; case 6: result = testSelectExtensionEvent(dpy, win); break; case 7: result = testSendExtensionEvent(dpy, win); break; default: usage(argv[0]); } if (result == 0) { XSync(dpy, False); printf("TEST FAILED: Did not recieve BadLength error message!\n"); } XDestroyWindow(dpy, win); XCloseDisplay(dpy); return result; }