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