"Fossies" - the Fresh Open Source Software Archive

Member "xorg-server-1.20.8/test/xi2/protocol-xigetclientpointer.c" (29 Mar 2020, 4408 Bytes) of package /linux/misc/xorg-server-1.20.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "protocol-xigetclientpointer.c": 1.20.7_vs_1.20.8.

    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 #ifdef HAVE_DIX_CONFIG_H
   25 #include <dix-config.h>
   26 #endif
   27 
   28 /*
   29  * Protocol testing for XIGetClientPointer request.
   30  */
   31 #include <stdint.h>
   32 #include <X11/X.h>
   33 #include <X11/Xproto.h>
   34 #include <X11/extensions/XI2proto.h>
   35 #include "inputstr.h"
   36 #include "windowstr.h"
   37 #include "scrnintstr.h"
   38 #include "xigetclientpointer.h"
   39 #include "exevents.h"
   40 
   41 #include "protocol-common.h"
   42 
   43 static struct {
   44     int cp_is_set;
   45     DeviceIntPtr dev;
   46     int win;
   47 } test_data;
   48 
   49 extern ClientRec client_window;
   50 static ClientRec client_request;
   51 
   52 static void
   53 reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata)
   54 {
   55     xXIGetClientPointerReply *rep = (xXIGetClientPointerReply *) data;
   56 
   57     if (client->swapped) {
   58         swapl(&rep->length);
   59         swaps(&rep->sequenceNumber);
   60         swaps(&rep->deviceid);
   61     }
   62 
   63     reply_check_defaults(rep, len, XIGetClientPointer);
   64 
   65     assert(rep->set == test_data.cp_is_set);
   66     if (rep->set)
   67         assert(rep->deviceid == test_data.dev->id);
   68 }
   69 
   70 static void
   71 request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq * req,
   72                            int error)
   73 {
   74     int rc;
   75 
   76     test_data.win = req->win;
   77 
   78     rc = ProcXIGetClientPointer(&client_request);
   79     assert(rc == error);
   80 
   81     if (rc == BadWindow)
   82         assert(client_request.errorValue == req->win);
   83 
   84     client_request.swapped = TRUE;
   85     swapl(&req->win);
   86     swaps(&req->length);
   87     rc = SProcXIGetClientPointer(&client_request);
   88     assert(rc == error);
   89 
   90     if (rc == BadWindow)
   91         assert(client_request.errorValue == req->win);
   92 
   93 }
   94 
   95 static void
   96 test_XIGetClientPointer(void)
   97 {
   98     xXIGetClientPointerReq request;
   99 
  100     request_init(&request, XIGetClientPointer);
  101 
  102     request.win = CLIENT_WINDOW_ID;
  103 
  104     reply_handler = reply_XIGetClientPointer;
  105 
  106     client_request = init_client(request.length, &request);
  107 
  108     printf("Testing invalid window\n");
  109     request.win = INVALID_WINDOW_ID;
  110     request_XIGetClientPointer(&client_request, &request, BadWindow);
  111 
  112     printf("Testing invalid length\n");
  113     client_request.req_len -= 4;
  114     request_XIGetClientPointer(&client_request, &request, BadLength);
  115     client_request.req_len += 4;
  116 
  117     test_data.cp_is_set = FALSE;
  118 
  119     printf("Testing window None, unset ClientPointer.\n");
  120     request.win = None;
  121     request_XIGetClientPointer(&client_request, &request, Success);
  122 
  123     printf("Testing valid window, unset ClientPointer.\n");
  124     request.win = CLIENT_WINDOW_ID;
  125     request_XIGetClientPointer(&client_request, &request, Success);
  126 
  127     printf("Testing valid window, set ClientPointer.\n");
  128     client_window.clientPtr = devices.vcp;
  129     test_data.dev = devices.vcp;
  130     test_data.cp_is_set = TRUE;
  131     request.win = CLIENT_WINDOW_ID;
  132     request_XIGetClientPointer(&client_request, &request, Success);
  133 
  134     client_window.clientPtr = NULL;
  135 
  136     printf("Testing window None, set ClientPointer.\n");
  137     client_request.clientPtr = devices.vcp;
  138     test_data.dev = devices.vcp;
  139     test_data.cp_is_set = TRUE;
  140     request.win = None;
  141     request_XIGetClientPointer(&client_request, &request, Success);
  142 }
  143 
  144 int
  145 protocol_xigetclientpointer_test(void)
  146 {
  147     init_simple();
  148     client_window = init_client(0, NULL);
  149 
  150     test_XIGetClientPointer();
  151 
  152     return 0;
  153 }