Debian Codegraph @

test/xi2/protocol-common.h

raw
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 #include "scrnintstr.h"
29 #include "windowstr.h"
30 #include "exevents.h"
31 #include <assert.h>
32
33 #include "tests.h"
34
35 #ifndef PROTOCOL_COMMON_H
36 #define PROTOCOL_COMMON_H
37
38 /* Check default values in a reply */
39 #define reply_check_defaults(rep, len, type) \
40 { \
41 assert((len) >= sz_x##type##Reply); \
42 assert((rep)->repType == X_Reply); \
43 assert((rep)->RepType == X_##type); \
44 assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
45 assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
46 }
47
48 /* initialise default values for request */
49 #define request_init(req, type) \
50 { \
51 (req)->reqType = 128; /* doesn't matter */ \
52 (req)->ReqType = X_##type; \
53 (req)->length = (sz_x##type##Req >> 2); \
54 }
55
56 /* Various defines used in the tests. Some tests may use different values
57 * than these defaults */
58 /* default client index */
59 #define CLIENT_INDEX 1
60 /* default client mask for resources and windows */
61 #define CLIENT_MASK ((CLIENT_INDEX) << CLIENTOFFSET)
62 /* default client sequence number for replies */
63 #define CLIENT_SEQUENCE 0x100
64 /* default root window id */
65 #define ROOT_WINDOW_ID 0x10
66 /* default client window id */
67 #define CLIENT_WINDOW_ID 0x100001
68 /* invalid window ID. use for BadWindow checks. */
69 #define INVALID_WINDOW_ID 0x111111
70 /* initial fake sprite position */
71 #define SPRITE_X 100
72 #define SPRITE_Y 200
73
74 /* Various structs used throughout the tests */
75
76 /* The default devices struct, contains one pointer + keyboard and the
77 * matching master devices. Initialize with init_devices() if needed. */
78 struct devices {
79 DeviceIntPtr vcp;
80 DeviceIntPtr vck;
81 DeviceIntPtr mouse;
82 DeviceIntPtr kbd;
83
84 int num_devices;
85 int num_master_devices;
86 };
87
88 /**
89 * The set of default devices available in all tests if necessary.
90 */
91 extern struct devices devices;
92
93 /**
94 * The default screen used for the windows. Initialized by init_simple().
95 */
96 extern ScreenRec screen;
97
98 /**
99 * Semi-initialized root window. initialized by init().
100 */
101 extern WindowRec root;
102
103 /**
104 * Semi-initialized top-level window. initialized by init().
105 */
106 extern WindowRec window;
107
108 /* various simple functions for quick setup */
109 /**
110 * Initialize the above struct with default devices and return the struct.
111 * Usually not needed if you call ::init_simple.
112 */
113 struct devices init_devices(void);
114
115 /**
116 * Init a mostly zeroed out client with default values for index and mask.
117 */
118 ClientRec init_client(int request_len, void *request_data);
119
120 /**
121 * Init a mostly zeroed out window with the given window ID.
122 * Usually not needed if you call ::init_simple which sets up root and
123 * window.
124 */
125 void init_window(WindowPtr window, WindowPtr parent, int id);
126
127 /**
128 * Create a very simple setup that provides the minimum values for most
129 * tests, including a screen, the root and client window and the default
130 * device setup.
131 */
132 void init_simple(void);
133
134 #endif /* PROTOCOL_COMMON_H */