xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

protocol-xigetclientpointer.c (4453B)


      1 /**
      2  * Copyright © 2009 Red Hat, Inc.
      3  *
      4  *  Permission is hereby granted, free of charge, to any person obtaining a
      5  *  copy of this software and associated documentation files (the "Software"),
      6  *  to deal in the Software without restriction, including without limitation
      7  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  *  and/or sell copies of the Software, and to permit persons to whom the
      9  *  Software is furnished to do so, subject to the following conditions:
     10  *
     11  *  The above copyright notice and this permission notice (including the next
     12  *  paragraph) shall be included in all copies or substantial portions of the
     13  *  Software.
     14  *
     15  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21  *  DEALINGS IN THE SOFTWARE.
     22  */
     23 
     24 /* Test relies on assert() */
     25 #undef NDEBUG
     26 
     27 #ifdef HAVE_DIX_CONFIG_H
     28 #include <dix-config.h>
     29 #endif
     30 
     31 /*
     32  * Protocol testing for XIGetClientPointer request.
     33  */
     34 #include <stdint.h>
     35 #include <X11/X.h>
     36 #include <X11/Xproto.h>
     37 #include <X11/extensions/XI2proto.h>
     38 #include "inputstr.h"
     39 #include "windowstr.h"
     40 #include "scrnintstr.h"
     41 #include "xigetclientpointer.h"
     42 #include "exevents.h"
     43 
     44 #include "protocol-common.h"
     45 
     46 static struct {
     47     int cp_is_set;
     48     DeviceIntPtr dev;
     49     int win;
     50 } test_data;
     51 
     52 extern ClientRec client_window;
     53 static ClientRec client_request;
     54 
     55 static void
     56 reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata)
     57 {
     58     xXIGetClientPointerReply *rep = (xXIGetClientPointerReply *) data;
     59 
     60     if (client->swapped) {
     61         swapl(&rep->length);
     62         swaps(&rep->sequenceNumber);
     63         swaps(&rep->deviceid);
     64     }
     65 
     66     reply_check_defaults(rep, len, XIGetClientPointer);
     67 
     68     assert(rep->set == test_data.cp_is_set);
     69     if (rep->set)
     70         assert(rep->deviceid == test_data.dev->id);
     71 }
     72 
     73 static void
     74 request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq * req,
     75                            int error)
     76 {
     77     int rc;
     78 
     79     test_data.win = req->win;
     80 
     81     rc = ProcXIGetClientPointer(&client_request);
     82     assert(rc == error);
     83 
     84     if (rc == BadWindow)
     85         assert(client_request.errorValue == req->win);
     86 
     87     client_request.swapped = TRUE;
     88     swapl(&req->win);
     89     swaps(&req->length);
     90     rc = SProcXIGetClientPointer(&client_request);
     91     assert(rc == error);
     92 
     93     if (rc == BadWindow)
     94         assert(client_request.errorValue == req->win);
     95 
     96 }
     97 
     98 static void
     99 test_XIGetClientPointer(void)
    100 {
    101     xXIGetClientPointerReq request;
    102 
    103     request_init(&request, XIGetClientPointer);
    104 
    105     request.win = CLIENT_WINDOW_ID;
    106 
    107     reply_handler = reply_XIGetClientPointer;
    108 
    109     client_request = init_client(request.length, &request);
    110 
    111     printf("Testing invalid window\n");
    112     request.win = INVALID_WINDOW_ID;
    113     request_XIGetClientPointer(&client_request, &request, BadWindow);
    114 
    115     printf("Testing invalid length\n");
    116     client_request.req_len -= 4;
    117     request_XIGetClientPointer(&client_request, &request, BadLength);
    118     client_request.req_len += 4;
    119 
    120     test_data.cp_is_set = FALSE;
    121 
    122     printf("Testing window None, unset ClientPointer.\n");
    123     request.win = None;
    124     request_XIGetClientPointer(&client_request, &request, Success);
    125 
    126     printf("Testing valid window, unset ClientPointer.\n");
    127     request.win = CLIENT_WINDOW_ID;
    128     request_XIGetClientPointer(&client_request, &request, Success);
    129 
    130     printf("Testing valid window, set ClientPointer.\n");
    131     client_window.clientPtr = devices.vcp;
    132     test_data.dev = devices.vcp;
    133     test_data.cp_is_set = TRUE;
    134     request.win = CLIENT_WINDOW_ID;
    135     request_XIGetClientPointer(&client_request, &request, Success);
    136 
    137     client_window.clientPtr = NULL;
    138 
    139     printf("Testing window None, set ClientPointer.\n");
    140     client_request.clientPtr = devices.vcp;
    141     test_data.dev = devices.vcp;
    142     test_data.cp_is_set = TRUE;
    143     request.win = None;
    144     request_XIGetClientPointer(&client_request, &request, Success);
    145 }
    146 
    147 int
    148 protocol_xigetclientpointer_test(void)
    149 {
    150     init_simple();
    151     client_window = init_client(0, NULL);
    152 
    153     test_XIGetClientPointer();
    154 
    155     return 0;
    156 }