1 | #include <gtk/gtk.h> |
2 | |
3 | typedef struct _Theme Theme; |
4 | |
5 | struct _Theme |
6 | { |
7 | const char *name; |
8 | const char *variant; |
9 | }; |
10 | |
11 | static void |
12 | theme_parsing_error (GtkCssProvider *provider, |
13 | GtkCssSection *section, |
14 | const GError *error, |
15 | gpointer unused) |
16 | { |
17 | char *s = gtk_css_section_to_string (section); |
18 | |
19 | g_test_message (format: "Theme parsing error: %s: %s" , |
20 | s, |
21 | error->message); |
22 | |
23 | g_free (mem: s); |
24 | |
25 | g_test_fail (); |
26 | } |
27 | |
28 | static void |
29 | test_theme (gconstpointer data) |
30 | { |
31 | const Theme *theme = data; |
32 | GtkCssProvider *provider; |
33 | |
34 | provider = gtk_css_provider_new (); |
35 | g_signal_connect (provider, "parsing-error" , |
36 | G_CALLBACK (theme_parsing_error), NULL); |
37 | gtk_css_provider_load_named (provider, name: theme->name, variant: theme->variant); |
38 | g_object_unref (object: provider); |
39 | } |
40 | |
41 | int |
42 | main (int argc, char *argv[]) |
43 | { |
44 | const Theme themes[] = { |
45 | { "Adwaita" , NULL }, |
46 | { "Adwaita" , "dark" }, |
47 | { "HighContrast" , NULL }, |
48 | { "HighContrast" , "dark" } |
49 | }; |
50 | guint i; |
51 | |
52 | gtk_init (); |
53 | (g_test_init) (argc: &argc, argv: &argv, NULL); |
54 | |
55 | for (i = 0; i < G_N_ELEMENTS (themes); i++) |
56 | { |
57 | char *testname; |
58 | |
59 | if (themes[i].variant == NULL) |
60 | testname = g_strdup_printf (format: "/theme-validate/%s" , themes[i].name); |
61 | else |
62 | testname = g_strdup_printf (format: "/theme-validate/%s-%s" , themes[i].name, themes[i].variant); |
63 | |
64 | g_test_add_data_func (testpath: testname, test_data: &themes[i], test_func: test_theme); |
65 | |
66 | g_free (mem: testname); |
67 | } |
68 | |
69 | return g_test_run (); |
70 | } |
71 | |