Debian Codegraph @

testsuite/gtk/test-focus-chain.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 Red Hat Inc.
3 *
4 * Author:
5 * Matthias Clasen <[email protected]>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <string.h>
22 #include <glib/gstdio.h>
23 #include <gtk/gtk.h>cxx . . $ `<file>/gtk/gtk.h`/
24 #include "testsuite/testutils.h"cxx . . $ `<file>/testsuite/testutils.h`/
25
26 #ifdef G_OS_WIN32
27 # include <io.h>
28 #endif
29
30 structcxx . . $ $anonymous_type_df42f243d659e8a4_0# {
31 GtkDirectionTypecxx . . $ GtkDirectionType# dircxx . . $ $anonymous_type_df42f243d659e8a4_0#dir.;
32 const char *extcxx . . $ $anonymous_type_df42f243d659e8a4_0#ext.;
33 } extensionscxx . . $ extensions.[] = {
34 { GTK_DIR_TAB_FORWARDcxx . . $ GTK_DIR_TAB_FORWARD., "tab" },
35 { GTK_DIR_TAB_BACKWARDcxx . . $ GTK_DIR_TAB_BACKWARD., "tab-backward" },
36 { GTK_DIR_UPcxx . . $ GTK_DIR_UP., "up" },
37 { GTK_DIR_DOWNcxx . . $ GTK_DIR_DOWN., "down" },
38 { GTK_DIR_LEFTcxx . . $ GTK_DIR_LEFT., "left" },
39 { GTK_DIR_RIGHTcxx . . $ GTK_DIR_RIGHT., "right" }
40 };
41
42 static void
43 check_focus_statescxx . . $ check_focus_states(d7cf858254b37903). (GtkWidgetcxx . . $ GtkWidget# *focus_widget)
44 {
45 GtkStateFlagscxx . . $ GtkStateFlags# state;
46 GtkWidgetcxx . . $ GtkWidget# *parent;
47
48 if (focus_widget == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
49 return;
50
51 /* Check that we set :focus and :focus-within on the focus_widget,
52 * and :focus-within on its ancestors
53 */
54
55 state = gtk_widget_get_state_flagscxx . . $ gtk_widget_get_state_flags(d8976ba950f6e7f). (focus_widget);
56 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! ((state & (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN)) ==
57 (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN));
58
59 parent = gtk_widget_get_parentcxx . . $ gtk_widget_get_parent(ef973e1b01680070). (focus_widget);
60 while (parent)
61 {
62 state = gtk_widget_get_state_flagscxx . . $ gtk_widget_get_state_flags(d8976ba950f6e7f). (parent);
63 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! ((state & GTK_STATE_FLAG_FOCUS_WITHIN) == GTK_STATE_FLAG_FOCUS_WITHIN);
64 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! ((state & GTK_STATE_FLAG_FOCUSED) == 0);
65
66 parent = gtk_widget_get_parentcxx . . $ gtk_widget_get_parent(ef973e1b01680070). (parent);
67 }
68 }
69
70 static gbooleancxx . . $ gboolean#
71 quit_iteration_loopcxx . . $ quit_iteration_loop(dedf1e9b1c614a07). (gpointercxx . . $ gpointer# user_data)
72 {
73 gbooleancxx . . $ gboolean# *keep_running = user_data;
74
75 *keep_running = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
76
77 return G_SOURCE_REMOVEcxx . . $ `<external>/1856471541377536744/gmain.h:475:9`!;
78 }
79
80 static void
81 timed_loopcxx . . $ timed_loop(cb2f890c2fdad230). (guintcxx . . $ guint# millis)
82 {
83 gbooleancxx . . $ gboolean# keep_running = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
84
85 g_timeout_addcxx . . $ g_timeout_add(ec6d13059821d355). (millis, quit_iteration_loopcxx . . $ quit_iteration_loop(dedf1e9b1c614a07)., &keep_running);
86 while (keep_running)
87 g_main_context_iterationcxx . . $ g_main_context_iteration(53f508c65b8b33ab). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!);
88 }
89
90 static char *
91 generate_focus_chaincxx . . $ generate_focus_chain(b6b79f7b11ea51a7). (GtkWidgetcxx . . $ GtkWidget# *window,
92 GtkDirectionTypecxx . . $ GtkDirectionType# dir)
93 {
94 char *first = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
95 char *last = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
96 char *name = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
97 char *key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
98 GStringcxx . . $ GString# *output = g_string_newcxx . . $ g_string_new(e8737c02110bb79b). ("");
99 GtkWidgetcxx . . $ GtkWidget# *focus;
100 int count = 0;
101
102 gtk_window_presentcxx . . $ gtk_window_present(f2417dd135ed86f3). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window));
103
104 /* start without focus */
105 gtk_window_set_focuscxx . . $ gtk_window_set_focus(59a2a0eb4c9edf98). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
106
107 while (TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!)
108 {
109 g_signal_emit_by_namecxx . . $ g_signal_emit_by_name(1ac911bdc4e9a14d). (window, "move-focus", dir);
110
111 focus = gtk_window_get_focuscxx . . $ gtk_window_get_focus(531371cb518b0b30). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window));
112
113 check_focus_statescxx . . $ check_focus_states(d7cf858254b37903). (focus);
114
115 if (focus)
116 {
117 /* ui files can't put a name on the embedded text,
118 * so include the parent entry here
119 */
120 if (GTK_IS_TEXTcxx . . $ `gtk/gtktext.h:44:9`! (focus))
121 name = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("%s %s",
122 gtk_widget_get_namecxx . . $ gtk_widget_get_name(e0c6ca3d7a269c15). (gtk_widget_get_parentcxx . . $ gtk_widget_get_parent(ef973e1b01680070). (focus)),
123 gtk_widget_get_namecxx . . $ gtk_widget_get_name(e0c6ca3d7a269c15). (focus));
124 else
125 name = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (gtk_widget_get_name (focus));
126
127 key = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("%s %p", name, focus);
128 }
129 else
130 {
131 name = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! ("NONE");
132 key = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (key);
133 }
134
135 if (first && g_str_equalcxx . . $ `<external>/7714589265505779806/ghash.h:175:9`! (key, first))
136 {
137 g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (output, "WRAP\n");
138 break; /* cycle completed */
139 }
140
141 if (last && g_str_equalcxx . . $ `<external>/7714589265505779806/ghash.h:175:9`! (key, last))
142 {
143 g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (output, "STOP\n");
144 break; /* dead end */
145 }
146
147 g_string_append_printfcxx . . $ g_string_append_printf(eeccf837eb821d11). (output, "%s\n", name);
148 timed_loopcxx . . $ timed_loop(cb2f890c2fdad230). (100);
149 count++;
150
151 if (!first)
152 first = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (key);
153
154 g_freecxx . . $ g_free(5d22bdacc48458e8). (last);
155 last = key;
156
157 if (count == 100)
158 {
159 g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (output, "ABORT\n");
160 break;
161 }
162
163 g_freecxx . . $ g_free(5d22bdacc48458e8). (name);
164 }
165
166 g_freecxx . . $ g_free(5d22bdacc48458e8). (name);
167 g_freecxx . . $ g_free(5d22bdacc48458e8). (key);
168 g_freecxx . . $ g_free(5d22bdacc48458e8). (first);
169 g_freecxx . . $ g_free(5d22bdacc48458e8). (last);
170
171 return g_string_freecxx . . $ `<external>/2906017559248664336/gstring.h:73:9`! (output, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!);
172 }
173
174 static GtkDirectionTypecxx . . $ GtkDirectionType#
175 get_dir_for_filecxx . . $ get_dir_for_file(8baf23c80081b8e3). (const char *path)
176 {
177 const char *p;
178 int i;
179
180 p = strrchrcxx . . $ strrchr(2050848944e00d54). (path, '.');
181 p++;
182
183 for (i = 0; i < G_N_ELEMENTScxx . . $ `<external>/12741050725406041920/gmacros.h:993:9`! (extensions); i++)
184 {
185 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88). (p, extensionscxx . . $ extensions.[i].extcxx . . $ $anonymous_type_df42f243d659e8a4_0#ext.) == 0)
186 return extensionscxx . . $ extensions.[i].dircxx . . $ $anonymous_type_df42f243d659e8a4_0#dir.;
187 }
188
189 g_errorcxx . . $ `<external>/5169755362661750954/gmessages.h:328:9`! ("Could not find direction for %s", path);
190
191 return 0;
192 }
193
194 static gbooleancxx . . $ gboolean#
195 load_ui_filecxx . . $ load_ui_file(20d5752e91d07b32). (GFilecxx . . $ GFile# *ui_file,
196 GFilecxx . . $ GFile# *ref_file,
197 const char *ext)
198 {
199 GtkBuildercxx . . $ GtkBuilder# *builder;
200 GtkWidgetcxx . . $ GtkWidget# *window;
201 char *output;
202 char *diff;
203 char *ui_path, *ref_path;
204 GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
205 GtkDirectionTypecxx . . $ GtkDirectionType# dir;
206 gbooleancxx . . $ gboolean# success = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
207 gbooleancxx . . $ gboolean# keep_running = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
208 guintcxx . . $ guint# timeout_handle_id;
209
210 ui_path = g_file_get_pathcxx . . $ g_file_get_path(bd69fa69840f32a9). (ui_file);
211
212 builder = gtk_builder_new_from_filecxx . . $ gtk_builder_new_from_file(11ae25fe414babe1). (ui_path);
213 window = GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (gtk_builder_get_object (builder, "window"));
214
215 g_assert_nonnullcxx . . $ `<external>/15287032793271088244/gtestutils.h:254:9`! (window);
216
217 gtk_window_presentcxx . . $ gtk_window_present(f2417dd135ed86f3). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window));
218
219 timeout_handle_id = g_timeout_addcxx . . $ g_timeout_add(ec6d13059821d355). (2000,
220 quit_iteration_loopcxx . . $ quit_iteration_loop(dedf1e9b1c614a07).,
221 &keep_running);
222 while (keep_running && !gtk_window_is_activecxx . . $ gtk_window_is_active(b9ada049f487cdbd). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window)))
223 g_main_context_iterationcxx . . $ g_main_context_iteration(53f508c65b8b33ab). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!);
224
225 if (keep_running)
226 g_source_removecxx . . $ g_source_remove(4c679297bf94b9eb). (timeout_handle_id);
227
228 if (!gtk_window_is_activecxx . . $ gtk_window_is_active(b9ada049f487cdbd). (GTK_WINDOWcxx . . $ `gtk/gtkwindow.h:39:9`! (window)))
229 {
230 g_printcxx . . $ g_print(326aeb464d16410c). ("Skipping focus tests because window did not get focus. Headless display?");
231 exitcxx . . $ exit(3ca292c338df9bb3). (77);
232 }
233
234 if (ext)
235 {
236 int i;
237
238 for (i = 0; i < G_N_ELEMENTScxx . . $ `<external>/12741050725406041920/gmacros.h:993:9`! (extensions); i++)
239 {
240 if (g_str_equalcxx . . $ `<external>/7714589265505779806/ghash.h:175:9`! (ext, extensions[i].ext))
241 {
242 output = generate_focus_chaincxx . . $ generate_focus_chain(b6b79f7b11ea51a7). (window, extensionscxx . . $ extensions.[i].dircxx . . $ $anonymous_type_df42f243d659e8a4_0#dir.);
243 g_printcxx . . $ g_print(326aeb464d16410c). ("%s", output);
244 success = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
245 goto out;
246 }
247 }
248
249 g_errorcxx . . $ `<external>/5169755362661750954/gmessages.h:328:9`! ("Not a supported direction: %s", ext);
250 goto out;
251 }
252
253 g_assert_nonnullcxx . . $ `<external>/15287032793271088244/gtestutils.h:254:9`! (ref_file);
254
255 ref_path = g_file_get_pathcxx . . $ g_file_get_path(bd69fa69840f32a9). (ref_file);
256
257 dir = get_dir_for_filecxx . . $ get_dir_for_file(8baf23c80081b8e3). (ref_path);
258 output = generate_focus_chaincxx . . $ generate_focus_chain(b6b79f7b11ea51a7). (window, dir);
259 diff = diff_string_with_filecxx . . $ diff_string_with_file(5ca5039161c453d4). (ref_path, output, -1, &error);
260 g_assert_no_errorcxx . . $ `<external>/15287032793271088244/gtestutils.h:217:9`! (error);
261
262 if (diff && diff[0])
263 g_printcxx . . $ g_print(326aeb464d16410c). ("Resulting output doesn't match reference:\n%s", diff);
264 else
265 success = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!;
266 g_freecxx . . $ g_free(5d22bdacc48458e8). (ref_path);
267 g_freecxx . . $ g_free(5d22bdacc48458e8). (diff);
268
269 out:
270 g_freecxx . . $ g_free(5d22bdacc48458e8). (output);
271 g_freecxx . . $ g_free(5d22bdacc48458e8). (ui_path);
272
273 return success;
274 }
275
276 static const char *arg_generatecxx . . $ arg_generate.;
277
278 static const GOptionEntrycxx . . $ GOptionEntry# optionscxx . . $ options.[] = {
279 { "generate", 0, 0, G_OPTION_ARG_STRINGcxx . . $ G_OPTION_ARG_STRING., &arg_generatecxx . . $ arg_generate., "DIRECTION" },
280 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }
281 };
282
283 int
284 maincxx . . $ main(afcd3168fc1188a4). (int argc, char **argv)
285 {
286 GOptionContextcxx . . $ GOptionContext# *context;
287 GFilecxx . . $ GFile# *ui_file;
288 GFilecxx . . $ GFile# *ref_file;
289 GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
290 gbooleancxx . . $ gboolean# success;
291
292 context = g_option_context_newcxx . . $ g_option_context_new(a696d53710071c45). ("- run focus chain tests");
293 g_option_context_add_main_entriescxx . . $ g_option_context_add_main_entries(2b8a7b3623c14603). (context, optionscxx . . $ options., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
294 g_option_context_set_ignore_unknown_optionscxx . . $ g_option_context_set_ignore_unknown_options(a30d000b03a2ce1f). (context, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!);
295
296 if (!g_option_context_parsecxx . . $ g_option_context_parse(e19b3ba917830101). (context, &argc, &argv, &error))
297 {
298 g_errorcxx . . $ `<external>/5169755362661750954/gmessages.h:328:9`! ("Option parsing failed: %s\n", error->message);
299 return 1;
300 }
301 g_option_context_freecxx . . $ g_option_context_free(a7838fb7f565d7ae). (context);
302
303 gtk_initcxx . . $ gtk_init(49f6e7a06ebc5aa8). ();
304
305 if (arg_generatecxx . . $ arg_generate.)
306 {
307 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:53:9`! (argc, ==, 2);
308
309 ui_file = g_file_new_for_commandline_argcxx . . $ g_file_new_for_commandline_arg(ba1fd5950b7d7bd5). (argv[1]);
310
311 success = load_ui_filecxx . . $ load_ui_file(20d5752e91d07b32). (ui_file, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, arg_generatecxx . . $ arg_generate.);
312
313 g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8). (ui_file);
314 }
315 else
316 {
317 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:53:9`! (argc, ==, 3);
318
319 ui_file = g_file_new_for_commandline_argcxx . . $ g_file_new_for_commandline_arg(ba1fd5950b7d7bd5). (argv[1]);
320 ref_file = g_file_new_for_commandline_argcxx . . $ g_file_new_for_commandline_arg(ba1fd5950b7d7bd5). (argv[2]);
321
322 success = load_ui_filecxx . . $ load_ui_file(20d5752e91d07b32). (ui_file, ref_file, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
323
324 g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8). (ui_file);
325 g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8). (ref_file);
326 }
327
328 return success ? 0 : 1;
329 }
330