Add patch that contain Mali fixes.
[deb_xorg-server.git] / test / xkb.c
CommitLineData
a09e091a
JB
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
28#include <xkb-config.h>
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <ctype.h>
33#include <unistd.h>
34#include <math.h>
35#include <X11/X.h>
36#include <X11/Xproto.h>
37#include <X11/keysym.h>
38#include <X11/Xatom.h>
39#include "misc.h"
40#include "inputstr.h"
41#include "opaque.h"
42#include "property.h"
43#define XKBSRV_NEED_FILE_FUNCS
44#include <xkbsrv.h>
45#include "../xkb/xkbgeom.h"
46#include <X11/extensions/XKMformat.h>
47#include "xkbfile.h"
48#include "../xkb/xkb.h"
49#include <assert.h>
50
51/**
52 * Initialize an empty XkbRMLVOSet.
53 * Call XkbGetRulesDflts to obtain the default ruleset.
54 * Compare obtained ruleset with the built-in defaults.
55 *
56 * Result: RMLVO defaults are the same as obtained.
57 */
58static void
59xkb_get_rules_test(void)
60{
61 XkbRMLVOSet rmlvo = { NULL };
62 XkbGetRulesDflts(&rmlvo);
63
64 assert(rmlvo.rules);
65 assert(rmlvo.model);
66 assert(rmlvo.layout);
67 assert(rmlvo.variant);
68 assert(rmlvo.options);
69 assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0);
70 assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0);
71 assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0);
72 assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0);
73 assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0);
74}
75
76/**
77 * Initialize an random XkbRMLVOSet.
78 * Call XkbGetRulesDflts to obtain the default ruleset.
79 * Compare obtained ruleset with the built-in defaults.
80 * Result: RMLVO defaults are the same as obtained.
81 */
82static void
83xkb_set_rules_test(void)
84{
85 XkbRMLVOSet rmlvo = {
86 .rules = "test-rules",
87 .model = "test-model",
88 .layout = "test-layout",
89 .variant = "test-variant",
90 .options = "test-options"
91 };
92 XkbRMLVOSet rmlvo_new = { NULL };
93
94 XkbSetRulesDflts(&rmlvo);
95 XkbGetRulesDflts(&rmlvo_new);
96
97 /* XkbGetRulesDflts strdups the values */
98 assert(rmlvo.rules != rmlvo_new.rules);
99 assert(rmlvo.model != rmlvo_new.model);
100 assert(rmlvo.layout != rmlvo_new.layout);
101 assert(rmlvo.variant != rmlvo_new.variant);
102 assert(rmlvo.options != rmlvo_new.options);
103
104 assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0);
105 assert(strcmp(rmlvo.model, rmlvo_new.model) == 0);
106 assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0);
107 assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0);
108 assert(strcmp(rmlvo.options, rmlvo_new.options) == 0);
109}
110
111/**
112 * Get the default RMLVO set.
113 * Set the default RMLVO set.
114 * Get the default RMLVO set.
115 * Repeat the last two steps.
116 *
117 * Result: RMLVO set obtained is the same as previously set.
118 */
119static void
120xkb_set_get_rules_test(void)
121{
122/* This test failed before XkbGetRulesDftlts changed to strdup.
123 We test this twice because the first time using XkbGetRulesDflts we obtain
124 the built-in defaults. The unexpected free isn't triggered until the second
125 XkbSetRulesDefaults.
126 */
127 XkbRMLVOSet rmlvo = { NULL };
128 XkbRMLVOSet rmlvo_backup;
129
130 XkbGetRulesDflts(&rmlvo);
131
132 /* pass 1 */
133 XkbSetRulesDflts(&rmlvo);
134 XkbGetRulesDflts(&rmlvo);
135
136 /* Make a backup copy */
137 rmlvo_backup.rules = strdup(rmlvo.rules);
138 rmlvo_backup.layout = strdup(rmlvo.layout);
139 rmlvo_backup.model = strdup(rmlvo.model);
140 rmlvo_backup.variant = strdup(rmlvo.variant);
141 rmlvo_backup.options = strdup(rmlvo.options);
142
143 /* pass 2 */
144 XkbSetRulesDflts(&rmlvo);
145
146 /* This test is iffy, because strictly we may be comparing against already
147 * freed memory */
148 assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
149 assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
150 assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
151 assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
152 assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
153
154 XkbGetRulesDflts(&rmlvo);
155 assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
156 assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
157 assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
158 assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
159 assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
160}
161
162int
163main(int argc, char **argv)
164{
165 xkb_set_get_rules_test();
166 xkb_get_rules_test();
167 xkb_set_rules_test();
168
169 return 0;
170}