1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun * Copyright © 2009 Red Hat, Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun * Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
25*4882a593Smuzhiyun #include <dix-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun #include <stdint.h>
28*4882a593Smuzhiyun #include <X11/Xatom.h>
29*4882a593Smuzhiyun #include "input.h"
30*4882a593Smuzhiyun #include "inputstr.h"
31*4882a593Smuzhiyun #include "scrnintstr.h"
32*4882a593Smuzhiyun #include "windowstr.h"
33*4882a593Smuzhiyun #include "exevents.h"
34*4882a593Smuzhiyun #include "extinit.h"
35*4882a593Smuzhiyun #include "xkbsrv.h"
36*4882a593Smuzhiyun #include "xserver-properties.h"
37*4882a593Smuzhiyun #include "syncsrv.h"
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun #include "tests-common.h"
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun */
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun /* from Xext/xtest.c */
45*4882a593Smuzhiyun extern DeviceIntPtr xtestpointer, xtestkeyboard;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* Needed for the screen setup, otherwise we crash during sprite initialization */
48*4882a593Smuzhiyun static Bool
device_cursor_init(DeviceIntPtr dev,ScreenPtr screen)49*4882a593Smuzhiyun device_cursor_init(DeviceIntPtr dev, ScreenPtr screen)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun return TRUE;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun static void
device_cursor_cleanup(DeviceIntPtr dev,ScreenPtr screen)55*4882a593Smuzhiyun device_cursor_cleanup(DeviceIntPtr dev, ScreenPtr screen)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static void
xtest_init_devices(void)60*4882a593Smuzhiyun xtest_init_devices(void)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun ScreenRec screen = {0};
63*4882a593Smuzhiyun ClientRec server_client = {0};
64*4882a593Smuzhiyun WindowRec root = {0};
65*4882a593Smuzhiyun WindowOptRec optional = {0};
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* random stuff that needs initialization */
68*4882a593Smuzhiyun root.drawable.id = 0xab;
69*4882a593Smuzhiyun root.optional = &optional;
70*4882a593Smuzhiyun screen.root = &root;
71*4882a593Smuzhiyun screenInfo.numScreens = 1;
72*4882a593Smuzhiyun screenInfo.screens[0] = &screen;
73*4882a593Smuzhiyun screen.myNum = 0;
74*4882a593Smuzhiyun screen.id = 100;
75*4882a593Smuzhiyun screen.width = 640;
76*4882a593Smuzhiyun screen.height = 480;
77*4882a593Smuzhiyun screen.DeviceCursorInitialize = device_cursor_init;
78*4882a593Smuzhiyun screen.DeviceCursorCleanup = device_cursor_cleanup;
79*4882a593Smuzhiyun dixResetPrivates();
80*4882a593Smuzhiyun serverClient = &server_client;
81*4882a593Smuzhiyun InitClient(serverClient, 0, (void *) NULL);
82*4882a593Smuzhiyun if (!InitClientResources(serverClient)) /* for root resources */
83*4882a593Smuzhiyun FatalError("couldn't init server resources");
84*4882a593Smuzhiyun InitAtoms();
85*4882a593Smuzhiyun SyncExtensionInit();
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun /* this also inits the xtest devices */
88*4882a593Smuzhiyun InitCoreDevices();
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun assert(xtestpointer);
91*4882a593Smuzhiyun assert(xtestkeyboard);
92*4882a593Smuzhiyun assert(IsXTestDevice(xtestpointer, NULL));
93*4882a593Smuzhiyun assert(IsXTestDevice(xtestkeyboard, NULL));
94*4882a593Smuzhiyun assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
97*4882a593Smuzhiyun assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /**
103*4882a593Smuzhiyun * Each xtest devices has a property attached marking it. This property
104*4882a593Smuzhiyun * cannot be changed.
105*4882a593Smuzhiyun */
106*4882a593Smuzhiyun static void
xtest_properties(void)107*4882a593Smuzhiyun xtest_properties(void)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun int rc;
110*4882a593Smuzhiyun char value = 1;
111*4882a593Smuzhiyun XIPropertyValuePtr prop;
112*4882a593Smuzhiyun Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
115*4882a593Smuzhiyun assert(rc == Success);
116*4882a593Smuzhiyun assert(prop);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
119*4882a593Smuzhiyun assert(rc == Success);
120*4882a593Smuzhiyun assert(prop != NULL);
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
123*4882a593Smuzhiyun XA_INTEGER, 8, PropModeReplace, 1, &value,
124*4882a593Smuzhiyun FALSE);
125*4882a593Smuzhiyun assert(rc == BadAccess);
126*4882a593Smuzhiyun rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
127*4882a593Smuzhiyun XA_INTEGER, 8, PropModeReplace, 1, &value,
128*4882a593Smuzhiyun FALSE);
129*4882a593Smuzhiyun assert(rc == BadAccess);
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun int
xtest_test(void)133*4882a593Smuzhiyun xtest_test(void)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun xtest_init_devices();
136*4882a593Smuzhiyun xtest_properties();
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return 0;
139*4882a593Smuzhiyun }
140