Debian Codegraph @

test/test.h

raw
1 /*
2 * Copyright © 2012 Intel Corporation
3 * SPDX-License-Identifier: MIT
4 *
5 * Author: Daniel Stone <[email protected]>
6 */
7 #pragma once
8
9 #include "config.h"
10
11 #include <assert.h>
12 #include <stdbool.h>
13
14 /* Don't use compat names in internal code. */
15 #define _XKBCOMMON_COMPAT_H
16 #include "xkbcommon/xkbcommon.h"
17 #include "xkbcommon/xkbcommon-compose.h"
18 #include "src/messages-codes.h"
19 #include "utils.h"
20
21 /* Automake test exit code to signify SKIP (à la PASS, FAIL, etc).
22 * See: https://www.gnu.org/software/automake/manual/html_node/Scripts_002dbased-Testsuites.html */
23 #define SKIP_TEST 77
24 #define TEST_SETUP_FAILURE 99
25
26 #define assert_printf(cond, ...) do { \
27 const bool __cond = (cond); \
28 if (!__cond) { \
29 fprintf(stderr, "Assertion failure: " __VA_ARGS__); \
30 assert(__cond); \
31 }} while (0)
32
33 #define assert_streq_not_null(test_name, expected, got) \
34 assert_printf(streq_not_null(expected, got), \
35 test_name ". Expected \"%s\", got: \"%s\"\n", expected, got)
36
37 #define assert_eq(test_name, expected, got, format, ...) \
38 assert_printf(expected == got, \
39 test_name ". Expected " format ", got: " format "\n", \
40 ##__VA_ARGS__, expected, got)
41
42 #define TEST_KEYMAP_SERIALIZE_FLAGS \
43 (XKB_KEYMAP_SERIALIZE_PRETTY | XKB_KEYMAP_SERIALIZE_KEEP_UNUSED)
44
45 void
46 test_init(void);
47
48 void
49 print_detailed_state(struct xkb_state *state);
50
51 /* The offset between KEY_* numbering, and keycodes in the XKB evdev
52 * dataset. */
53 #define EVDEV_OFFSET 8
54
55 enum key_seq_state {
56 DOWN,
57 REPEAT,
58 UP,
59 BOTH,
60 NEXT,
61 FINISH,
62 };
63
64 int
65 test_key_seq(struct xkb_keymap *keymap, ...);
66
67 int
68 test_key_seq_va(struct xkb_keymap *keymap, va_list args);
69
70 char *
71 test_makedir(const char *parent, const char *path);
72
73 char *
74 test_maketempdir(const char *template);
75
76 char *
77 test_get_path(const char *path_rel);
78
79 char *
80 read_file(const char *path, FILE *file);
81
82 char *
83 test_read_file(const char *path_rel);
84
85 enum test_context_flags {
86 CONTEXT_NO_FLAG = 0,
87 CONTEXT_ALLOW_ENVIRONMENT_NAMES = (1 << 0),
88 };
89
90 struct xkb_context *
91 test_get_context(enum test_context_flags flags);
92
93 struct xkb_keymap *
94 test_compile_file(struct xkb_context *context, enum xkb_keymap_format format,
95 const char *path_rel);
96
97 struct xkb_keymap *
98 test_compile_string(struct xkb_context *context, enum xkb_keymap_format format,
99 const char *string);
100
101 struct xkb_keymap *
102 test_compile_buffer(struct xkb_context *context, enum xkb_keymap_format format,
103 const char *buf, size_t len);
104
105 typedef struct xkb_keymap * (*test_compile_buffer_t)(struct xkb_context *context,
106 enum xkb_keymap_format format,
107 const char *buf, size_t len,
108 void *private);
109
110 bool
111 test_compile_output(struct xkb_context *ctx, enum xkb_keymap_format input_format,
112 enum xkb_keymap_format output_format,
113 test_compile_buffer_t compile_buffer,
114 void *compile_buffer_private, const char *test_title,
115 const char *keymap_str, size_t keymap_len,
116 const char *rel_path, bool update_output_files);
117
118 bool
119 test_compile_output2(struct xkb_context *ctx,
120 enum xkb_keymap_format input_format,
121 enum xkb_keymap_format output_format,
122 enum xkb_keymap_serialize_flags serialize_flags,
123 test_compile_buffer_t compile_buffer,
124 void *compile_buffer_private, const char *test_title,
125 const char *keymap_str, size_t keymap_len,
126 const char *rel_path, bool update_output_files);
127
128 typedef int (*test_third_party_compile_buffer_t)(const char *buf, size_t len,
129 void *private,
130 char **out, size_t *size_out);
131
132 bool
133 test_third_pary_compile_output(test_third_party_compile_buffer_t compile_buffer,
134 void *compile_buffer_private,
135 const char *test_title,
136 const char *keymap_str, size_t keymap_len,
137 const char *rel_path, bool update_output_files);
138
139 struct xkb_keymap *
140 test_compile_rmlvo(struct xkb_context *context, enum xkb_keymap_format format,
141 const char *rules, const char *model, const char *layout,
142 const char *variant, const char *options);
143
144 struct xkb_keymap *
145 test_compile_rules(struct xkb_context *context, enum xkb_keymap_format format,
146 const char *rules, const char *model, const char *layout,
147 const char *variant, const char *options);
148
149 static inline void
150 xkb_enable_quiet_logging(struct xkb_context *ctx)
151 {
152 xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
153 xkb_context_set_log_verbosity(ctx, XKB_LOG_VERBOSITY_MINIMAL);
154 }
155
156 #ifdef _WIN32
157 #define setenv(varname, value, overwrite) _putenv_s((varname), (value))
158 #define unsetenv(varname) _putenv_s(varname, "")
159 #endif