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
245a112b11Smrg/* Test relies on assert() */
255a112b11Smrg#undef NDEBUG
265a112b11Smrg
276747b715Smrg#ifdef HAVE_DIX_CONFIG_H
286747b715Smrg#include <dix-config.h>
296747b715Smrg#endif
306747b715Smrg
316747b715Smrg/*
326747b715Smrg * Protocol testing for XIQueryPointer request.
336747b715Smrg */
346747b715Smrg#include <stdint.h>
356747b715Smrg#include <X11/X.h>
366747b715Smrg#include <X11/Xproto.h>
376747b715Smrg#include <X11/extensions/XI2proto.h>
386747b715Smrg#include "inputstr.h"
396747b715Smrg#include "windowstr.h"
406747b715Smrg#include "scrnintstr.h"
416747b715Smrg#include "xiquerypointer.h"
426747b715Smrg#include "exevents.h"
43f7df2e56Smrg#include "exglobals.h"
446747b715Smrg
456747b715Smrg#include "protocol-common.h"
466747b715Smrg
47806e81e9Smrgextern ClientRec client_window;
486747b715Smrgstatic ClientRec client_request;
496747b715Smrgstatic void reply_XIQueryPointer_data(ClientPtr client, int len,
50f7df2e56Smrg                                      char *data, void *closure);
516747b715Smrg
526747b715Smrgstatic struct {
536747b715Smrg    DeviceIntPtr dev;
546747b715Smrg    WindowPtr win;
556747b715Smrg} test_data;
566747b715Smrg
57f7df2e56Smrgstatic void
58f7df2e56Smrgreply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
596747b715Smrg{
60f7df2e56Smrg    xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
616747b715Smrg    SpritePtr sprite;
626747b715Smrg
636747b715Smrg    if (!rep->repType)
646747b715Smrg        return;
656747b715Smrg
66f7df2e56Smrg    if (client->swapped) {
67f7df2e56Smrg        swapl(&rep->length);
68f7df2e56Smrg        swaps(&rep->sequenceNumber);
69f7df2e56Smrg        swapl(&rep->root);
70f7df2e56Smrg        swapl(&rep->child);
71f7df2e56Smrg        swapl(&rep->root_x);
72f7df2e56Smrg        swapl(&rep->root_y);
73f7df2e56Smrg        swapl(&rep->win_x);
74f7df2e56Smrg        swapl(&rep->win_y);
75f7df2e56Smrg        swaps(&rep->buttons_len);
766747b715Smrg    }
776747b715Smrg
786747b715Smrg    reply_check_defaults(rep, len, XIQueryPointer);
796747b715Smrg
80f7df2e56Smrg    assert(rep->root == root.drawable.id);
81f7df2e56Smrg    assert(rep->same_screen == xTrue);
826747b715Smrg
836747b715Smrg    sprite = test_data.dev->spriteInfo->sprite;
84f7df2e56Smrg    assert((rep->root_x >> 16) == sprite->hot.x);
85f7df2e56Smrg    assert((rep->root_y >> 16) == sprite->hot.y);
86f7df2e56Smrg
87f7df2e56Smrg    if (test_data.win == &root) {
88f7df2e56Smrg        assert(rep->root_x == rep->win_x);
89f7df2e56Smrg        assert(rep->root_y == rep->win_y);
90f7df2e56Smrg        assert(rep->child == window.drawable.id);
91f7df2e56Smrg    }
92f7df2e56Smrg    else {
936747b715Smrg        int x, y;
946747b715Smrg
956747b715Smrg        x = sprite->hot.x - window.drawable.x;
966747b715Smrg        y = sprite->hot.y - window.drawable.y;
976747b715Smrg
98f7df2e56Smrg        assert((rep->win_x >> 16) == x);
99f7df2e56Smrg        assert((rep->win_y >> 16) == y);
100f7df2e56Smrg        assert(rep->child == None);
1016747b715Smrg    }
1026747b715Smrg
103f7df2e56Smrg    assert(rep->same_screen == xTrue);
1046747b715Smrg
1056747b715Smrg    reply_handler = reply_XIQueryPointer_data;
1066747b715Smrg}
1076747b715Smrg
108f7df2e56Smrgstatic void
109f7df2e56Smrgreply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
1106747b715Smrg{
1116747b715Smrg    reply_handler = reply_XIQueryPointer;
1126747b715Smrg}
1136747b715Smrg
114f7df2e56Smrgstatic void
115f7df2e56Smrgrequest_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
1166747b715Smrg{
1176747b715Smrg    int rc;
1186747b715Smrg
1196747b715Smrg    rc = ProcXIQueryPointer(&client_request);
120f7df2e56Smrg    assert(rc == error);
1216747b715Smrg
1226747b715Smrg    if (rc == BadDevice)
123f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1246747b715Smrg
1256747b715Smrg    client_request.swapped = TRUE;
126f7df2e56Smrg    swaps(&req->deviceid);
1277e31ba66Smrg    swapl(&req->win);
128f7df2e56Smrg    swaps(&req->length);
1296747b715Smrg    rc = SProcXIQueryPointer(&client_request);
130f7df2e56Smrg    assert(rc == error);
1316747b715Smrg
1326747b715Smrg    if (rc == BadDevice)
133f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1346747b715Smrg}
1356747b715Smrg
136f7df2e56Smrgstatic void
137f7df2e56Smrgtest_XIQueryPointer(void)
1386747b715Smrg{
1396747b715Smrg    int i;
1406747b715Smrg    xXIQueryPointerReq request;
1416747b715Smrg
1426747b715Smrg    memset(&request, 0, sizeof(request));
1436747b715Smrg
1446747b715Smrg    request_init(&request, XIQueryPointer);
1456747b715Smrg
1466747b715Smrg    reply_handler = reply_XIQueryPointer;
1476747b715Smrg
1486747b715Smrg    client_request = init_client(request.length, &request);
1496747b715Smrg
1506747b715Smrg    request.deviceid = XIAllDevices;
1516747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1526747b715Smrg
1536747b715Smrg    request.deviceid = XIAllMasterDevices;
1546747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1556747b715Smrg
1566747b715Smrg    request.win = root.drawable.id;
1576747b715Smrg    test_data.win = &root;
1586747b715Smrg
1596747b715Smrg    test_data.dev = devices.vcp;
1606747b715Smrg    request.deviceid = devices.vcp->id;
1616747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1626747b715Smrg    request.deviceid = devices.vck->id;
1636747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1646747b715Smrg    request.deviceid = devices.mouse->id;
1656747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1666747b715Smrg    request.deviceid = devices.kbd->id;
1676747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1686747b715Smrg
1696747b715Smrg    test_data.dev = devices.mouse;
170f7df2e56Smrg    devices.mouse->master = NULL;       /* Float, kind-of */
1716747b715Smrg    request.deviceid = devices.mouse->id;
1726747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1736747b715Smrg
174f7df2e56Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
1756747b715Smrg        request.deviceid = i;
1766747b715Smrg        request_XIQueryPointer(&client_request, &request, BadDevice);
1776747b715Smrg    }
1786747b715Smrg
1796747b715Smrg    request.win = window.drawable.id;
1806747b715Smrg
1816747b715Smrg    test_data.dev = devices.vcp;
1826747b715Smrg    test_data.win = &window;
1836747b715Smrg    request.deviceid = devices.vcp->id;
1846747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1856747b715Smrg
1866747b715Smrg    test_data.dev = devices.mouse;
1876747b715Smrg    request.deviceid = devices.mouse->id;
1886747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1890b0d8713Smrg
1900b0d8713Smrg    /* test REQUEST_SIZE_MATCH */
1910b0d8713Smrg    client_request.req_len -= 4;
1920b0d8713Smrg    request_XIQueryPointer(&client_request, &request, BadLength);
1936747b715Smrg}
1946747b715Smrg
195f7df2e56Smrgint
1967e31ba66Smrgprotocol_xiquerypointer_test(void)
1976747b715Smrg{
1986747b715Smrg    init_simple();
1996747b715Smrg
200f7df2e56Smrg    test_XIQueryPointer();
2016747b715Smrg
202f7df2e56Smrg    return 0;
2036747b715Smrg}
204