xtest.c 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#include <stdint.h>
28#include <X11/Xatom.h>
29#include "input.h"
30#include "inputstr.h"
31#include "scrnintstr.h"
32#include "exevents.h"
33#include "extinit.h"
34#include "xkbsrv.h"
35#include "xserver-properties.h"
36#include "syncsrv.h"
37
38/**
39 */
40
41/* from Xext/xtest.c */
42extern DeviceIntPtr xtestpointer, xtestkeyboard;
43
44/* Needed for the screen setup, otherwise we crash during sprite initialization */
45static Bool
46device_cursor_init(DeviceIntPtr dev, ScreenPtr screen)
47{
48    return TRUE;
49}
50
51static void
52device_cursor_cleanup(DeviceIntPtr dev, ScreenPtr screen)
53{
54}
55
56static void
57xtest_init_devices(void)
58{
59    ScreenRec screen;
60    ClientRec server_client;
61
62    /* random stuff that needs initialization */
63    memset(&screen, 0, sizeof(screen));
64    screenInfo.numScreens = 1;
65    screenInfo.screens[0] = &screen;
66    screen.myNum = 0;
67    screen.id = 100;
68    screen.width = 640;
69    screen.height = 480;
70    screen.DeviceCursorInitialize = device_cursor_init;
71    screen.DeviceCursorCleanup = device_cursor_cleanup;
72    dixResetPrivates();
73    serverClient = &server_client;
74    InitClient(serverClient, 0, (void *) NULL);
75    if (!InitClientResources(serverClient)) /* for root resources */
76        FatalError("couldn't init server resources");
77    InitAtoms();
78    SyncExtensionInit();
79
80    /* this also inits the xtest devices */
81    InitCoreDevices();
82
83    assert(xtestpointer);
84    assert(xtestkeyboard);
85    assert(IsXTestDevice(xtestpointer, NULL));
86    assert(IsXTestDevice(xtestkeyboard, NULL));
87    assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
88
89    assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
90    assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
91
92    assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
93}
94
95/**
96 * Each xtest devices has a property attached marking it. This property
97 * cannot be changed.
98 */
99static void
100xtest_properties(void)
101{
102    int rc;
103    char value = 1;
104    XIPropertyValuePtr prop;
105    Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
106
107    rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
108    assert(rc == Success);
109    assert(prop);
110
111    rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
112    assert(rc == Success);
113    assert(prop != NULL);
114
115    rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
116                                XA_INTEGER, 8, PropModeReplace, 1, &value,
117                                FALSE);
118    assert(rc == BadAccess);
119    rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
120                                XA_INTEGER, 8, PropModeReplace, 1, &value,
121                                FALSE);
122    assert(rc == BadAccess);
123}
124
125int
126main(int argc, char **argv)
127{
128    xtest_init_devices();
129    xtest_properties();
130
131    return 0;
132}
133