| 1 |
#include <gtk/gtk.h> |
| 2 |
|
| 3 |
static void |
| 4 |
assert_section_is_not_null (GtkCssProvider *provider, |
| 5 |
GtkCssSection *section, |
| 6 |
const GError *error, |
| 7 |
gpointer unused) |
| 8 |
{ |
| 9 |
g_assert (section != NULL); |
| 10 |
} |
| 11 |
|
| 12 |
static void |
| 13 |
test_section_in_load_from_data (void) |
| 14 |
{ |
| 15 |
GtkCssProvider *provider; |
| 16 |
|
| 17 |
provider = gtk_css_provider_new (); |
| 18 |
g_signal_connect (provider, "parsing-error", |
| 19 |
G_CALLBACK (assert_section_is_not_null), NULL); |
| 20 |
gtk_css_provider_load_from_data (provider, "random garbage goes here", -1, NULL); |
| 21 |
g_object_unref (provider); |
| 22 |
} |
| 23 |
|
| 24 |
static void |
| 25 |
test_section_in_style_property (void) |
| 26 |
{ |
| 27 |
GtkCssProvider *provider; |
| 28 |
GtkWidgetClass *widget_class; |
| 29 |
GtkWidgetPath *path; |
| 30 |
GParamSpec *pspec; |
| 31 |
GValue value = G_VALUE_INIT; |
| 32 |
|
| 33 |
provider = gtk_css_provider_new (); |
| 34 |
g_signal_connect (provider, "parsing-error", |
| 35 |
G_CALLBACK (assert_section_is_not_null), NULL); |
| 36 |
gtk_css_provider_load_from_data (provider, "* { -GtkWidget-interior-focus: random garbage goes here; }", -1, NULL); |
| 37 |
|
| 38 |
widget_class = g_type_class_ref (GTK_TYPE_WIDGET); |
| 39 |
pspec = gtk_widget_class_find_style_property (widget_class, "interior-focus"); |
| 40 |
g_assert (pspec); |
| 41 |
path = gtk_widget_path_new (); |
| 42 |
gtk_widget_path_append_type (path, GTK_TYPE_WIDGET); |
| 43 |
|
| 44 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 45 |
gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (provider), path, 0, pspec, &value); |
| 46 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 47 |
|
| 48 |
gtk_widget_path_unref (path); |
| 49 |
g_type_class_unref (widget_class); |
| 50 |
g_object_unref (provider); |
| 51 |
} |
| 52 |
|
| 53 |
static void |
| 54 |
test_section_load_nonexisting_file (void) |
| 55 |
{ |
| 56 |
GtkCssProvider *provider; |
| 57 |
|
| 58 |
provider = gtk_css_provider_new (); |
| 59 |
g_signal_connect (provider, "parsing-error", |
| 60 |
G_CALLBACK (assert_section_is_not_null), NULL); |
| 61 |
gtk_css_provider_load_from_path (provider, "this/path/does/absolutely/not/exist.css", NULL); |
| 62 |
g_object_unref (provider); |
| 63 |
} |
| 64 |
|
| 65 |
int |
| 66 |
main (int argc, char *argv[]) |
| 67 |
{ |
| 68 |
gtk_init (NULL, NULL); |
| 69 |
g_test_init (&argc, &argv, NULL); |
| 70 |
|
| 71 |
g_test_add_func ("/cssprovider/section-in-load-from-data", test_section_in_load_from_data); |
| 72 |
g_test_add_func ("/cssprovider/section-in-style-property", test_section_in_style_property); |
| 73 |
g_test_add_func ("/cssprovider/load-nonexisting-file", test_section_load_nonexisting_file); |
| 74 |
|
| 75 |
return g_test_run (); |
| 76 |
} |