1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*:*
* ggaze — window smoke test (integration)
*
* Constructs a GgazeWindow offscreen and asserts the two-view stack exists
* (children "grid" and "large", default visible = "grid"), and that
* ggaze_window_open titles the window with the file's basename.
*
* The window is built with g_object_new() (no "application" property): the
* stack/header are constructed in ggaze_window_init, independent of the app
* association. Setting GtkWindow:application requires the GApplication
* ::startup signal to have fired (it does in production via activate/open;
* not in this isolated smoke test). Needs a display, so this lives in the
* `integration` suite (CI runs it under xvfb); skipped cleanly when no
* display is available.
*
* Copyright (c) 2026 ggaze contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*:*/
#include "window.h"
#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
static GgazeWindow *
new_window(void) {
return (GGAZE_WINDOW(g_object_new(GGAZE_TYPE_WINDOW, NULL)));
}
static void
test_stack_has_two_views(void) {
GgazeWindow *p_win = new_window();
g_assert_nonnull(p_win);
GtkWidget *p_child = GTK_WIDGET(ggaze_window_get_stack(p_win));
g_assert_nonnull(p_child);
g_assert_true(GTK_IS_STACK(p_child));
GtkStack *p_stack = GTK_STACK(p_child);
GListModel *p_pages = G_LIST_MODEL(gtk_stack_get_pages(p_stack));
g_assert_cmpint(g_list_model_get_n_items(p_pages), ==, 2);
g_assert_nonnull(gtk_stack_get_child_by_name(p_stack, "grid"));
g_assert_nonnull(gtk_stack_get_child_by_name(p_stack, "large"));
g_assert_cmpstr(gtk_stack_get_visible_child_name(p_stack), ==, "grid");
g_object_unref(p_pages);
g_object_unref(p_win);
}
static void
test_open_titles_window(void) {
const gchar *c_dir = g_getenv("GGAZE_FIXTURES_DIR");
g_assert_nonnull(c_dir);
gchar *c_path = g_build_filename(c_dir, "plain.jpg", NULL);
GgazeWindow *p_win = new_window();
GFile *p_file = g_file_new_for_path(c_path);
ggaze_window_open(p_win, p_file);
/* M2: opening a file lists its parent folder; the header title carries
* the current filename + "n/total". */
const gchar *c_title = gtk_window_get_title(GTK_WINDOW(p_win));
g_assert_nonnull(c_title);
g_assert_nonnull(g_strstr_len(c_title, -1, "plain.jpg"));
g_assert_nonnull(g_strstr_len(c_title, -1, "/"));
g_object_unref(p_file);
g_object_unref(p_win);
g_free(c_path);
}
int
main(int i_argc, char **c_argv) {
g_test_init(&i_argc, &c_argv, NULL);
/* Tolerate host GTK WARNINGs (e.g. an unknown gtk-modules key delivered
* by the live GNOME session via XSettings) that g_test_init makes fatal.
* Keep CRITICALs fatal — those are real bugs. */
g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
if (!gtk_init_check()) {
g_test_skip("no display available (run under xvfb)");
return (g_test_run());
}
g_test_add_func("/window/stack_has_two_views", test_stack_has_two_views);
g_test_add_func("/window/open_titles_window", test_open_titles_window);
return (g_test_run());
}
|