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 XIWarpPointer 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 "xiwarppointer.h"
426747b715Smrg#include "exevents.h"
43f7df2e56Smrg#include "exglobals.h"
446747b715Smrg
456747b715Smrg#include "protocol-common.h"
466747b715Smrg
476747b715Smrgstatic int expected_x = SPRITE_X;
486747b715Smrgstatic int expected_y = SPRITE_Y;
496747b715Smrg
50806e81e9Smrgextern ClientRec client_window;
516747b715Smrg
526747b715Smrg/**
536747b715Smrg * This function overrides the one in the screen rec.
546747b715Smrg */
55f7df2e56Smrgstatic Bool
56f7df2e56SmrgScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr scr,
57f7df2e56Smrg                        int x, int y, Bool generateEvent)
586747b715Smrg{
59f7df2e56Smrg    assert(x == expected_x);
60f7df2e56Smrg    assert(y == expected_y);
616747b715Smrg    return TRUE;
626747b715Smrg}
636747b715Smrg
64f7df2e56Smrgstatic void
65f7df2e56Smrgrequest_XIWarpPointer(ClientPtr client, xXIWarpPointerReq * req, int error)
666747b715Smrg{
676747b715Smrg    int rc;
686747b715Smrg
696747b715Smrg    rc = ProcXIWarpPointer(client);
70f7df2e56Smrg    assert(rc == error);
716747b715Smrg
726747b715Smrg    if (rc == BadDevice)
73f7df2e56Smrg        assert(client->errorValue == req->deviceid);
746747b715Smrg    else if (rc == BadWindow)
75f7df2e56Smrg        assert(client->errorValue == req->dst_win ||
76f7df2e56Smrg               client->errorValue == req->src_win);
776747b715Smrg
786747b715Smrg    client->swapped = TRUE;
796747b715Smrg
80f7df2e56Smrg    swapl(&req->src_win);
81f7df2e56Smrg    swapl(&req->dst_win);
82f7df2e56Smrg    swapl(&req->src_x);
83f7df2e56Smrg    swapl(&req->src_y);
84f7df2e56Smrg    swapl(&req->dst_x);
85f7df2e56Smrg    swapl(&req->dst_y);
86f7df2e56Smrg    swaps(&req->src_width);
87f7df2e56Smrg    swaps(&req->src_height);
88f7df2e56Smrg    swaps(&req->deviceid);
896747b715Smrg
906747b715Smrg    rc = SProcXIWarpPointer(client);
91f7df2e56Smrg    assert(rc == error);
926747b715Smrg
936747b715Smrg    if (rc == BadDevice)
94f7df2e56Smrg        assert(client->errorValue == req->deviceid);
956747b715Smrg    else if (rc == BadWindow)
96f7df2e56Smrg        assert(client->errorValue == req->dst_win ||
97f7df2e56Smrg               client->errorValue == req->src_win);
986747b715Smrg
996747b715Smrg    client->swapped = FALSE;
1006747b715Smrg}
1016747b715Smrg
102f7df2e56Smrgstatic void
103f7df2e56Smrgtest_XIWarpPointer(void)
1046747b715Smrg{
1056747b715Smrg    int i;
1066747b715Smrg    ClientRec client_request;
1076747b715Smrg    xXIWarpPointerReq request;
1086747b715Smrg
1096747b715Smrg    memset(&request, 0, sizeof(request));
1106747b715Smrg
1116747b715Smrg    request_init(&request, XIWarpPointer);
1126747b715Smrg
1136747b715Smrg    client_request = init_client(request.length, &request);
1146747b715Smrg
1156747b715Smrg    request.deviceid = XIAllDevices;
1166747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1176747b715Smrg
1186747b715Smrg    request.deviceid = XIAllMasterDevices;
1196747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1206747b715Smrg
1216747b715Smrg    request.src_win = root.drawable.id;
1226747b715Smrg    request.dst_win = root.drawable.id;
1236747b715Smrg    request.deviceid = devices.vcp->id;
1246747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1256747b715Smrg    request.deviceid = devices.vck->id;
1266747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1276747b715Smrg    request.deviceid = devices.mouse->id;
1286747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1296747b715Smrg    request.deviceid = devices.kbd->id;
1306747b715Smrg    request_XIWarpPointer(&client_request, &request, BadDevice);
1316747b715Smrg
132f7df2e56Smrg    devices.mouse->master = NULL;       /* Float, kind-of */
1336747b715Smrg    request.deviceid = devices.mouse->id;
1346747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1356747b715Smrg
136f7df2e56Smrg    for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
1376747b715Smrg        request.deviceid = i;
1386747b715Smrg        request_XIWarpPointer(&client_request, &request, BadDevice);
1396747b715Smrg    }
1406747b715Smrg
1416747b715Smrg    request.src_win = window.drawable.id;
1426747b715Smrg    request.deviceid = devices.vcp->id;
1436747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1446747b715Smrg
1456747b715Smrg    request.deviceid = devices.mouse->id;
1466747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1476747b715Smrg
1486747b715Smrg    request.src_win = root.drawable.id;
149f7df2e56Smrg    request.dst_win = 0xFFFF;   /* invalid window */
1506747b715Smrg    request_XIWarpPointer(&client_request, &request, BadWindow);
1516747b715Smrg
152f7df2e56Smrg    request.src_win = 0xFFFF;   /* invalid window */
1536747b715Smrg    request.dst_win = root.drawable.id;
1546747b715Smrg    request_XIWarpPointer(&client_request, &request, BadWindow);
1556747b715Smrg
1566747b715Smrg    request.src_win = None;
1576747b715Smrg    request.dst_win = None;
1586747b715Smrg
1596747b715Smrg    request.dst_y = 0;
1606747b715Smrg    expected_y = SPRITE_Y;
1616747b715Smrg
1626747b715Smrg    request.dst_x = 1 << 16;
1636747b715Smrg    expected_x = SPRITE_X + 1;
1646747b715Smrg    request.deviceid = devices.vcp->id;
1656747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1666747b715Smrg
1676747b715Smrg    request.dst_x = -1 << 16;
1686747b715Smrg    expected_x = SPRITE_X - 1;
1696747b715Smrg    request.deviceid = devices.vcp->id;
1706747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1716747b715Smrg
1726747b715Smrg    request.dst_x = 0;
1736747b715Smrg    expected_x = SPRITE_X;
1746747b715Smrg
1756747b715Smrg    request.dst_y = 1 << 16;
1766747b715Smrg    expected_y = SPRITE_Y + 1;
1776747b715Smrg    request.deviceid = devices.vcp->id;
1786747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1796747b715Smrg
1806747b715Smrg    request.dst_y = -1 << 16;
1816747b715Smrg    expected_y = SPRITE_Y - 1;
1826747b715Smrg    request.deviceid = devices.vcp->id;
1836747b715Smrg    request_XIWarpPointer(&client_request, &request, Success);
1846747b715Smrg
1856747b715Smrg    /* FIXME: src_x/y checks */
1860b0d8713Smrg
1870b0d8713Smrg    client_request.req_len -= 2; /* invalid length */
1880b0d8713Smrg    request_XIWarpPointer(&client_request, &request, BadLength);
1896747b715Smrg}
1906747b715Smrg
191f7df2e56Smrgint
1927e31ba66Smrgprotocol_xiwarppointer_test(void)
1936747b715Smrg{
1946747b715Smrg    init_simple();
1956747b715Smrg    screen.SetCursorPosition = ScreenSetCursorPosition;
1966747b715Smrg
197f7df2e56Smrg    test_XIWarpPointer();
1986747b715Smrg
199f7df2e56Smrg    return 0;
2006747b715Smrg}
201