protocol-common.h revision 35c4bbdf
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#ifndef PROTOCOL_COMMON_H
34#define PROTOCOL_COMMON_H
35
36/* Check default values in a reply */
37#define reply_check_defaults(rep, len, type) \
38    { \
39        assert((len) >= sz_x##type##Reply); \
40        assert((rep)->repType == X_Reply); \
41        assert((rep)->RepType == X_##type); \
42        assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
43        assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
44    }
45
46/* initialise default values for request */
47#define request_init(req, type) \
48    { \
49        (req)->reqType = 128; /* doesn't matter */ \
50        (req)->ReqType = X_##type; \
51        (req)->length = (sz_x##type##Req >> 2); \
52    }
53
54/* Various defines used in the tests. Some tests may use different values
55 * than these defaults */
56/* default client index */
57#define CLIENT_INDEX            1
58/* default client mask for resources and windows */
59#define CLIENT_MASK             ((CLIENT_INDEX) << CLIENTOFFSET)
60/* default client sequence number for replies */
61#define CLIENT_SEQUENCE         0x100
62/* default root window id */
63#define ROOT_WINDOW_ID          0x10
64/* default client window id */
65#define CLIENT_WINDOW_ID        0x100001
66/* invalid window ID. use for BadWindow checks. */
67#define INVALID_WINDOW_ID       0x111111
68/* initial fake sprite position */
69#define SPRITE_X                100
70#define SPRITE_Y                200
71
72/* Various structs used throughout the tests */
73
74/* The default devices struct, contains one pointer + keyboard and the
75 * matching master devices. Initialize with init_devices() if needed. */
76struct devices {
77    DeviceIntPtr vcp;
78    DeviceIntPtr vck;
79    DeviceIntPtr mouse;
80    DeviceIntPtr kbd;
81
82    int num_devices;
83    int num_master_devices;
84};
85
86/**
87 * The set of default devices available in all tests if necessary.
88 */
89extern struct devices devices;
90
91/**
92 * test-specific userdata, passed into the reply handler.
93 */
94extern void *global_userdata;
95
96/**
97 * The reply handler called from WriteToClient. Set this handler if you need
98 * to check the reply values.
99 */
100void (*reply_handler) (ClientPtr client, int len, char *data, void *userdata);
101
102/**
103 * The default screen used for the windows. Initialized by init_simple().
104 */
105extern ScreenRec screen;
106
107/**
108 * Semi-initialized root window. initialized by init().
109 */
110extern WindowRec root;
111
112/**
113 * Semi-initialized top-level window. initialized by init().
114 */
115extern WindowRec window;
116
117/* various simple functions for quick setup */
118/**
119 * Initialize the above struct with default devices and return the struct.
120 * Usually not needed if you call ::init_simple.
121 */
122struct devices init_devices(void);
123
124/**
125 * Init a mostly zeroed out client with default values for index and mask.
126 */
127ClientRec init_client(int request_len, void *request_data);
128
129/**
130 * Init a mostly zeroed out window with the given window ID.
131 * Usually not needed if you call ::init_simple which sets up root and
132 * window.
133 */
134void init_window(WindowPtr window, WindowPtr parent, int id);
135
136/**
137 * Create a very simple setup that provides the minimum values for most
138 * tests, including a screen, the root and client window and the default
139 * device setup.
140 */
141void init_simple(void);
142
143/* Declarations for various overrides in the test files. */
144void __wrap_WriteToClient(ClientPtr client, int len, void *data);
145int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len,
146                          unsigned char *mask);
147int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client,
148                           Mask access);
149int __real_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client,
150                           Mask access);
151Bool __wrap_AddResource(XID id, RESTYPE type, void *value);
152int __wrap_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
153int __real_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
154
155#endif                          /* PROTOCOL_COMMON_H */
156