protocol-xiquerypointer.c revision f7df2e56
16747b715Smrg/**
26747b715Smrg * Copyright © 2009 Red Hat, Inc.
36747b715Smrg *
46747b715Smrg *  Permission is hereby granted, free of charge, to any person obtaining a
56747b715Smrg *  copy of this software and associated documentation files (the "Software"),
66747b715Smrg *  to deal in the Software without restriction, including without limitation
76747b715Smrg *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
86747b715Smrg *  and/or sell copies of the Software, and to permit persons to whom the
96747b715Smrg *  Software is furnished to do so, subject to the following conditions:
106747b715Smrg *
116747b715Smrg *  The above copyright notice and this permission notice (including the next
126747b715Smrg *  paragraph) shall be included in all copies or substantial portions of the
136747b715Smrg *  Software.
146747b715Smrg *
156747b715Smrg *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
166747b715Smrg *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176747b715Smrg *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
186747b715Smrg *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196747b715Smrg *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
206747b715Smrg *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
216747b715Smrg *  DEALINGS IN THE SOFTWARE.
226747b715Smrg */
236747b715Smrg
246747b715Smrg#ifdef HAVE_DIX_CONFIG_H
256747b715Smrg#include <dix-config.h>
266747b715Smrg#endif
276747b715Smrg
286747b715Smrg/*
296747b715Smrg * Protocol testing for XIQueryPointer request.
306747b715Smrg */
316747b715Smrg#include <stdint.h>
326747b715Smrg#include <X11/X.h>
336747b715Smrg#include <X11/Xproto.h>
346747b715Smrg#include <X11/extensions/XI2proto.h>
356747b715Smrg#include "inputstr.h"
366747b715Smrg#include "windowstr.h"
376747b715Smrg#include "scrnintstr.h"
386747b715Smrg#include "xiquerypointer.h"
396747b715Smrg#include "exevents.h"
40f7df2e56Smrg#include "exglobals.h"
416747b715Smrg
426747b715Smrg#include "protocol-common.h"
436747b715Smrg
446747b715Smrgstatic ClientRec client_request;
456747b715Smrgstatic void reply_XIQueryPointer_data(ClientPtr client, int len,
46f7df2e56Smrg                                      char *data, void *closure);
476747b715Smrg
486747b715Smrgstatic struct {
496747b715Smrg    DeviceIntPtr dev;
506747b715Smrg    WindowPtr win;
516747b715Smrg} test_data;
526747b715Smrg
536747b715Smrg/* dixLookupWindow requires a lot of setup not necessary for this test.
546747b715Smrg * Simple wrapper that returns either one of the fake root window or the
556747b715Smrg * fake client window. If the requested ID is neither of those wanted,
566747b715Smrg * return whatever the real dixLookupWindow does.
576747b715Smrg */
58f7df2e56Smrgint
59f7df2e56Smrg__wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
606747b715Smrg{
61f7df2e56Smrg    if (id == root.drawable.id) {
626747b715Smrg        *win = &root;
636747b715Smrg        return Success;
64f7df2e56Smrg    }
65f7df2e56Smrg    else if (id == window.drawable.id) {
666747b715Smrg        *win = &window;
676747b715Smrg        return Success;
686747b715Smrg    }
696747b715Smrg
706747b715Smrg    return __real_dixLookupWindow(win, id, client, access);
716747b715Smrg}
726747b715Smrg
73f7df2e56Smrgstatic void
74f7df2e56Smrgreply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
756747b715Smrg{
76f7df2e56Smrg    xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
776747b715Smrg    SpritePtr sprite;
786747b715Smrg
796747b715Smrg    if (!rep->repType)
806747b715Smrg        return;
816747b715Smrg
82f7df2e56Smrg    if (client->swapped) {
83f7df2e56Smrg        swapl(&rep->length);
84f7df2e56Smrg        swaps(&rep->sequenceNumber);
85f7df2e56Smrg        swapl(&rep->root);
86f7df2e56Smrg        swapl(&rep->child);
87f7df2e56Smrg        swapl(&rep->root_x);
88f7df2e56Smrg        swapl(&rep->root_y);
89f7df2e56Smrg        swapl(&rep->win_x);
90f7df2e56Smrg        swapl(&rep->win_y);
91f7df2e56Smrg        swaps(&rep->buttons_len);
926747b715Smrg    }
936747b715Smrg
946747b715Smrg    reply_check_defaults(rep, len, XIQueryPointer);
956747b715Smrg
96f7df2e56Smrg    assert(rep->root == root.drawable.id);
97f7df2e56Smrg    assert(rep->same_screen == xTrue);
986747b715Smrg
996747b715Smrg    sprite = test_data.dev->spriteInfo->sprite;
100f7df2e56Smrg    assert((rep->root_x >> 16) == sprite->hot.x);
101f7df2e56Smrg    assert((rep->root_y >> 16) == sprite->hot.y);
102f7df2e56Smrg
103f7df2e56Smrg    if (test_data.win == &root) {
104f7df2e56Smrg        assert(rep->root_x == rep->win_x);
105f7df2e56Smrg        assert(rep->root_y == rep->win_y);
106f7df2e56Smrg        assert(rep->child == window.drawable.id);
107f7df2e56Smrg    }
108f7df2e56Smrg    else {
1096747b715Smrg        int x, y;
1106747b715Smrg
1116747b715Smrg        x = sprite->hot.x - window.drawable.x;
1126747b715Smrg        y = sprite->hot.y - window.drawable.y;
1136747b715Smrg
114f7df2e56Smrg        assert((rep->win_x >> 16) == x);
115f7df2e56Smrg        assert((rep->win_y >> 16) == y);
116f7df2e56Smrg        assert(rep->child == None);
1176747b715Smrg    }
1186747b715Smrg
119f7df2e56Smrg    assert(rep->same_screen == xTrue);
1206747b715Smrg
1216747b715Smrg    reply_handler = reply_XIQueryPointer_data;
1226747b715Smrg}
1236747b715Smrg
124f7df2e56Smrgstatic void
125f7df2e56Smrgreply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
1266747b715Smrg{
1276747b715Smrg    reply_handler = reply_XIQueryPointer;
1286747b715Smrg}
1296747b715Smrg
130f7df2e56Smrgstatic void
131f7df2e56Smrgrequest_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
1326747b715Smrg{
1336747b715Smrg    int rc;
1346747b715Smrg
1356747b715Smrg    rc = ProcXIQueryPointer(&client_request);
136f7df2e56Smrg    assert(rc == error);
1376747b715Smrg
1386747b715Smrg    if (rc == BadDevice)
139f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1406747b715Smrg
1416747b715Smrg    client_request.swapped = TRUE;
142f7df2e56Smrg    swaps(&req->deviceid);
143f7df2e56Smrg    swaps(&req->length);
1446747b715Smrg    rc = SProcXIQueryPointer(&client_request);
145f7df2e56Smrg    assert(rc == error);
1466747b715Smrg
1476747b715Smrg    if (rc == BadDevice)
148f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1496747b715Smrg}
1506747b715Smrg
151f7df2e56Smrgstatic void
152f7df2e56Smrgtest_XIQueryPointer(void)
1536747b715Smrg{
1546747b715Smrg    int i;
1556747b715Smrg    xXIQueryPointerReq request;
1566747b715Smrg
1576747b715Smrg    memset(&request, 0, sizeof(request));
1586747b715Smrg
1596747b715Smrg    request_init(&request, XIQueryPointer);
1606747b715Smrg
1616747b715Smrg    reply_handler = reply_XIQueryPointer;
1626747b715Smrg
1636747b715Smrg    client_request = init_client(request.length, &request);
1646747b715Smrg
1656747b715Smrg    request.deviceid = XIAllDevices;
1666747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1676747b715Smrg
1686747b715Smrg    request.deviceid = XIAllMasterDevices;
1696747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1706747b715Smrg
1716747b715Smrg    request.win = root.drawable.id;
1726747b715Smrg    test_data.win = &root;
1736747b715Smrg
1746747b715Smrg    test_data.dev = devices.vcp;
1756747b715Smrg    request.deviceid = devices.vcp->id;
1766747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1776747b715Smrg    request.deviceid = devices.vck->id;
1786747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1796747b715Smrg    request.deviceid = devices.mouse->id;
1806747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1816747b715Smrg    request.deviceid = devices.kbd->id;
1826747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1836747b715Smrg
1846747b715Smrg    test_data.dev = devices.mouse;
185f7df2e56Smrg    devices.mouse->master = NULL;       /* Float, kind-of */
1866747b715Smrg    request.deviceid = devices.mouse->id;
1876747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1886747b715Smrg
189f7df2e56Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
1906747b715Smrg        request.deviceid = i;
1916747b715Smrg        request_XIQueryPointer(&client_request, &request, BadDevice);
1926747b715Smrg    }
1936747b715Smrg
1946747b715Smrg    request.win = window.drawable.id;
1956747b715Smrg
1966747b715Smrg    test_data.dev = devices.vcp;
1976747b715Smrg    test_data.win = &window;
1986747b715Smrg    request.deviceid = devices.vcp->id;
1996747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
2006747b715Smrg
2016747b715Smrg    test_data.dev = devices.mouse;
2026747b715Smrg    request.deviceid = devices.mouse->id;
2036747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
2040b0d8713Smrg
2050b0d8713Smrg    /* test REQUEST_SIZE_MATCH */
2060b0d8713Smrg    client_request.req_len -= 4;
2070b0d8713Smrg    request_XIQueryPointer(&client_request, &request, BadLength);
2086747b715Smrg}
2096747b715Smrg
210f7df2e56Smrgint
211f7df2e56Smrgmain(int argc, char **argv)
2126747b715Smrg{
2136747b715Smrg    init_simple();
2146747b715Smrg
215f7df2e56Smrg    test_XIQueryPointer();
2166747b715Smrg
217f7df2e56Smrg    return 0;
2186747b715Smrg}
219