protocol-xiwarppointer.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 XIWarpPointer 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 "xiwarppointer.h"
396747b715Smrg#include "exevents.h"
40f7df2e56Smrg#include "exglobals.h"
416747b715Smrg
426747b715Smrg#include "protocol-common.h"
436747b715Smrg
446747b715Smrgstatic int expected_x = SPRITE_X;
456747b715Smrgstatic int expected_y = SPRITE_Y;
466747b715Smrg
47806e81e9Smrgextern ClientRec client_window;
486747b715Smrg
496747b715Smrg/**
506747b715Smrg * This function overrides the one in the screen rec.
516747b715Smrg */
52f7df2e56Smrgstatic Bool
53f7df2e56SmrgScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr scr,
54f7df2e56Smrg                        int x, int y, Bool generateEvent)
556747b715Smrg{
56f7df2e56Smrg    assert(x == expected_x);
57f7df2e56Smrg    assert(y == expected_y);
586747b715Smrg    return TRUE;
596747b715Smrg}
606747b715Smrg
61f7df2e56Smrgstatic void
62f7df2e56Smrgrequest_XIWarpPointer(ClientPtr client, xXIWarpPointerReq * req, int error)
636747b715Smrg{
646747b715Smrg    int rc;
656747b715Smrg
666747b715Smrg    rc = ProcXIWarpPointer(client);
67f7df2e56Smrg    assert(rc == error);
686747b715Smrg
696747b715Smrg    if (rc == BadDevice)
70f7df2e56Smrg        assert(client->errorValue == req->deviceid);
716747b715Smrg    else if (rc == BadWindow)
72f7df2e56Smrg        assert(client->errorValue == req->dst_win ||
73f7df2e56Smrg               client->errorValue == req->src_win);
746747b715Smrg
756747b715Smrg    client->swapped = TRUE;
766747b715Smrg
77f7df2e56Smrg    swapl(&req->src_win);
78f7df2e56Smrg    swapl(&req->dst_win);
79f7df2e56Smrg    swapl(&req->src_x);
80f7df2e56Smrg    swapl(&req->src_y);
81f7df2e56Smrg    swapl(&req->dst_x);
82f7df2e56Smrg    swapl(&req->dst_y);
83f7df2e56Smrg    swaps(&req->src_width);
84f7df2e56Smrg    swaps(&req->src_height);
85f7df2e56Smrg    swaps(&req->deviceid);
866747b715Smrg
876747b715Smrg    rc = SProcXIWarpPointer(client);
88f7df2e56Smrg    assert(rc == error);
896747b715Smrg
906747b715Smrg    if (rc == BadDevice)
91f7df2e56Smrg        assert(client->errorValue == req->deviceid);
926747b715Smrg    else if (rc == BadWindow)
93f7df2e56Smrg        assert(client->errorValue == req->dst_win ||
94f7df2e56Smrg               client->errorValue == req->src_win);
956747b715Smrg
966747b715Smrg    client->swapped = FALSE;
976747b715Smrg}
986747b715Smrg
99f7df2e56Smrgstatic void
100f7df2e56Smrgtest_XIWarpPointer(void)
1016747b715Smrg{
1026747b715Smrg    int i;
1036747b715Smrg    ClientRec client_request;
1046747b715Smrg    xXIWarpPointerReq request;
1056747b715Smrg
1066747b715Smrg    memset(&request, 0, sizeof(request));
1076747b715Smrg
1086747b715Smrg    request_init(&request, XIWarpPointer);
1096747b715Smrg
1106747b715Smrg    client_request = init_client(request.length, &request);
1116747b715Smrg
1126747b715Smrg    request.deviceid = XIAllDevices;
1136747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1146747b715Smrg
1156747b715Smrg    request.deviceid = XIAllMasterDevices;
1166747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1176747b715Smrg
1186747b715Smrg    request.src_win = root.drawable.id;
1196747b715Smrg    request.dst_win = root.drawable.id;
1206747b715Smrg    request.deviceid = devices.vcp->id;
1216747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1226747b715Smrg    request.deviceid = devices.vck->id;
1236747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1246747b715Smrg    request.deviceid = devices.mouse->id;
1256747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1266747b715Smrg    request.deviceid = devices.kbd->id;
1276747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1286747b715Smrg
129f7df2e56Smrg    devices.mouse->master = NULL;       /* Float, kind-of */
1306747b715Smrg    request.deviceid = devices.mouse->id;
1316747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1326747b715Smrg
133f7df2e56Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
1346747b715Smrg        request.deviceid = i;
1356747b715Smrg        request_XIWarpPointer(&client_request, &request, BadDevice);
1366747b715Smrg    }
1376747b715Smrg
1386747b715Smrg    request.src_win = window.drawable.id;
1396747b715Smrg    request.deviceid = devices.vcp->id;
1406747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1416747b715Smrg
1426747b715Smrg    request.deviceid = devices.mouse->id;
1436747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1446747b715Smrg
1456747b715Smrg    request.src_win = root.drawable.id;
146f7df2e56Smrg    request.dst_win = 0xFFFF;   /* invalid window */
1476747b715Smrg    request_XIWarpPointer(&client_request, &request, BadWindow);
1486747b715Smrg
149f7df2e56Smrg    request.src_win = 0xFFFF;   /* invalid window */
1506747b715Smrg    request.dst_win = root.drawable.id;
1516747b715Smrg    request_XIWarpPointer(&client_request, &request, BadWindow);
1526747b715Smrg
1536747b715Smrg    request.src_win = None;
1546747b715Smrg    request.dst_win = None;
1556747b715Smrg
1566747b715Smrg    request.dst_y = 0;
1576747b715Smrg    expected_y = SPRITE_Y;
1586747b715Smrg
1596747b715Smrg    request.dst_x = 1 << 16;
1606747b715Smrg    expected_x = SPRITE_X + 1;
1616747b715Smrg    request.deviceid = devices.vcp->id;
1626747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1636747b715Smrg
1646747b715Smrg    request.dst_x = -1 << 16;
1656747b715Smrg    expected_x = SPRITE_X - 1;
1666747b715Smrg    request.deviceid = devices.vcp->id;
1676747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1686747b715Smrg
1696747b715Smrg    request.dst_x = 0;
1706747b715Smrg    expected_x = SPRITE_X;
1716747b715Smrg
1726747b715Smrg    request.dst_y = 1 << 16;
1736747b715Smrg    expected_y = SPRITE_Y + 1;
1746747b715Smrg    request.deviceid = devices.vcp->id;
1756747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1766747b715Smrg
1776747b715Smrg    request.dst_y = -1 << 16;
1786747b715Smrg    expected_y = SPRITE_Y - 1;
1796747b715Smrg    request.deviceid = devices.vcp->id;
1806747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1816747b715Smrg
1826747b715Smrg    /* FIXME: src_x/y checks */
1830b0d8713Smrg
1840b0d8713Smrg    client_request.req_len -= 2; /* invalid length */
1850b0d8713Smrg    request_XIWarpPointer(&client_request, &request, BadLength);
1866747b715Smrg}
1876747b715Smrg
188f7df2e56Smrgint
1897e31ba66Smrgprotocol_xiwarppointer_test(void)
1906747b715Smrg{
1916747b715Smrg    init_simple();
1926747b715Smrg    screen.SetCursorPosition = ScreenSetCursorPosition;
1936747b715Smrg
194f7df2e56Smrg    test_XIWarpPointer();
1956747b715Smrg
196f7df2e56Smrg    return 0;
1976747b715Smrg}
198