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 "xkbsrv.h"
34#include "xserver-properties.h"
35
36#include <glib.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 device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
46
47static void xtest_init_devices(void)
48{
49    ScreenRec screen;
50
51    /* random stuff that needs initialization */
52    memset(&screen, 0, sizeof(screen));
53    screenInfo.numScreens = 1;
54    screenInfo.screens[0] = &screen;
55    screen.myNum = 0;
56    screen.id = 100;
57    screen.width = 640;
58    screen.height = 480;
59    screen.DeviceCursorInitialize = device_cursor_init;
60    dixResetPrivates();
61    InitAtoms();
62
63    XkbInitPrivates();
64
65    /* this also inits the xtest devices */
66    InitCoreDevices();
67
68    g_assert(xtestpointer);
69    g_assert(xtestkeyboard);
70    g_assert(IsXTestDevice(xtestpointer, NULL));
71    g_assert(IsXTestDevice(xtestkeyboard, NULL));
72    g_assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
73    g_assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
74    g_assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
75    g_assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
76}
77
78/**
79 * Each xtest devices has a property attached marking it. This property
80 * cannot be changed.
81 */
82static void xtest_properties(void)
83{
84    int rc;
85    char value = 1;
86    XIPropertyValuePtr prop;
87    Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
88
89    rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
90    g_assert(rc == Success);
91    g_assert(prop);
92
93    rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
94    g_assert(rc == Success);
95    g_assert(prop != NULL);
96
97    rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
98                                XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
99    g_assert(rc == BadAccess);
100    rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
101                                XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
102    g_assert(rc == BadAccess);
103}
104
105
106
107int main(int argc, char** argv)
108{
109    g_test_init(&argc, &argv,NULL);
110    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
111
112    g_test_add_func("/dix/xtest/init", xtest_init_devices);
113    g_test_add_func("/dix/xtest/properties", xtest_properties);
114
115    return g_test_run();
116}
117
118
119