2 * Copyright © 2009 Red Hat, Inc.
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:
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
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.
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
28 #include <xkb-config.h>
36 #include <X11/Xproto.h>
37 #include <X11/keysym.h>
38 #include <X11/Xatom.h>
43 #define XKBSRV_NEED_FILE_FUNCS
45 #include "../xkb/xkbgeom.h"
46 #include <X11/extensions/XKMformat.h>
48 #include "../xkb/xkb.h"
52 * Initialize an empty XkbRMLVOSet.
53 * Call XkbGetRulesDflts to obtain the default ruleset.
54 * Compare obtained ruleset with the built-in defaults.
56 * Result: RMLVO defaults are the same as obtained.
59 xkb_get_rules_test(void)
61 XkbRMLVOSet rmlvo
= { NULL
};
62 XkbGetRulesDflts(&rmlvo
);
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);
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.
83 xkb_set_rules_test(void)
86 .rules
= "test-rules",
87 .model
= "test-model",
88 .layout
= "test-layout",
89 .variant
= "test-variant",
90 .options
= "test-options"
92 XkbRMLVOSet rmlvo_new
= { NULL
};
94 XkbSetRulesDflts(&rmlvo
);
95 XkbGetRulesDflts(&rmlvo_new
);
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
);
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);
112 * Get the default RMLVO set.
113 * Set the default RMLVO set.
114 * Get the default RMLVO set.
115 * Repeat the last two steps.
117 * Result: RMLVO set obtained is the same as previously set.
120 xkb_set_get_rules_test(void)
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
127 XkbRMLVOSet rmlvo
= { NULL
};
128 XkbRMLVOSet rmlvo_backup
;
130 XkbGetRulesDflts(&rmlvo
);
133 XkbSetRulesDflts(&rmlvo
);
134 XkbGetRulesDflts(&rmlvo
);
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
);
144 XkbSetRulesDflts(&rmlvo
);
146 /* This test is iffy, because strictly we may be comparing against already
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);
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);
163 main(int argc
, char **argv
)
165 xkb_set_get_rules_test();
166 xkb_get_rules_test();
167 xkb_set_rules_test();