xref: /OK3568_Linux_fs/external/xserver/test/xi2/protocol-common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun  * Copyright © 2009 Red Hat, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  *  copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  *  to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  *  and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  *  Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun  *  paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun  *  Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*4882a593Smuzhiyun  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun  *  DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
25*4882a593Smuzhiyun #include <dix-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include "scrnintstr.h"
29*4882a593Smuzhiyun #include "windowstr.h"
30*4882a593Smuzhiyun #include "exevents.h"
31*4882a593Smuzhiyun #include <assert.h>
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #include "tests.h"
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #ifndef PROTOCOL_COMMON_H
36*4882a593Smuzhiyun #define PROTOCOL_COMMON_H
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /* Check default values in a reply */
39*4882a593Smuzhiyun #define reply_check_defaults(rep, len, type) \
40*4882a593Smuzhiyun     { \
41*4882a593Smuzhiyun         assert((len) >= sz_x##type##Reply); \
42*4882a593Smuzhiyun         assert((rep)->repType == X_Reply); \
43*4882a593Smuzhiyun         assert((rep)->RepType == X_##type); \
44*4882a593Smuzhiyun         assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
45*4882a593Smuzhiyun         assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
46*4882a593Smuzhiyun     }
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* initialise default values for request */
49*4882a593Smuzhiyun #define request_init(req, type) \
50*4882a593Smuzhiyun     { \
51*4882a593Smuzhiyun         (req)->reqType = 128; /* doesn't matter */ \
52*4882a593Smuzhiyun         (req)->ReqType = X_##type; \
53*4882a593Smuzhiyun         (req)->length = (sz_x##type##Req >> 2); \
54*4882a593Smuzhiyun     }
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* Various defines used in the tests. Some tests may use different values
57*4882a593Smuzhiyun  * than these defaults */
58*4882a593Smuzhiyun /* default client index */
59*4882a593Smuzhiyun #define CLIENT_INDEX            1
60*4882a593Smuzhiyun /* default client mask for resources and windows */
61*4882a593Smuzhiyun #define CLIENT_MASK             ((CLIENT_INDEX) << CLIENTOFFSET)
62*4882a593Smuzhiyun /* default client sequence number for replies */
63*4882a593Smuzhiyun #define CLIENT_SEQUENCE         0x100
64*4882a593Smuzhiyun /* default root window id */
65*4882a593Smuzhiyun #define ROOT_WINDOW_ID          0x10
66*4882a593Smuzhiyun /* default client window id */
67*4882a593Smuzhiyun #define CLIENT_WINDOW_ID        0x100001
68*4882a593Smuzhiyun /* invalid window ID. use for BadWindow checks. */
69*4882a593Smuzhiyun #define INVALID_WINDOW_ID       0x111111
70*4882a593Smuzhiyun /* initial fake sprite position */
71*4882a593Smuzhiyun #define SPRITE_X                100
72*4882a593Smuzhiyun #define SPRITE_Y                200
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* Various structs used throughout the tests */
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /* The default devices struct, contains one pointer + keyboard and the
77*4882a593Smuzhiyun  * matching master devices. Initialize with init_devices() if needed. */
78*4882a593Smuzhiyun struct devices {
79*4882a593Smuzhiyun     DeviceIntPtr vcp;
80*4882a593Smuzhiyun     DeviceIntPtr vck;
81*4882a593Smuzhiyun     DeviceIntPtr mouse;
82*4882a593Smuzhiyun     DeviceIntPtr kbd;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun     int num_devices;
85*4882a593Smuzhiyun     int num_master_devices;
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /**
89*4882a593Smuzhiyun  * The set of default devices available in all tests if necessary.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun extern struct devices devices;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun  * test-specific userdata, passed into the reply handler.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun extern void *global_userdata;
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /**
99*4882a593Smuzhiyun  * The reply handler called from WriteToClient. Set this handler if you need
100*4882a593Smuzhiyun  * to check the reply values.
101*4882a593Smuzhiyun  */
102*4882a593Smuzhiyun extern void (*reply_handler) (ClientPtr client, int len, char *data, void *userdata);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /**
105*4882a593Smuzhiyun  * The default screen used for the windows. Initialized by init_simple().
106*4882a593Smuzhiyun  */
107*4882a593Smuzhiyun extern ScreenRec screen;
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /**
110*4882a593Smuzhiyun  * Semi-initialized root window. initialized by init().
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun extern WindowRec root;
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun /**
115*4882a593Smuzhiyun  * Semi-initialized top-level window. initialized by init().
116*4882a593Smuzhiyun  */
117*4882a593Smuzhiyun extern WindowRec window;
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /* various simple functions for quick setup */
120*4882a593Smuzhiyun /**
121*4882a593Smuzhiyun  * Initialize the above struct with default devices and return the struct.
122*4882a593Smuzhiyun  * Usually not needed if you call ::init_simple.
123*4882a593Smuzhiyun  */
124*4882a593Smuzhiyun struct devices init_devices(void);
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun /**
127*4882a593Smuzhiyun  * Init a mostly zeroed out client with default values for index and mask.
128*4882a593Smuzhiyun  */
129*4882a593Smuzhiyun ClientRec init_client(int request_len, void *request_data);
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /**
132*4882a593Smuzhiyun  * Init a mostly zeroed out window with the given window ID.
133*4882a593Smuzhiyun  * Usually not needed if you call ::init_simple which sets up root and
134*4882a593Smuzhiyun  * window.
135*4882a593Smuzhiyun  */
136*4882a593Smuzhiyun void init_window(WindowPtr window, WindowPtr parent, int id);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun  * Create a very simple setup that provides the minimum values for most
140*4882a593Smuzhiyun  * tests, including a screen, the root and client window and the default
141*4882a593Smuzhiyun  * device setup.
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun void init_simple(void);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun /* Declarations for various overrides in the test files. */
146*4882a593Smuzhiyun void __wrap_WriteToClient(ClientPtr client, int len, void *data);
147*4882a593Smuzhiyun int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
148*4882a593Smuzhiyun                           int len, unsigned char *mask);
149*4882a593Smuzhiyun int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client,
150*4882a593Smuzhiyun                            Mask access);
151*4882a593Smuzhiyun int __real_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client,
152*4882a593Smuzhiyun                            Mask access);
153*4882a593Smuzhiyun Bool __wrap_AddResource(XID id, RESTYPE type, void *value);
154*4882a593Smuzhiyun int __wrap_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
155*4882a593Smuzhiyun int __real_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun #endif                          /* PROTOCOL_COMMON_H */
158