protocol-xiquerypointer.c revision 806e81e9
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
44806e81e9Smrgextern ClientRec client_window;
456747b715Smrgstatic ClientRec client_request;
466747b715Smrgstatic void reply_XIQueryPointer_data(ClientPtr client, int len,
47f7df2e56Smrg                                      char *data, void *closure);
486747b715Smrg
496747b715Smrgstatic struct {
506747b715Smrg    DeviceIntPtr dev;
516747b715Smrg    WindowPtr win;
526747b715Smrg} test_data;
536747b715Smrg
54f7df2e56Smrgstatic void
55f7df2e56Smrgreply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
566747b715Smrg{
57f7df2e56Smrg    xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
586747b715Smrg    SpritePtr sprite;
596747b715Smrg
606747b715Smrg    if (!rep->repType)
616747b715Smrg        return;
626747b715Smrg
63f7df2e56Smrg    if (client->swapped) {
64f7df2e56Smrg        swapl(&rep->length);
65f7df2e56Smrg        swaps(&rep->sequenceNumber);
66f7df2e56Smrg        swapl(&rep->root);
67f7df2e56Smrg        swapl(&rep->child);
68f7df2e56Smrg        swapl(&rep->root_x);
69f7df2e56Smrg        swapl(&rep->root_y);
70f7df2e56Smrg        swapl(&rep->win_x);
71f7df2e56Smrg        swapl(&rep->win_y);
72f7df2e56Smrg        swaps(&rep->buttons_len);
736747b715Smrg    }
746747b715Smrg
756747b715Smrg    reply_check_defaults(rep, len, XIQueryPointer);
766747b715Smrg
77f7df2e56Smrg    assert(rep->root == root.drawable.id);
78f7df2e56Smrg    assert(rep->same_screen == xTrue);
796747b715Smrg
806747b715Smrg    sprite = test_data.dev->spriteInfo->sprite;
81f7df2e56Smrg    assert((rep->root_x >> 16) == sprite->hot.x);
82f7df2e56Smrg    assert((rep->root_y >> 16) == sprite->hot.y);
83f7df2e56Smrg
84f7df2e56Smrg    if (test_data.win == &root) {
85f7df2e56Smrg        assert(rep->root_x == rep->win_x);
86f7df2e56Smrg        assert(rep->root_y == rep->win_y);
87f7df2e56Smrg        assert(rep->child == window.drawable.id);
88f7df2e56Smrg    }
89f7df2e56Smrg    else {
906747b715Smrg        int x, y;
916747b715Smrg
926747b715Smrg        x = sprite->hot.x - window.drawable.x;
936747b715Smrg        y = sprite->hot.y - window.drawable.y;
946747b715Smrg
95f7df2e56Smrg        assert((rep->win_x >> 16) == x);
96f7df2e56Smrg        assert((rep->win_y >> 16) == y);
97f7df2e56Smrg        assert(rep->child == None);
986747b715Smrg    }
996747b715Smrg
100f7df2e56Smrg    assert(rep->same_screen == xTrue);
1016747b715Smrg
1026747b715Smrg    reply_handler = reply_XIQueryPointer_data;
1036747b715Smrg}
1046747b715Smrg
105f7df2e56Smrgstatic void
106f7df2e56Smrgreply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
1076747b715Smrg{
1086747b715Smrg    reply_handler = reply_XIQueryPointer;
1096747b715Smrg}
1106747b715Smrg
111f7df2e56Smrgstatic void
112f7df2e56Smrgrequest_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
1136747b715Smrg{
1146747b715Smrg    int rc;
1156747b715Smrg
1166747b715Smrg    rc = ProcXIQueryPointer(&client_request);
117f7df2e56Smrg    assert(rc == error);
1186747b715Smrg
1196747b715Smrg    if (rc == BadDevice)
120f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1216747b715Smrg
1226747b715Smrg    client_request.swapped = TRUE;
123f7df2e56Smrg    swaps(&req->deviceid);
1247e31ba66Smrg    swapl(&req->win);
125f7df2e56Smrg    swaps(&req->length);
1266747b715Smrg    rc = SProcXIQueryPointer(&client_request);
127f7df2e56Smrg    assert(rc == error);
1286747b715Smrg
1296747b715Smrg    if (rc == BadDevice)
130f7df2e56Smrg        assert(client_request.errorValue == req->deviceid);
1316747b715Smrg}
1326747b715Smrg
133f7df2e56Smrgstatic void
134f7df2e56Smrgtest_XIQueryPointer(void)
1356747b715Smrg{
1366747b715Smrg    int i;
1376747b715Smrg    xXIQueryPointerReq request;
1386747b715Smrg
1396747b715Smrg    memset(&request, 0, sizeof(request));
1406747b715Smrg
1416747b715Smrg    request_init(&request, XIQueryPointer);
1426747b715Smrg
1436747b715Smrg    reply_handler = reply_XIQueryPointer;
1446747b715Smrg
1456747b715Smrg    client_request = init_client(request.length, &request);
1466747b715Smrg
1476747b715Smrg    request.deviceid = XIAllDevices;
1486747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1496747b715Smrg
1506747b715Smrg    request.deviceid = XIAllMasterDevices;
1516747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1526747b715Smrg
1536747b715Smrg    request.win = root.drawable.id;
1546747b715Smrg    test_data.win = &root;
1556747b715Smrg
1566747b715Smrg    test_data.dev = devices.vcp;
1576747b715Smrg    request.deviceid = devices.vcp->id;
1586747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1596747b715Smrg    request.deviceid = devices.vck->id;
1606747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1616747b715Smrg    request.deviceid = devices.mouse->id;
1626747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1636747b715Smrg    request.deviceid = devices.kbd->id;
1646747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1656747b715Smrg
1666747b715Smrg    test_data.dev = devices.mouse;
167f7df2e56Smrg    devices.mouse->master = NULL;       /* Float, kind-of */
1686747b715Smrg    request.deviceid = devices.mouse->id;
1696747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1706747b715Smrg
171f7df2e56Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
1726747b715Smrg        request.deviceid = i;
1736747b715Smrg        request_XIQueryPointer(&client_request, &request, BadDevice);
1746747b715Smrg    }
1756747b715Smrg
1766747b715Smrg    request.win = window.drawable.id;
1776747b715Smrg
1786747b715Smrg    test_data.dev = devices.vcp;
1796747b715Smrg    test_data.win = &window;
1806747b715Smrg    request.deviceid = devices.vcp->id;
1816747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1826747b715Smrg
1836747b715Smrg    test_data.dev = devices.mouse;
1846747b715Smrg    request.deviceid = devices.mouse->id;
1856747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1860b0d8713Smrg
1870b0d8713Smrg    /* test REQUEST_SIZE_MATCH */
1880b0d8713Smrg    client_request.req_len -= 4;
1890b0d8713Smrg    request_XIQueryPointer(&client_request, &request, BadLength);
1906747b715Smrg}
1916747b715Smrg
192f7df2e56Smrgint
1937e31ba66Smrgprotocol_xiquerypointer_test(void)
1946747b715Smrg{
1956747b715Smrg    init_simple();
1966747b715Smrg
197f7df2e56Smrg    test_XIQueryPointer();
1986747b715Smrg
199f7df2e56Smrg    return 0;
2006747b715Smrg}
201