1706f2543Smrg/**
2706f2543Smrg * Copyright © 2009 Red Hat, Inc.
3706f2543Smrg *
4706f2543Smrg *  Permission is hereby granted, free of charge, to any person obtaining a
5706f2543Smrg *  copy of this software and associated documentation files (the "Software"),
6706f2543Smrg *  to deal in the Software without restriction, including without limitation
7706f2543Smrg *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8706f2543Smrg *  and/or sell copies of the Software, and to permit persons to whom the
9706f2543Smrg *  Software is furnished to do so, subject to the following conditions:
10706f2543Smrg *
11706f2543Smrg *  The above copyright notice and this permission notice (including the next
12706f2543Smrg *  paragraph) shall be included in all copies or substantial portions of the
13706f2543Smrg *  Software.
14706f2543Smrg *
15706f2543Smrg *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16706f2543Smrg *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17706f2543Smrg *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18706f2543Smrg *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19706f2543Smrg *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20706f2543Smrg *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21706f2543Smrg *  DEALINGS IN THE SOFTWARE.
22706f2543Smrg */
23706f2543Smrg
24706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
25706f2543Smrg#include <dix-config.h>
26706f2543Smrg#endif
27706f2543Smrg#include <stdint.h>
28706f2543Smrg#include <X11/Xatom.h>
29706f2543Smrg#include "input.h"
30706f2543Smrg#include "inputstr.h"
31706f2543Smrg#include "scrnintstr.h"
32706f2543Smrg#include "exevents.h"
33706f2543Smrg#include "xkbsrv.h"
34706f2543Smrg#include "xserver-properties.h"
35706f2543Smrg
36706f2543Smrg#include <glib.h>
37706f2543Smrg
38706f2543Smrg/**
39706f2543Smrg */
40706f2543Smrg
41706f2543Smrg/* from Xext/xtest.c */
42706f2543Smrgextern DeviceIntPtr xtestpointer, xtestkeyboard;
43706f2543Smrg
44706f2543Smrg/* Needed for the screen setup, otherwise we crash during sprite initialization */
45706f2543Smrgstatic Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
46706f2543Smrg
47706f2543Smrgstatic void xtest_init_devices(void)
48706f2543Smrg{
49706f2543Smrg    ScreenRec screen;
50706f2543Smrg
51706f2543Smrg    /* random stuff that needs initialization */
52706f2543Smrg    memset(&screen, 0, sizeof(screen));
53706f2543Smrg    screenInfo.numScreens = 1;
54706f2543Smrg    screenInfo.screens[0] = &screen;
55706f2543Smrg    screen.myNum = 0;
56706f2543Smrg    screen.id = 100;
57706f2543Smrg    screen.width = 640;
58706f2543Smrg    screen.height = 480;
59706f2543Smrg    screen.DeviceCursorInitialize = device_cursor_init;
60706f2543Smrg    dixResetPrivates();
61706f2543Smrg    InitAtoms();
62706f2543Smrg
63706f2543Smrg    XkbInitPrivates();
64706f2543Smrg
65706f2543Smrg    /* this also inits the xtest devices */
66706f2543Smrg    InitCoreDevices();
67706f2543Smrg
68706f2543Smrg    g_assert(xtestpointer);
69706f2543Smrg    g_assert(xtestkeyboard);
70706f2543Smrg    g_assert(IsXTestDevice(xtestpointer, NULL));
71706f2543Smrg    g_assert(IsXTestDevice(xtestkeyboard, NULL));
72706f2543Smrg    g_assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
73706f2543Smrg    g_assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
74706f2543Smrg    g_assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
75706f2543Smrg    g_assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
76706f2543Smrg}
77706f2543Smrg
78706f2543Smrg/**
79706f2543Smrg * Each xtest devices has a property attached marking it. This property
80706f2543Smrg * cannot be changed.
81706f2543Smrg */
82706f2543Smrgstatic void xtest_properties(void)
83706f2543Smrg{
84706f2543Smrg    int rc;
85706f2543Smrg    char value = 1;
86706f2543Smrg    XIPropertyValuePtr prop;
87706f2543Smrg    Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
88706f2543Smrg
89706f2543Smrg    rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
90706f2543Smrg    g_assert(rc == Success);
91706f2543Smrg    g_assert(prop);
92706f2543Smrg
93706f2543Smrg    rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
94706f2543Smrg    g_assert(rc == Success);
95706f2543Smrg    g_assert(prop != NULL);
96706f2543Smrg
97706f2543Smrg    rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
98706f2543Smrg                                XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
99706f2543Smrg    g_assert(rc == BadAccess);
100706f2543Smrg    rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
101706f2543Smrg                                XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
102706f2543Smrg    g_assert(rc == BadAccess);
103706f2543Smrg}
104706f2543Smrg
105706f2543Smrg
106706f2543Smrg
107706f2543Smrgint main(int argc, char** argv)
108706f2543Smrg{
109706f2543Smrg    g_test_init(&argc, &argv,NULL);
110706f2543Smrg    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
111706f2543Smrg
112706f2543Smrg    g_test_add_func("/dix/xtest/init", xtest_init_devices);
113706f2543Smrg    g_test_add_func("/dix/xtest/properties", xtest_properties);
114706f2543Smrg
115706f2543Smrg    return g_test_run();
116706f2543Smrg}
117706f2543Smrg
118706f2543Smrg
119