Debian Codegraph @

testsuite/gtk/firefox-stylecontext.c

raw
1 #include <gtk/gtk.h>
2
3 static void
4 test_init_of_theme (void)
5 {
6 GtkStyleContext *context;
7 GtkCssProvider *provider;
8 GtkWidgetPath *path;
9 GdkRGBA before, after;
10 char *css;
11
12 /* Test that a style context actually uses the theme loaded for the
13 * screen it is using. If no screen is set, it's the default one.
14 */
15 context = gtk_style_context_new ();
16 path = gtk_widget_path_new ();
17
18 /* Set a path that will have a color set.
19 * (This could actually fail if style classes change, so if this test
20 * fails, make sure to have this path represent something sane.)
21 */
22 gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
23 gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND);
24 gtk_style_context_set_path (context, path);
25 gtk_widget_path_free (path);
26
27 /* Get the color. This should be initialized by the theme and not be
28 * the default. */
29 gtk_style_context_get_color (context, gtk_style_context_get_state (context), &before);
30
31 /* Add a style that sets a different color for this widget.
32 * This style has a higher priority than fallback, but a lower
33 * priority than the theme. */
34 css = g_strdup_printf (".background { color: %s; }",
35 before.alpha < 0.5 ? "black" : "transparent");
36 provider = gtk_css_provider_new ();
37 gtk_css_provider_load_from_data (provider, css, -1, NULL);
38 gtk_style_context_add_provider (context,
39 GTK_STYLE_PROVIDER (provider),
40 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1);
41 g_object_unref (provider);
42
43 /* Get the color again. */
44 gtk_style_context_get_color (context, gtk_style_context_get_state (context), &after);
45
46 /* Because the style we added does not influence the color,
47 * the before and after colors should be identical. */
48 g_assert (gdk_rgba_equal (&before, &after));
49
50 g_object_unref (context);
51 }
52
53 int
54 main (int argc, char *argv[])
55 {
56 /* If gdk_init() is called before gtk_init() the GTK code takes
57 * a different path (why?)
58 */
59 gdk_init (NULL, NULL);
60 gtk_init (NULL, NULL);
61 g_test_init (&argc, &argv, NULL);
62
63 g_test_add_func ("/style/init_of_theme", test_init_of_theme);
64
65 return g_test_run ();
66 }