1/**
2 * Copyright © 2009 Red Hat, Inc.
3 *
4 *  Permission is hereby granted, free of charge, to any person obtaining a
5 *  copy of this software and associated documentation files (the "Software"),
6 *  to deal in the Software without restriction, including without limitation
7 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 *  and/or sell copies of the Software, and to permit persons to whom the
9 *  Software is furnished to do so, subject to the following conditions:
10 *
11 *  The above copyright notice and this permission notice (including the next
12 *  paragraph) shall be included in all copies or substantial portions of the
13 *  Software.
14 *
15 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 *  DEALINGS IN THE SOFTWARE.
22 */
23
24/* Test relies on assert() */
25#undef NDEBUG
26
27#ifdef HAVE_DIX_CONFIG_H
28#include <dix-config.h>
29#endif
30
31/*
32 * Protocol testing for XISetClientPointer request.
33 *
34 * Tests include:
35 * BadDevice of all devices except master pointers.
36 * Success for a valid window.
37 * Success for window None.
38 * BadWindow for invalid windows.
39 */
40#include <stdint.h>
41#include <X11/X.h>
42#include <X11/Xproto.h>
43#include <X11/extensions/XI2proto.h>
44#include "inputstr.h"
45#include "windowstr.h"
46#include "extinit.h"            /* for XInputExtensionInit */
47#include "scrnintstr.h"
48#include "xisetclientpointer.h"
49#include "exevents.h"
50#include "exglobals.h"
51
52#include "protocol-common.h"
53
54extern ClientRec client_window;
55static ClientRec client_request;
56
57static void
58request_XISetClientPointer(xXISetClientPointerReq * req, int error)
59{
60    int rc;
61
62    client_request = init_client(req->length, req);
63
64    rc = ProcXISetClientPointer(&client_request);
65    assert(rc == error);
66
67    if (rc == BadDevice)
68        assert(client_request.errorValue == req->deviceid);
69
70    client_request.swapped = TRUE;
71    swapl(&req->win);
72    swaps(&req->length);
73    swaps(&req->deviceid);
74    rc = SProcXISetClientPointer(&client_request);
75    assert(rc == error);
76
77    if (rc == BadDevice)
78        assert(client_request.errorValue == req->deviceid);
79
80}
81
82static void
83test_XISetClientPointer(void)
84{
85    int i;
86    xXISetClientPointerReq request;
87
88    request_init(&request, XISetClientPointer);
89
90    request.win = CLIENT_WINDOW_ID;
91
92    printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
93    request.deviceid = XIAllDevices;
94    request_XISetClientPointer(&request, BadDevice);
95
96    request.deviceid = XIAllMasterDevices;
97    request_XISetClientPointer(&request, BadDevice);
98
99    printf("Testing Success for VCP and VCK.\n");
100    request.deviceid = devices.vcp->id; /* 2 */
101    request_XISetClientPointer(&request, Success);
102    assert(client_window.clientPtr->id == 2);
103
104    request.deviceid = devices.vck->id; /* 3 */
105    request_XISetClientPointer(&request, Success);
106    assert(client_window.clientPtr->id == 2);
107
108    printf("Testing BadDevice error for all other devices.\n");
109    for (i = 4; i <= 0xFFFF; i++) {
110        request.deviceid = i;
111        request_XISetClientPointer(&request, BadDevice);
112    }
113
114    printf("Testing window None\n");
115    request.win = None;
116    request.deviceid = devices.vcp->id; /* 2 */
117    request_XISetClientPointer(&request, Success);
118    assert(client_request.clientPtr->id == 2);
119
120    printf("Testing invalid window\n");
121    request.win = INVALID_WINDOW_ID;
122    request.deviceid = devices.vcp->id;
123    request_XISetClientPointer(&request, BadWindow);
124
125}
126
127int
128protocol_xisetclientpointer_test(void)
129{
130    init_simple();
131    client_window = init_client(0, NULL);
132
133    test_XISetClientPointer();
134
135    return 0;
136}
137