protocol-xiquerypointer.c revision 0b0d8713
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"
406747b715Smrg
416747b715Smrg#include "protocol-common.h"
426747b715Smrg#include <glib.h>
436747b715Smrg
446747b715Smrgstatic ClientRec client_request;
456747b715Smrgstatic void reply_XIQueryPointer_data(ClientPtr client, int len,
466747b715Smrg                                      char *data, void *userdata);
476747b715Smrg
486747b715Smrgstatic struct {
496747b715Smrg    DeviceIntPtr dev;
506747b715Smrg    WindowPtr win;
516747b715Smrg} test_data;
526747b715Smrg
536747b715Smrg
546747b715Smrg/* dixLookupWindow requires a lot of setup not necessary for this test.
556747b715Smrg * Simple wrapper that returns either one of the fake root window or the
566747b715Smrg * fake client window. If the requested ID is neither of those wanted,
576747b715Smrg * return whatever the real dixLookupWindow does.
586747b715Smrg */
596747b715Smrgint __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
606747b715Smrg{
616747b715Smrg    if (id == root.drawable.id)
626747b715Smrg    {
636747b715Smrg        *win = &root;
646747b715Smrg        return Success;
656747b715Smrg    } else if (id == window.drawable.id)
666747b715Smrg    {
676747b715Smrg        *win = &window;
686747b715Smrg        return Success;
696747b715Smrg    }
706747b715Smrg
716747b715Smrg    return __real_dixLookupWindow(win, id, client, access);
726747b715Smrg}
736747b715Smrg
746747b715Smrgstatic void reply_XIQueryPointer(ClientPtr client, int len, char *data,
756747b715Smrg                                 void *userdata)
766747b715Smrg{
776747b715Smrg    xXIQueryPointerReply *rep = (xXIQueryPointerReply*)data;
786747b715Smrg    SpritePtr sprite;
796747b715Smrg
806747b715Smrg    if (!rep->repType)
816747b715Smrg        return;
826747b715Smrg
836747b715Smrg    if (client->swapped)
846747b715Smrg    {
856747b715Smrg        char n;
866747b715Smrg        swapl(&rep->length, n);
876747b715Smrg        swaps(&rep->sequenceNumber, n);
886747b715Smrg        swapl(&rep->root, n);
896747b715Smrg        swapl(&rep->child, n);
906747b715Smrg        swapl(&rep->root_x, n);
916747b715Smrg        swapl(&rep->root_y, n);
926747b715Smrg        swapl(&rep->win_x, n);
936747b715Smrg        swapl(&rep->win_y, n);
946747b715Smrg        swaps(&rep->buttons_len, n);
956747b715Smrg    }
966747b715Smrg
976747b715Smrg    reply_check_defaults(rep, len, XIQueryPointer);
986747b715Smrg
996747b715Smrg    g_assert(rep->root == root.drawable.id);
1006747b715Smrg    g_assert(rep->same_screen == xTrue);
1016747b715Smrg
1026747b715Smrg    sprite = test_data.dev->spriteInfo->sprite;
1036747b715Smrg    g_assert((rep->root_x >> 16) == sprite->hot.x);
1046747b715Smrg    g_assert((rep->root_y >> 16) == sprite->hot.y);
1056747b715Smrg
1066747b715Smrg    if (test_data.win == &root)
1076747b715Smrg    {
1086747b715Smrg        g_assert(rep->root_x == rep->win_x);
1096747b715Smrg        g_assert(rep->root_y == rep->win_y);
1106747b715Smrg        g_assert(rep->child == window.drawable.id);
1116747b715Smrg    } else
1126747b715Smrg    {
1136747b715Smrg        int x, y;
1146747b715Smrg
1156747b715Smrg        x = sprite->hot.x - window.drawable.x;
1166747b715Smrg        y = sprite->hot.y - window.drawable.y;
1176747b715Smrg
1186747b715Smrg        g_assert((rep->win_x >> 16) == x);
1196747b715Smrg        g_assert((rep->win_y >> 16) == y);
1206747b715Smrg        g_assert(rep->child == None);
1216747b715Smrg    }
1226747b715Smrg
1236747b715Smrg
1246747b715Smrg    g_assert(rep->same_screen == xTrue);
1256747b715Smrg
1266747b715Smrg    reply_handler = reply_XIQueryPointer_data;
1276747b715Smrg}
1286747b715Smrg
1296747b715Smrgstatic void reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *userdata)
1306747b715Smrg{
1316747b715Smrg    reply_handler = reply_XIQueryPointer;
1326747b715Smrg}
1336747b715Smrg
1346747b715Smrgstatic void request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq* req, int error)
1356747b715Smrg{
1366747b715Smrg    char n;
1376747b715Smrg    int rc;
1386747b715Smrg
1396747b715Smrg    rc = ProcXIQueryPointer(&client_request);
1406747b715Smrg    g_assert(rc == error);
1416747b715Smrg
1426747b715Smrg    if (rc == BadDevice)
1436747b715Smrg        g_assert(client_request.errorValue == req->deviceid);
1446747b715Smrg
1456747b715Smrg    client_request.swapped = TRUE;
1466747b715Smrg    swaps(&req->deviceid, n);
1476747b715Smrg    swaps(&req->length, n);
1486747b715Smrg    rc = SProcXIQueryPointer(&client_request);
1496747b715Smrg    g_assert(rc == error);
1506747b715Smrg
1516747b715Smrg    if (rc == BadDevice)
1526747b715Smrg        g_assert(client_request.errorValue == req->deviceid);
1536747b715Smrg}
1546747b715Smrg
1556747b715Smrgstatic void test_XIQueryPointer(void)
1566747b715Smrg{
1576747b715Smrg    int i;
1586747b715Smrg    xXIQueryPointerReq request;
1596747b715Smrg
1606747b715Smrg    memset(&request, 0, sizeof(request));
1616747b715Smrg
1626747b715Smrg    request_init(&request, XIQueryPointer);
1636747b715Smrg
1646747b715Smrg    reply_handler = reply_XIQueryPointer;
1656747b715Smrg
1666747b715Smrg    client_request = init_client(request.length, &request);
1676747b715Smrg
1686747b715Smrg    request.deviceid = XIAllDevices;
1696747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1706747b715Smrg
1716747b715Smrg    request.deviceid = XIAllMasterDevices;
1726747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1736747b715Smrg
1746747b715Smrg    request.win = root.drawable.id;
1756747b715Smrg    test_data.win = &root;
1766747b715Smrg
1776747b715Smrg    test_data.dev = devices.vcp;
1786747b715Smrg    request.deviceid = devices.vcp->id;
1796747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1806747b715Smrg    request.deviceid = devices.vck->id;
1816747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1826747b715Smrg    request.deviceid = devices.mouse->id;
1836747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1846747b715Smrg    request.deviceid = devices.kbd->id;
1856747b715Smrg    request_XIQueryPointer(&client_request, &request, BadDevice);
1866747b715Smrg
1876747b715Smrg    test_data.dev = devices.mouse;
1886747b715Smrg    devices.mouse->u.master = NULL; /* Float, kind-of */
1896747b715Smrg    request.deviceid = devices.mouse->id;
1906747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
1916747b715Smrg
1926747b715Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++)
1936747b715Smrg    {
1946747b715Smrg        request.deviceid = i;
1956747b715Smrg        request_XIQueryPointer(&client_request, &request, BadDevice);
1966747b715Smrg    }
1976747b715Smrg
1986747b715Smrg    request.win = window.drawable.id;
1996747b715Smrg
2006747b715Smrg    test_data.dev = devices.vcp;
2016747b715Smrg    test_data.win = &window;
2026747b715Smrg    request.deviceid = devices.vcp->id;
2036747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
2046747b715Smrg
2056747b715Smrg    test_data.dev = devices.mouse;
2066747b715Smrg    request.deviceid = devices.mouse->id;
2076747b715Smrg    request_XIQueryPointer(&client_request, &request, Success);
2080b0d8713Smrg
2090b0d8713Smrg    /* test REQUEST_SIZE_MATCH */
2100b0d8713Smrg    client_request.req_len -= 4;
2110b0d8713Smrg    request_XIQueryPointer(&client_request, &request, BadLength);
2126747b715Smrg}
2136747b715Smrg
2146747b715Smrgint main(int argc, char** argv)
2156747b715Smrg{
2166747b715Smrg    g_test_init(&argc, &argv,NULL);
2176747b715Smrg    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
2186747b715Smrg
2196747b715Smrg    init_simple();
2206747b715Smrg
2216747b715Smrg    g_test_add_func("/xi2/protocol/XIQueryPointer", test_XIQueryPointer);
2226747b715Smrg
2236747b715Smrg    return g_test_run();
2246747b715Smrg}
225