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