diff options
Diffstat (limited to 'testsuite')
61 files changed, 968 insertions, 47 deletions
diff --git a/testsuite/css/change/meson.build b/testsuite/css/change/meson.build index 83e37ae2f6..a52fc5348e 100644 --- a/testsuite/css/change/meson.build +++ b/testsuite/css/change/meson.build @@ -1,3 +1,12 @@ +changetest_env = environment() +changetest_env.set('GTK_TEST_ACCESSIBLE', '1') +changetest_env.set('GSK_RENDERER', 'cairo') +changetest_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +changetest_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) +changetest_env.set('GIO_USE_VFS', 'local') +changetest_env.set('GSETTINGS_BACKEND', 'memory') +changetest_env.set('G_ENABLE_DIAGNOSTIC', '0') + testexecdir = join_paths(installed_test_bindir, 'css', 'change') testdatadir = join_paths(installed_test_datadir, 'css') @@ -13,7 +22,7 @@ test_change = executable( test('change', test_change, args: [ '--tap', '-k' ], protocol: 'tap', - env: csstest_env, + env: changetest_env, suite: 'css', ) diff --git a/testsuite/css/data.c b/testsuite/css/data.c index 72533fcfb2..978be0e55e 100644 --- a/testsuite/css/data.c +++ b/testsuite/css/data.c @@ -58,6 +58,15 @@ Test tests[] = { { "charset_base64", "data:text/plain;charset=ISO-8859-5;base64,wOPh29DdILjW0ePb0OLe0g==", "text/plain", CONTENTS("Руслан Ижбулатов") }, + { "wrong_scheme", + "duda:,Hello", + NULL, NULL, 0 }, + { "missing_comma", + "data:text/plain;charset=ISO-8859-1:bla", + NULL, NULL, 0 }, + { "bad_escape", + "data:,abc%00", + NULL, NULL, -1 }, }; static void @@ -70,17 +79,25 @@ test_parse (gconstpointer data) bytes = gtk_css_data_url_parse (test->url, &mimetype, &error); - g_assert (bytes != NULL); - g_assert_no_error (error); - if (test->mimetype == NULL) - g_assert (mimetype == NULL); - else - g_assert_cmpstr (mimetype, ==, test->mimetype); - - g_assert_cmpmem (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), - test->contents, test->contents_len); + if (test->contents) + { + g_assert_nonnull (bytes); + g_assert_no_error (error); + if (test->mimetype == NULL) + g_assert (mimetype == NULL); + else + g_assert_cmpstr (mimetype, ==, test->mimetype); - g_bytes_unref (bytes); + g_assert_cmpmem (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), + test->contents, test->contents_len); + g_bytes_unref (bytes); + } + else + { + g_assert_null (bytes); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME); + g_error_free (error); + } } int diff --git a/testsuite/css/nodes/meson.build b/testsuite/css/nodes/meson.build index 11ed48b9e5..313e06a112 100644 --- a/testsuite/css/nodes/meson.build +++ b/testsuite/css/nodes/meson.build @@ -1,3 +1,12 @@ +nodetest_env = environment() +nodetest_env.set('GTK_TEST_ACCESSIBLE', '1') +nodetest_env.set('GSK_RENDERER', 'cairo') +nodetest_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +nodetest_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) +nodetest_env.set('GIO_USE_VFS', 'local') +nodetest_env.set('GSETTINGS_BACKEND', 'memory') +nodetest_env.set('G_ENABLE_DIAGNOSTIC', '0') + testexecdir = join_paths(installed_test_bindir, 'css', 'nodes') testdatadir = join_paths(installed_test_datadir, 'css') @@ -9,7 +18,7 @@ test_nodes = executable('test-css-nodes', 'test-css-nodes.c', test('nodes', test_nodes, args: [ '--tap', '-k' ], protocol: 'tap', - env: csstest_env, + env: nodetest_env, suite: 'css', ) diff --git a/testsuite/css/parser/cdo-cdc.css b/testsuite/css/parser/cdo-cdc.css new file mode 100644 index 0000000000..3670c19285 --- /dev/null +++ b/testsuite/css/parser/cdo-cdc.css @@ -0,0 +1,7 @@ +<!-- + +label { + color: red; +} + +--> diff --git a/testsuite/css/parser/cdo-cdc.ref.css b/testsuite/css/parser/cdo-cdc.ref.css new file mode 100644 index 0000000000..e53c8cfd5c --- /dev/null +++ b/testsuite/css/parser/cdo-cdc.ref.css @@ -0,0 +1,3 @@ +label { + color: rgb(255,0,0); +} diff --git a/testsuite/css/parser/meson.build b/testsuite/css/parser/meson.build index 7ffd5d2644..7e501aebda 100644 --- a/testsuite/css/parser/meson.build +++ b/testsuite/css/parser/meson.build @@ -197,6 +197,8 @@ test_data = [ 'calc.ref.css', 'calc-simple.css', 'calc-simple.ref.css', + 'cdo-cdc.css', + 'cdo-cdc.ref.css', 'close-at-end-of-file.css', 'close-at-end-of-file.errors', 'close-at-end-of-file.ref.css', @@ -372,6 +374,8 @@ test_data = [ 'not-unclosed.ref.css', 'nth-child.css', 'nth-child.ref.css', + 'number-values.css', + 'number-values.ref.css', 'opacity.css', 'opacity.ref.css', 'outline-color.css', @@ -440,6 +444,18 @@ test_data = [ 'transition.ref.css', 'transition-timing-function.css', 'transition-timing-function.ref.css', + 'url-invalid1.css', + 'url-invalid1.errors', + 'url-invalid1.ref.css', + 'url-invalid2.css', + 'url-invalid2.errors', + 'url-invalid2.ref.css', + 'url-valid1.css', + 'url-valid1.ref.css', + 'url-valid2.css', + 'url-valid2.ref.css', + 'url-valid3.css', + 'url-valid3.ref.css', 'value-inherit.css', 'value-inherit.ref.css', 'value-inherit.errors', diff --git a/testsuite/css/parser/url-invalid1.css b/testsuite/css/parser/url-invalid1.css new file mode 100644 index 0000000000..903f2dc996 --- /dev/null +++ b/testsuite/css/parser/url-invalid1.css @@ -0,0 +1,4 @@ + +label { + background-image: url(resource:///org/gtk/libgtk/icons/16x16(/places/user-trash.png); +} diff --git a/testsuite/css/parser/url-invalid1.errors b/testsuite/css/parser/url-invalid1.errors new file mode 100644 index 0000000000..4fe152bf6e --- /dev/null +++ b/testsuite/css/parser/url-invalid1.errors @@ -0,0 +1 @@ +url-invalid1.css:3:21-87: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/css/parser/url-invalid1.ref.css b/testsuite/css/parser/url-invalid1.ref.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/css/parser/url-invalid1.ref.css diff --git a/testsuite/css/parser/url-invalid2.css b/testsuite/css/parser/url-invalid2.css new file mode 100644 index 0000000000..340d29925c --- /dev/null +++ b/testsuite/css/parser/url-invalid2.css @@ -0,0 +1,4 @@ + +label { + background-image: url(resource:///org/gtk/ libgtk/icons/16x16/places/user-trash.png); +} diff --git a/testsuite/css/parser/url-invalid2.errors b/testsuite/css/parser/url-invalid2.errors new file mode 100644 index 0000000000..7978a02772 --- /dev/null +++ b/testsuite/css/parser/url-invalid2.errors @@ -0,0 +1 @@ +url-invalid2.css:3:21-87: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/css/parser/url-invalid2.ref.css b/testsuite/css/parser/url-invalid2.ref.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/css/parser/url-invalid2.ref.css diff --git a/testsuite/css/parser/url-valid1.css b/testsuite/css/parser/url-valid1.css new file mode 100644 index 0000000000..c2f1984998 --- /dev/null +++ b/testsuite/css/parser/url-valid1.css @@ -0,0 +1,3 @@ +label { + background-image: url("resource:///org/gtk/libgtk/icons/16x16/places/user-trash.png"); +} diff --git a/testsuite/css/parser/url-valid1.ref.css b/testsuite/css/parser/url-valid1.ref.css new file mode 100644 index 0000000000..e0f30dafeb --- /dev/null +++ b/testsuite/css/parser/url-valid1.ref.css @@ -0,0 +1,3 @@ +label { + background-image: none /* FIXME */; +} diff --git a/testsuite/css/parser/url-valid2.css b/testsuite/css/parser/url-valid2.css new file mode 100644 index 0000000000..89f42f16cf --- /dev/null +++ b/testsuite/css/parser/url-valid2.css @@ -0,0 +1,4 @@ + +label { + background-image: url(resource:///org/gtk/libgtk/icons/16x16/places/user-trash.png); +} diff --git a/testsuite/css/parser/url-valid2.ref.css b/testsuite/css/parser/url-valid2.ref.css new file mode 100644 index 0000000000..e0f30dafeb --- /dev/null +++ b/testsuite/css/parser/url-valid2.ref.css @@ -0,0 +1,3 @@ +label { + background-image: none /* FIXME */; +} diff --git a/testsuite/css/parser/url-valid3.css b/testsuite/css/parser/url-valid3.css new file mode 100644 index 0000000000..b9add7f7a7 --- /dev/null +++ b/testsuite/css/parser/url-valid3.css @@ -0,0 +1,4 @@ + +label { + background-image: url( resource:///\6F rg/gtk/libgtk/icons/16x16/places/user-trash.png ); +} diff --git a/testsuite/css/parser/url-valid3.ref.css b/testsuite/css/parser/url-valid3.ref.css new file mode 100644 index 0000000000..e0f30dafeb --- /dev/null +++ b/testsuite/css/parser/url-valid3.ref.css @@ -0,0 +1,3 @@ +label { + background-image: none /* FIXME */; +} diff --git a/testsuite/css/style/meson.build b/testsuite/css/style/meson.build index b54adf7c68..a7af27deb3 100644 --- a/testsuite/css/style/meson.build +++ b/testsuite/css/style/meson.build @@ -1,3 +1,12 @@ +styletest_env = environment() +styletest_env.set('GTK_TEST_ACCESSIBLE', '1') +styletest_env.set('GSK_RENDERER', 'cairo') +styletest_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +styletest_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) +styletest_env.set('GIO_USE_VFS', 'local') +styletest_env.set('GSETTINGS_BACKEND', 'memory') +styletest_env.set('G_ENABLE_DIAGNOSTIC', '0') + testexecdir = join_paths(installed_test_bindir, 'css', 'style') testdatadir = join_paths(installed_test_datadir, 'css') @@ -19,7 +28,7 @@ test_style = executable( test('style', test_style, args: [ '--tap', '-k' ], protocol: 'tap', - env: csstest_env, + env: styletest_env, suite: 'css', ) diff --git a/testsuite/gdk/displaymanager.c b/testsuite/gdk/displaymanager.c new file mode 100644 index 0000000000..ce7c0d974f --- /dev/null +++ b/testsuite/gdk/displaymanager.c @@ -0,0 +1,55 @@ +#include <gtk/gtk.h> + +static void +test_basic (void) +{ + GdkDisplayManager *manager; + GdkDisplay *d, *d2; + GSList *list; + + manager = gdk_display_manager_get (); + g_assert_nonnull (manager); + + d = gdk_display_manager_get_default_display (manager); + g_assert_nonnull (d); + g_object_get (manager, "default-display", &d2, NULL); + g_assert_true (d == d2); + g_object_unref (d2); + + list = gdk_display_manager_list_displays (manager); + g_assert_nonnull (g_slist_find (list, d)); + g_slist_free (list); +} + +static void +test_set_default (void) +{ + GdkDisplayManager *manager; + GdkDisplay *d, *d2; + const char *name; + + manager = gdk_display_manager_get (); + g_assert_nonnull (manager); + + d = gdk_display_manager_get_default_display (manager); + name = gdk_display_get_name (d); + d2 = gdk_display_manager_open_display (manager, name); + g_object_set (manager, "default-display", d2, NULL); + + d = gdk_display_manager_get_default_display (manager); + g_assert_true (d == d2); +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + /* Open default display */ + gdk_display_open (NULL); + + g_test_add_func ("/displaymanager/basic", test_basic); + g_test_add_func ("/displaymanager/set-default", test_set_default); + + return g_test_run (); +} diff --git a/testsuite/gdk/keysyms.c b/testsuite/gdk/keysyms.c index 217b8a4600..481aafae4c 100644 --- a/testsuite/gdk/keysyms.c +++ b/testsuite/gdk/keysyms.c @@ -54,7 +54,77 @@ test_keysyms_xf86 (void) g_assert_cmpuint (gdk_keyval_from_name ("Display"), ==, GDK_KEY_Display); } -int main (int argc, char *argv[]) +#define UNICODE_KEYVAL(wc) ((wc) | 0x01000000) + +static void +test_key_case (void) +{ + struct { + guint lower; + guint upper; + } tests[] = { + { GDK_KEY_a, GDK_KEY_A }, + { GDK_KEY_agrave, GDK_KEY_Agrave }, + { GDK_KEY_thorn, GDK_KEY_Thorn }, + { GDK_KEY_oslash, GDK_KEY_Oslash }, + { GDK_KEY_aogonek, GDK_KEY_Aogonek }, + { GDK_KEY_lstroke, GDK_KEY_Lstroke }, + { GDK_KEY_scaron, GDK_KEY_Scaron }, + { GDK_KEY_zcaron, GDK_KEY_Zcaron }, + { GDK_KEY_racute, GDK_KEY_Racute }, + { GDK_KEY_hstroke, GDK_KEY_Hstroke }, + { GDK_KEY_jcircumflex, GDK_KEY_Jcircumflex }, + { GDK_KEY_cabovedot, GDK_KEY_Cabovedot }, + { GDK_KEY_rcedilla, GDK_KEY_Rcedilla }, + { GDK_KEY_eng, GDK_KEY_ENG }, + { GDK_KEY_amacron, GDK_KEY_Amacron }, + { GDK_KEY_Serbian_dje, GDK_KEY_Serbian_DJE }, + { GDK_KEY_Cyrillic_yu, GDK_KEY_Cyrillic_YU }, + { GDK_KEY_Greek_alphaaccent, GDK_KEY_Greek_ALPHAaccent }, + { GDK_KEY_Greek_omega, GDK_KEY_Greek_OMEGA }, + { GDK_KEY_Greek_sigma, GDK_KEY_Greek_SIGMA }, + + { GDK_KEY_space, GDK_KEY_space }, + { GDK_KEY_0, GDK_KEY_0 }, + { GDK_KEY_KP_0, GDK_KEY_KP_0 }, + + /* Face Savouring Delicious Food */ + { UNICODE_KEYVAL (0x1f60b), UNICODE_KEYVAL (0x1f60b) }, + }; + guint i; + + for (i = 0; i < G_N_ELEMENTS (tests); i++) + { + g_assert_true (gdk_keyval_is_lower (tests[i].lower)); + g_assert_true (gdk_keyval_is_upper (tests[i].upper)); + g_assert_cmpuint (gdk_keyval_to_upper (tests[i].lower), ==, tests[i].upper); + g_assert_cmpuint (gdk_keyval_to_lower (tests[i].upper), ==, tests[i].lower); + } +} + +static void +test_key_unicode (void) +{ + struct { + guint key; + gunichar ch; + } tests[] = { + { GDK_KEY_a, 'a' }, + { GDK_KEY_A, 'A' }, + { GDK_KEY_EuroSign, 0x20ac }, + { UNICODE_KEYVAL (0x1f60b), 0x1f60b }, + }; + guint i; + + for (i = 0; i < G_N_ELEMENTS (tests); i++) + { + g_assert_cmpuint (gdk_keyval_to_unicode (tests[i].key), ==, tests[i].ch); + g_assert_cmpuint (gdk_unicode_to_keyval (tests[i].ch), ==, tests[i].key); + } +} + +int +main (int argc, char *argv[]) { setlocale (LC_ALL, ""); @@ -64,6 +134,8 @@ int main (int argc, char *argv[]) g_test_add_func ("/keysyms/basic", test_keysyms_basic); g_test_add_func ("/keysyms/void", test_keysyms_void); g_test_add_func ("/keysyms/xf86", test_keysyms_xf86); + g_test_add_func ("/keys/case", test_key_case); + g_test_add_func ("/keys/unicode", test_key_unicode); return g_test_run (); } diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build index aa93f8384d..c62c931905 100644 --- a/testsuite/gdk/meson.build +++ b/testsuite/gdk/meson.build @@ -6,12 +6,14 @@ tests = [ 'cairo', 'clipboard', 'display', + 'displaymanager', 'encoding', 'keysyms', 'memorytexture', 'rectangle', 'rgba', 'seat', + 'texture', ] foreach t : tests diff --git a/testsuite/gdk/rectangle.c b/testsuite/gdk/rectangle.c index ead270eea7..bf8f9983b3 100644 --- a/testsuite/gdk/rectangle.c +++ b/testsuite/gdk/rectangle.c @@ -1,4 +1,5 @@ #include <gtk/gtk.h> +#include <cairo-gobject.h> static void test_rectangle_equal (void) @@ -65,6 +66,47 @@ test_rectangle_union (void) g_assert_true (gdk_rectangle_equal (&f, &g)); } +/* Test that GdkRectangle works as a boxed type */ + +static void +test_rectangle_type (void) +{ + GValue value = G_VALUE_INIT; + GdkRectangle b = { 5, 5, 10, 10 }; + GdkRectangle *c; + GValue value2 = G_VALUE_INIT; + cairo_rectangle_int_t *c2; + + g_value_init (&value, GDK_TYPE_RECTANGLE); + g_value_set_boxed (&value, &b); + c = g_value_get_boxed (&value); + + g_assert_true (gdk_rectangle_equal (&b, c)); + + g_assert_true (g_value_type_transformable (GDK_TYPE_RECTANGLE, CAIRO_GOBJECT_TYPE_RECTANGLE_INT)); + g_value_init (&value2, CAIRO_GOBJECT_TYPE_RECTANGLE_INT); + g_assert_true (g_value_transform (&value, &value2)); + c2 = g_value_get_boxed (&value2); + g_assert_cmpint (c->x, ==, c2->x); + g_assert_cmpint (c->y, ==, c2->y); + g_assert_cmpint (c->width, ==, c2->width); + g_assert_cmpint (c->height, ==, c2->height); + + g_value_unset (&value); + g_value_unset (&value2); +} + +static void +test_rectangle_contains (void) +{ + GdkRectangle b = { 5, 5, 5, 5 }; + + g_assert_true (gdk_rectangle_contains_point (&b, 5, 5)); + g_assert_true (gdk_rectangle_contains_point (&b, 9, 9)); + g_assert_false (gdk_rectangle_contains_point (&b, 4, 8)); + g_assert_false (gdk_rectangle_contains_point (&b, 10, 6)); +} + int main (int argc, char *argv[]) { @@ -75,6 +117,8 @@ main (int argc, char *argv[]) g_test_add_func ("/rectangle/equal", test_rectangle_equal); g_test_add_func ("/rectangle/intersect", test_rectangle_intersect); g_test_add_func ("/rectangle/union", test_rectangle_union); + g_test_add_func ("/rectangle/type", test_rectangle_type); + g_test_add_func ("/rectangle/contains", test_rectangle_contains); return g_test_run (); } diff --git a/testsuite/gdk/seat.c b/testsuite/gdk/seat.c index bd98236132..75fd9616fd 100644 --- a/testsuite/gdk/seat.c +++ b/testsuite/gdk/seat.c @@ -38,11 +38,12 @@ test_list_seats (void) static void test_default_seat (void) { - GdkDisplay *display; + GdkDisplay *display, *d; GdkSeat *seat0; GdkSeatCapabilities caps; GdkDevice *pointer0, *keyboard0, *device; - GList *physical_devices, *l; + GList *physical_devices, *tools, *l; + GdkDeviceTool *tool; display = gdk_display_get_default (); seat0 = gdk_display_get_default_seat (display); @@ -55,9 +56,14 @@ test_default_seat (void) g_assert_true (GDK_IS_SEAT (seat0)); + g_assert_true (gdk_seat_get_display (seat0) == display); + g_object_get (seat0, "display", &d, NULL); + g_assert_true (display == d); + g_object_unref (d); + caps = gdk_seat_get_capabilities (seat0); - g_assert (caps != GDK_SEAT_CAPABILITY_NONE); + g_assert_true (caps != GDK_SEAT_CAPABILITY_NONE); pointer0 = gdk_seat_get_pointer (seat0); physical_devices = gdk_seat_get_devices (seat0, GDK_SEAT_CAPABILITY_POINTER); @@ -65,15 +71,15 @@ test_default_seat (void) if ((caps & GDK_SEAT_CAPABILITY_POINTER) != 0) { g_assert_nonnull (pointer0); - g_assert (gdk_device_get_display (pointer0) == display); - g_assert (gdk_device_get_seat (pointer0) == seat0); + g_assert_true (gdk_device_get_display (pointer0) == display); + g_assert_true (gdk_device_get_seat (pointer0) == seat0); g_assert_nonnull (physical_devices); for (l = physical_devices; l; l = l->next) { device = l->data; - g_assert (gdk_device_get_display (device) == display); - g_assert (gdk_device_get_seat (device) == seat0); + g_assert_true (gdk_device_get_display (device) == display); + g_assert_true (gdk_device_get_seat (device) == seat0); } g_list_free (physical_devices); } @@ -89,17 +95,17 @@ test_default_seat (void) if ((caps & GDK_SEAT_CAPABILITY_KEYBOARD) != 0) { g_assert_nonnull (keyboard0); - g_assert (gdk_device_get_display (keyboard0) == display); - g_assert (gdk_device_get_seat (keyboard0) == seat0); - g_assert (gdk_device_get_source (keyboard0) == GDK_SOURCE_KEYBOARD); + g_assert_true (gdk_device_get_display (keyboard0) == display); + g_assert_true (gdk_device_get_seat (keyboard0) == seat0); + g_assert_true (gdk_device_get_source (keyboard0) == GDK_SOURCE_KEYBOARD); g_assert_nonnull (physical_devices); for (l = physical_devices; l; l = l->next) { device = l->data; - g_assert (gdk_device_get_display (device) == display); - g_assert (gdk_device_get_seat (device) == seat0); - g_assert (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD); + g_assert_true (gdk_device_get_display (device) == display); + g_assert_true (gdk_device_get_seat (device) == seat0); + g_assert_true (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD); } g_list_free (physical_devices); } @@ -109,6 +115,13 @@ test_default_seat (void) g_assert_null (physical_devices); } + tools = gdk_seat_get_tools (seat0); + for (l = tools; l; l = l->next) + { + tool = l->data; + g_assert_true (GDK_IS_DEVICE_TOOL (tool)); + } + g_list_free (tools); } int diff --git a/testsuite/gdk/texture.c b/testsuite/gdk/texture.c new file mode 100644 index 0000000000..fc1f728c7c --- /dev/null +++ b/testsuite/gdk/texture.c @@ -0,0 +1,120 @@ +#include <gtk.h> + +static gboolean +compare_pixels (int width, + int height, + guchar *data1, + gsize stride1, + guchar *data2, + gsize stride2) +{ + int i; + for (i = 0; i < height; i++) + { + gconstpointer p1 = data1 + i * stride1; + gconstpointer p2 = data2 + i * stride2; + if (memcmp (p1, p2, width * 4) != 0) + return FALSE; + } + return TRUE; +} + +static void +test_texture_from_pixbuf (void) +{ + GdkPixbuf *pixbuf; + GdkTexture *texture; + GError *error = NULL; + guchar *data; + int width, height; + gsize stride; + cairo_surface_t *surface; + cairo_t *cr; + + pixbuf = gdk_pixbuf_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png", &error); + g_assert_no_error (error); + g_assert_nonnull (pixbuf); + g_assert_true (gdk_pixbuf_get_has_alpha (pixbuf)); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + texture = gdk_texture_new_for_pixbuf (pixbuf); + + g_assert_nonnull (texture); + g_assert_cmpint (gdk_texture_get_width (texture), ==, width); + g_assert_cmpint (gdk_texture_get_height (texture), ==, height); + + stride = 4 * width; + data = g_new0 (guchar, stride * height); + gdk_texture_download (texture, data, stride); + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + cr = cairo_create (surface); + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + + g_assert_true (compare_pixels (width, height, + data, stride, + cairo_image_surface_get_data (surface), + cairo_image_surface_get_stride (surface))); + + g_free (data); + + g_object_unref (pixbuf); + g_object_unref (texture); + cairo_surface_destroy (surface); +} + +static void +test_texture_from_resource (void) +{ + GdkTexture *texture; + int width, height; + + texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png"); + + g_assert_nonnull (texture); + g_object_get (texture, + "width", &width, + "height", &height, + NULL); + g_assert_cmpint (width, ==, 16); + g_assert_cmpint (height, ==, 16); + + g_object_unref (texture); +} + +static void +test_texture_save_to_png (void) +{ + GdkTexture *texture; + GError *error = NULL; + GFile *file; + GdkTexture *texture2; + + texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png"); + + gdk_texture_save_to_png (texture, "test.png"); + file = g_file_new_for_path ("test.png"); + texture2 = gdk_texture_new_from_file (file, &error); + g_object_unref (file); + g_assert_no_error (error); + + g_object_unref (texture); + g_object_unref (texture2); +} + +int +main (int argc, char *argv[]) +{ + /* We want to use resources from libgtk, so we need gtk initialized */ + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/texture/from-pixbuf", test_texture_from_pixbuf); + g_test_add_func ("/texture/from-resource", test_texture_from_resource); + g_test_add_func ("/texture/save-to-png", test_texture_save_to_png); + + return g_test_run (); +} diff --git a/testsuite/gtk/expression.c b/testsuite/gtk/expression.c index a874e562a4..cea66f3ae9 100644 --- a/testsuite/gtk/expression.c +++ b/testsuite/gtk/expression.c @@ -61,6 +61,16 @@ test_property (void) g_object_unref (filter); } +static void +test_interface_property (void) +{ + GtkExpression *expr; + + expr = gtk_property_expression_new (GTK_TYPE_ORIENTABLE, NULL, "orientation"); + g_assert_cmpstr (gtk_property_expression_get_pspec (expr)->name, ==, "orientation"); + gtk_expression_unref (expr); +} + static char * print_filter_info (GtkStringFilter *filter, const char *search, @@ -75,7 +85,7 @@ print_filter_info (GtkStringFilter *filter, } static void -test_closure (void) +test_cclosure (void) { GValue value = G_VALUE_INIT; GtkExpression *expr, *pexpr[3]; @@ -127,11 +137,34 @@ test_closure (void) g_object_unref (filter); } +static char * +make_string (void) +{ + return g_strdup ("Hello"); +} + +static void +test_closure (void) +{ + GValue value = G_VALUE_INIT; + GtkExpression *expr; + GClosure *closure; + + closure = g_cclosure_new (G_CALLBACK (make_string), NULL, NULL); + expr = gtk_closure_expression_new (G_TYPE_STRING, closure, 0, NULL); + g_assert (gtk_expression_evaluate (expr, NULL, &value)); + g_assert_cmpstr (g_value_get_string (&value), ==, "Hello"); + g_value_unset (&value); + + gtk_expression_unref (expr); +} + static void test_constant (void) { GtkExpression *expr; GValue value = G_VALUE_INIT; + const GValue *v; gboolean res; expr = gtk_constant_expression_new (G_TYPE_INT, 22); @@ -142,6 +175,9 @@ test_constant (void) g_assert_true (res); g_assert_cmpint (g_value_get_int (&value), ==, 22); + v = gtk_constant_expression_get_value (expr); + g_assert_cmpint (g_value_get_int (v), ==, 22); + gtk_expression_unref (expr); } @@ -155,6 +191,7 @@ test_object (void) GObject *obj; GValue value = G_VALUE_INIT; gboolean res; + GObject *o; obj = G_OBJECT (gtk_string_filter_new (NULL)); @@ -167,6 +204,9 @@ test_object (void) g_assert_true (g_value_get_object (&value) == obj); g_value_unset (&value); + o = gtk_object_expression_get_object (expr); + g_assert_true (o == obj); + g_clear_object (&obj); res = gtk_expression_evaluate (expr, NULL, &value); g_assert_false (res); @@ -650,6 +690,9 @@ test_binds (void) expr2 = gtk_property_expression_new (GTK_TYPE_STRING_FILTER, gtk_expression_ref (filter2_expr), "ignore-case"); + g_assert_true (gtk_property_expression_get_expression (expr2) == filter2_expr); + g_assert_cmpstr (gtk_property_expression_get_pspec (expr2)->name, ==, "ignore-case"); + gtk_expression_bind (gtk_expression_ref (expr), filter3, "search", NULL); gtk_expression_bind (gtk_expression_ref (expr2), filter3, "ignore-case", NULL); @@ -704,6 +747,28 @@ test_bind_object (void) g_object_unref (model); } +static void +test_value (void) +{ + GValue value = G_VALUE_INIT; + GtkExpression *expr; + + expr = gtk_constant_expression_new (G_TYPE_INT, 22); + + g_value_init (&value, GTK_TYPE_EXPRESSION); + gtk_value_take_expression (&value, expr); + g_assert_true (G_VALUE_TYPE (&value) == GTK_TYPE_EXPRESSION); + + expr = gtk_value_dup_expression (&value); + gtk_expression_unref (expr); + + expr = gtk_constant_expression_new (G_TYPE_INT, 23); + gtk_value_set_expression (&value, expr); + gtk_expression_unref (expr); + + g_value_unset (&value); +} + int main (int argc, char *argv[]) { @@ -711,6 +776,8 @@ main (int argc, char *argv[]) setlocale (LC_ALL, "C"); g_test_add_func ("/expression/property", test_property); + g_test_add_func ("/expression/interface-property", test_interface_property); + g_test_add_func ("/expression/cclosure", test_cclosure); g_test_add_func ("/expression/closure", test_closure); g_test_add_func ("/expression/constant", test_constant); g_test_add_func ("/expression/constant-watch-this-destroyed", test_constant_watch_this_destroyed); @@ -726,6 +793,7 @@ main (int argc, char *argv[]) g_test_add_func ("/expression/double-bind", test_double_bind); g_test_add_func ("/expression/binds", test_binds); g_test_add_func ("/expression/bind-object", test_bind_object); + g_test_add_func ("/expression/value", test_value); return g_test_run (); } diff --git a/testsuite/gtk/filter.c b/testsuite/gtk/filter.c index b16c5c4321..d6fb3fdb0e 100644 --- a/testsuite/gtk/filter.c +++ b/testsuite/gtk/filter.c @@ -219,6 +219,7 @@ test_any_simple (void) { GtkFilterListModel *model; GtkFilter *any, *filter1, *filter2; + gpointer item; any = GTK_FILTER (gtk_any_filter_new ()); filter1 = GTK_FILTER (gtk_custom_filter_new (divisible_by, GUINT_TO_POINTER (3), NULL)); @@ -233,6 +234,12 @@ test_any_simple (void) gtk_multi_filter_append (GTK_MULTI_FILTER (any), filter2); assert_model (model, "3 5 6 9 10 12 15 18 20"); + g_assert_true (g_list_model_get_item_type (G_LIST_MODEL (any)) == GTK_TYPE_FILTER); + g_assert_cmpuint (2, ==, g_list_model_get_n_items (G_LIST_MODEL (any))); + item = g_list_model_get_item (G_LIST_MODEL (any), 1); + g_assert_true (GTK_FILTER (item) == filter2); + g_object_unref (item); + gtk_multi_filter_remove (GTK_MULTI_FILTER (any), 0); assert_model (model, "5 10 15 20"); @@ -275,13 +282,15 @@ test_string_properties (void) { GtkFilterListModel *model; GtkFilter *filter; + GtkExpression *expr; - filter = GTK_FILTER (gtk_string_filter_new ( - gtk_cclosure_expression_new (G_TYPE_STRING, - NULL, - 0, NULL, - G_CALLBACK (get_spelled_out), - NULL, NULL))); + expr = gtk_cclosure_expression_new (G_TYPE_STRING, + NULL, + 0, NULL, + G_CALLBACK (get_spelled_out), + NULL, NULL); + filter = GTK_FILTER (gtk_string_filter_new (expr)); + g_assert_true (expr == gtk_string_filter_get_expression (GTK_STRING_FILTER (filter))); model = new_model (1000, filter); gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "thirte"); @@ -296,12 +305,18 @@ test_string_properties (void) gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "Thirteen"); assert_model (model, "13"); + gtk_string_filter_set_match_mode (GTK_STRING_FILTER (filter), GTK_STRING_FILTER_MATCH_MODE_PREFIX); + assert_model (model, "13"); + gtk_string_filter_set_match_mode (GTK_STRING_FILTER (filter), GTK_STRING_FILTER_MATCH_MODE_EXACT); assert_model (model, "13"); gtk_string_filter_set_ignore_case (GTK_STRING_FILTER (filter), TRUE); assert_model (model, "13"); + gtk_string_filter_set_match_mode (GTK_STRING_FILTER (filter), GTK_STRING_FILTER_MATCH_MODE_PREFIX); + assert_model (model, "13"); + gtk_string_filter_set_match_mode (GTK_STRING_FILTER (filter), GTK_STRING_FILTER_MATCH_MODE_SUBSTRING); assert_model (model, "13 113 213 313 413 513 613 713 813 913"); @@ -326,9 +341,11 @@ test_bool_simple (void) assert_model (model, "3 6 9 12 15 18"); gtk_bool_filter_set_invert (GTK_BOOL_FILTER (filter), TRUE); + g_assert_true (gtk_bool_filter_get_invert (GTK_BOOL_FILTER (filter))); assert_model (model, "1 2 4 5 7 8 10 11 13 14 16 17 19 20"); gtk_bool_filter_set_invert (GTK_BOOL_FILTER (filter), FALSE); + g_assert_false (gtk_bool_filter_get_invert (GTK_BOOL_FILTER (filter))); assert_model (model, "3 6 9 12 15 18"); expr = gtk_cclosure_expression_new (G_TYPE_BOOLEAN, @@ -337,6 +354,7 @@ test_bool_simple (void) G_CALLBACK (divisible_by), GUINT_TO_POINTER (5), NULL); gtk_bool_filter_set_expression (GTK_BOOL_FILTER (filter), expr); + g_assert_true (expr == gtk_bool_filter_get_expression (GTK_BOOL_FILTER (filter))); gtk_expression_unref (expr); assert_model (model, "5 10 15 20"); diff --git a/testsuite/gtk/main.c b/testsuite/gtk/main.c index 20a3c63083..d1d3e6ee1b 100644 --- a/testsuite/gtk/main.c +++ b/testsuite/gtk/main.c @@ -9,6 +9,21 @@ test_init (void) g_assert (gtk_is_initialized () == TRUE); } +static void +test_version (void) +{ + g_assert_cmpuint (gtk_get_major_version (), ==, GTK_MAJOR_VERSION); + g_assert_cmpuint (gtk_get_minor_version (), ==, GTK_MINOR_VERSION); + g_assert_cmpuint (gtk_get_micro_version (), ==, GTK_MICRO_VERSION); + g_assert_cmpuint (gtk_get_binary_age (), ==, GTK_BINARY_AGE); + g_assert_cmpuint (gtk_get_interface_age (), ==, GTK_INTERFACE_AGE); + + g_assert_null (gtk_check_version (GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION)); + g_assert_nonnull (gtk_check_version (5, 0, 0)); + g_assert_nonnull (gtk_check_version (1, 0, 0)); + g_assert_nonnull (gtk_check_version (3, 1000, 10)); +} + int main (int argc, char *argv[]) { @@ -18,6 +33,7 @@ main (int argc, char *argv[]) setlocale (LC_ALL, "C"); g_test_add_func ("/main/init", test_init); + g_test_add_func ("/main/version", test_version); return g_test_run (); } diff --git a/testsuite/gtk/sorter.c b/testsuite/gtk/sorter.c index ad6d94ebbb..6822c9ad08 100644 --- a/testsuite/gtk/sorter.c +++ b/testsuite/gtk/sorter.c @@ -405,6 +405,7 @@ test_multi (void) GtkSorter *sorter1; GtkSorter *sorter2; GtkExpression *expression; + gpointer item; model = new_model (20, NULL); assert_not_model (model, "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"); @@ -424,6 +425,12 @@ test_multi (void) gtk_multi_sorter_append (GTK_MULTI_SORTER (sorter), sorter1); gtk_multi_sorter_append (GTK_MULTI_SORTER (sorter), sorter2); + g_assert_true (GTK_TYPE_SORTER == g_list_model_get_item_type (G_LIST_MODEL (sorter))); + g_assert_cmpuint (2, ==, g_list_model_get_n_items (G_LIST_MODEL (sorter))); + item = g_list_model_get_item (G_LIST_MODEL (sorter), 1); + g_assert_true (item == sorter2); + g_object_unref (item); + assert_model (model, "2 4 6 8 10 12 14 16 18 20 1 3 5 7 9 11 13 15 17 19"); /* This doesn't do anything */ diff --git a/testsuite/gtk/stringlist.c b/testsuite/gtk/stringlist.c index 12169be13e..63a1f6def4 100644 --- a/testsuite/gtk/stringlist.c +++ b/testsuite/gtk/stringlist.c @@ -110,12 +110,24 @@ new_model (const char **strings) } static void +test_string_object (void) +{ + GtkStringObject *so; + + so = gtk_string_object_new ("Hello"); + g_assert_cmpstr (gtk_string_object_get_string (so), ==, "Hello"); + g_object_unref (so); +} + +static void test_create_empty (void) { GtkStringList *list; list = new_model ((const char *[]){ NULL }); + g_assert_true (g_type_is_a (g_list_model_get_item_type (G_LIST_MODEL (list)), G_TYPE_OBJECT)); + assert_model (list, ""); assert_changes (list, ""); @@ -237,6 +249,7 @@ main (int argc, char *argv[]) changes_quark = g_quark_from_static_string ("What did I see? Can I believe what I saw?"); + g_test_add_func ("/stringobject/basic", test_string_object); g_test_add_func ("/stringlist/create/empty", test_create_empty); g_test_add_func ("/stringlist/create/strv", test_create_strv); g_test_add_func ("/stringlist/create/builder", test_create_builder); diff --git a/testsuite/gtk/ui/constraints.expected b/testsuite/gtk/ui/constraints.expected new file mode 100644 index 0000000000..ff43ca4091 --- /dev/null +++ b/testsuite/gtk/ui/constraints.expected @@ -0,0 +1 @@ +SUCCESS diff --git a/testsuite/gtk/ui/constraints.ui b/testsuite/gtk/ui/constraints.ui new file mode 100644 index 0000000000..9dadad61e1 --- /dev/null +++ b/testsuite/gtk/ui/constraints.ui @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkWindow" id="window1"> + <property name="title" translatable="yes">Constraints</property> + <child> + <object class="GtkBox"> + <property name="layout-manager"> + <object class="GtkConstraintLayout"> + <constraints> + <guide name="space" + min-width="10" min-height="10" + nat-width="100" nat-height="10" + max-width="200" max-height="20" + strength="strong"/> + <constraint target="button1" target-attribute="width" + relation="le" + constant="200" + multiplier="2.5" + strength="required"/> + <constraint target="super" target-attribute="start" + relation="eq" + source="button1" source-attribute="start" + constant="-8" + multiplier="100" + strength="strong"/> + <constraint target="button1" target-attribute="width" + relation="eq" + source="button2" source-attribute="left" + strength="medium"/> + <constraint target="button1" target-attribute="end" + relation="eq" + source="space" source-attribute="right" + strength="weak"/> + <constraint target="space" target-attribute="end" + relation="eq" + source="button2" source-attribute="center-x" + strength="required"/> + <constraint target="super" target-attribute="center-y" + relation="eq" + source="button2" source-attribute="baseline" + constant="8" + strength="required"/> + <constraint target="super" target-attribute="start" + relation="eq" + source="button3" source-attribute="start" + constant="-8" + strength="required"/> + <constraint target="super" target-attribute="end" + relation="eq" + source="button3" source-attribute="end" + constant="8" + strength="required"/> + <constraint target="super" target-attribute="top" + relation="eq" + source="button1" source-attribute="top" + constant="-8" + strength="required"/> + <constraint target="super" target-attribute="top" + relation="eq" + source="button2" source-attribute="top" + constant="-8" + strength="required"/> + <constraint target="button1" target-attribute="bottom" + relation="eq" + source="button3" source-attribute="top" + constant="-12" + strength="required"/> + <constraint target="button2" target-attribute="bottom" + relation="eq" + source="button3" source-attribute="top" + constant="-12" + strength="required"/> + <constraint target="button3" target-attribute="height" + relation="eq" + source="button1" source-attribute="height" + strength="required"/> + <constraint target="button3" target-attribute="height" + relation="eq" + source="button2" source-attribute="height" + strength="required"/> + <constraint target="super" target-attribute="bottom" + relation="eq" + source="button3" source-attribute="bottom" + constant="8" + strength="required"/> + </constraints> + </object> + </property> + <child> + <object class="GtkButton" id="button1"> + <property name="label">Child 1</property> + </object> + </child> + <child> + <object class="GtkButton" id="button2"> + <property name="label">Child 2</property> + </object> + </child> + <child> + <object class="GtkButton" id="button3"> + <property name="label">Child 3</property> + </object> + </child> + </object> + </child> + </object> +</interface> diff --git a/testsuite/tools/meson.build b/testsuite/tools/meson.build index 1369ccfedc..54b9312e7a 100644 --- a/testsuite/tools/meson.build +++ b/testsuite/tools/meson.build @@ -5,7 +5,7 @@ bash = find_program('bash', required : false) if bash.found() test_env = environment() - foreach t : ['simplify', 'simplify-3to4', 'settings'] + foreach t : ['simplify', 'simplify-3to4', 'validate', 'settings'] if get_option('install-tests') configure_file(output: t, input: '@0@.in'.format(t), @@ -44,4 +44,5 @@ if get_option('install-tests') install_subdir('simplify-data', install_dir: testexecdir) install_subdir('simplify-data-3to4', install_dir: testexecdir) + install_subdir('validate-data', install_dir: testexecdir) endif diff --git a/testsuite/tools/simplify-3to4.in b/testsuite/tools/simplify-3to4.in index 31d7da0970..35b8a8272f 100755 --- a/testsuite/tools/simplify-3to4.in +++ b/testsuite/tools/simplify-3to4.in @@ -7,13 +7,14 @@ TEST_RESULT_DIR=${TEST_RESULT_DIR:-/tmp} shopt -s nullglob TESTS=( "$TEST_DATA_DIR"/*.ui ) -echo "1..${#TESTS[*]}" +echo "1..$((2 * ${#TESTS[*]}))" I=1 for t in ${TESTS[*]}; do name=$(basename $t .ui) expected="$TEST_DATA_DIR/$name.expected" result="$TEST_RESULT_DIR/$name.out" + result2="$TEST_RESULT_DIR/$name.out2" diff="$TEST_RESULT_DIR/$name.diff" ref="$TEST_RESULT_DIR/$name.ref" @@ -28,4 +29,17 @@ for t in ${TESTS[*]}; do fi I=$((I+1)) + + cp $t $result2 + $GTK_BUILDER_TOOL simplify --3to4 --replace $result2 2>/dev/null + + if diff -u "$expected" "$result2" > "$diff"; then + echo "ok $I $name (--replace)" + rm "$diff" + else + echo "not ok $I $name (--replace)" + cp "$expected" "$ref" + fi + + I=$((I+1)) done diff --git a/testsuite/tools/simplify-data-3to4/actionbar.expected b/testsuite/tools/simplify-data-3to4/actionbar.expected new file mode 100644 index 0000000000..a063c7f2b6 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/actionbar.expected @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkActionBar"> + <property name="visible">0</property> + <child type="start"> + <object class="GtkButton" id="button"> + <property name="visible">0</property> + <property name="icon-name">document-new</property> + </object> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/actionbar.ui b/testsuite/tools/simplify-data-3to4/actionbar.ui new file mode 100644 index 0000000000..efae5962d9 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/actionbar.ui @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkActionBar"> + <child> + <object class="GtkButton" id="button"> + <property name="icon-name">document-new</property> + </object> + <packing> + <property name="pack-type">start</property> + </packing> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/fixed.expected b/testsuite/tools/simplify-data-3to4/fixed.expected new file mode 100644 index 0000000000..74953b12c6 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/fixed.expected @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkFixed"> + <child> + <object class="GtkButton" id="button"> + <layout> + <property name="transform">translate(10, 15)</property> + </layout> + <property name="visible">0</property> + </object> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/fixed.ui b/testsuite/tools/simplify-data-3to4/fixed.ui new file mode 100644 index 0000000000..699bea2e07 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/fixed.ui @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.2 --> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkFixed"> + <property name="visible">True</property> + <child> + <object class="GtkButton" id="button"> + </object> + <packing> + <property name="x">10</property> + <property name="y">15</property> + </packing> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/headerbar.expected b/testsuite/tools/simplify-data-3to4/headerbar.expected index aa7351fc06..5b642b28d8 100644 --- a/testsuite/tools/simplify-data-3to4/headerbar.expected +++ b/testsuite/tools/simplify-data-3to4/headerbar.expected @@ -4,6 +4,11 @@ <child type="titlebar"> <object class="GtkHeaderBar" id="headerbar1"> <property name="title-widget">box1</property> + <child type="end"> + <object class="GtkButton"> + <property name="label">A!</property> + </object> + </child> </object> </child> </object> diff --git a/testsuite/tools/simplify-data-3to4/headerbar.ui b/testsuite/tools/simplify-data-3to4/headerbar.ui index 9ad70329d7..c12d3d9ed1 100644 --- a/testsuite/tools/simplify-data-3to4/headerbar.ui +++ b/testsuite/tools/simplify-data-3to4/headerbar.ui @@ -7,6 +7,15 @@ <property name="visible">True</property> <property name="show-close-button">True</property> <property name="custom-title">box1</property> + <child> + <object class="GtkButton"> + <property name="visible">True</property> + <property name="label">A!</property> + </object> + <packing> + <property name="pack-type">end</property> + </packing> + </child> </object> </child> </object> diff --git a/testsuite/tools/simplify-data-3to4/overlay.expected b/testsuite/tools/simplify-data-3to4/overlay.expected new file mode 100644 index 0000000000..67e6ccade1 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/overlay.expected @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkOverlay"> + <child type="overlay"> + <object class="GtkButton" id="button"> + <property name="can-target">0</property> + <property name="icon-name">document-new</property> + </object> + </child> + <property name="child"> + <object class="GtkLabel" id="label"> + <property name="visible">0</property> + </object> + </property> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/overlay.ui b/testsuite/tools/simplify-data-3to4/overlay.ui new file mode 100644 index 0000000000..d83a16149f --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/overlay.ui @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkOverlay"> + <property name="visible">1</property> + <child type="overlay"> + <object class="GtkButton" id="button"> + <property name="visible">1</property> + <property name="icon-name">document-new</property> + </object> + <packing> + <property name="pass-through">True</property> + <property name="index">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label"/> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/paned.expected b/testsuite/tools/simplify-data-3to4/paned.expected new file mode 100644 index 0000000000..a1acaae442 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/paned.expected @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkPaned"> + <property name="resize-end-child">0</property> + <property name="shrink-start-child">0</property> + <child> + <object class="GtkButton" id="button"/> + </child> + <child> + <object class="GtkLabel" id="label"/> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/paned.ui b/testsuite/tools/simplify-data-3to4/paned.ui new file mode 100644 index 0000000000..13f736438a --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/paned.ui @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkPaned"> + <property name="visible">1</property> + <child> + <object class="GtkButton" id="button"> + <property name="visible">1</property> + </object> + <packing> + <property name="resize">True</property> + <property name="shrink">False</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label"> + <property name="visible">1</property> + </object> + <packing> + <property name="resize">0</property> + <property name="shrink">1</property> + </packing> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/test1.expected b/testsuite/tools/simplify-data-3to4/test1.expected deleted file mode 100644 index 0ddbcae8f5..0000000000 --- a/testsuite/tools/simplify-data-3to4/test1.expected +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<interface> - <object class="GtkWindow"> - <child> - <object class="GtkLabel"> - <property name="visible">0</property> - </object> - </child> - </object> -</interface> diff --git a/testsuite/tools/simplify-data-3to4/toolbar.expected b/testsuite/tools/simplify-data-3to4/toolbar.expected new file mode 100644 index 0000000000..fa090a9284 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/toolbar.expected @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkBox"> + <style> + <class name="toolbar"/> + </style> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">New</property> + <property name="icon-name">document-new</property> + <property name="tooltip-text" translatable="yes">Create a new document</property> + </object> + </child> + <child> + <object class="GtkSeparator"> + <property name="orientation">vertical</property> + </object> + </child> + <child> + <object class="GtkToggleButton"/> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify-data-3to4/toolbar.ui b/testsuite/tools/simplify-data-3to4/toolbar.ui new file mode 100644 index 0000000000..3f45466024 --- /dev/null +++ b/testsuite/tools/simplify-data-3to4/toolbar.ui @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkToolbar"> + <property name="visible">1</property> + <child> + <object class="GtkToolButton"> + <property name="visible">1</property> + <property name="label" translatable="yes">New</property> + <property name="icon-name">document-new</property> + <property name="tooltip-text" translatable="yes">Create a new document</property> + </object> + <packing> + <property name="homogeneous">1</property> + </packing> + </child> + <child> + <object class="GtkSeparatorToolItem"> + <property name="visible">1</property> + </object> + </child> + <child> + <object class="GtkToggleToolButton"> + </object> + </child> + </object> +</interface> diff --git a/testsuite/tools/simplify.in b/testsuite/tools/simplify.in index c92c5c6d9c..e90437337b 100755 --- a/testsuite/tools/simplify.in +++ b/testsuite/tools/simplify.in @@ -7,13 +7,14 @@ TEST_RESULT_DIR=${TEST_RESULT_DIR:-/tmp} shopt -s nullglob TESTS=( "$TEST_DATA_DIR"/*.ui ) -echo "1..${#TESTS[*]}" +echo "1..$((2 * ${#TESTS[*]}))" I=1 for t in ${TESTS[*]}; do name=$(basename $t .ui) expected="$TEST_DATA_DIR/$name.expected" result="$TEST_RESULT_DIR/$name.out" + result2="$TEST_RESULT_DIR/$name.out2" diff="$TEST_RESULT_DIR/$name.diff" ref="$TEST_RESULT_DIR/$name.ref" @@ -28,4 +29,17 @@ for t in ${TESTS[*]}; do fi I=$((I+1)) + + cp $t $result2 + $GTK_BUILDER_TOOL simplify --replace $result2 2>/dev/null + + if diff -u "$expected" "$result2" > "$diff"; then + echo "ok $I $name (--replace)" + rm "$diff" + else + echo "not ok $I $name (--replace)" + cp "$expected" "$ref" + fi + + I=$((I+1)) done diff --git a/testsuite/tools/validate-data/invalid1.expected b/testsuite/tools/validate-data/invalid1.expected new file mode 100644 index 0000000000..77c70ce0dc --- /dev/null +++ b/testsuite/tools/validate-data/invalid1.expected @@ -0,0 +1 @@ +invalid1.ui:3:1 <child> is not a valid tag here diff --git a/testsuite/tools/validate-data/invalid1.ui b/testsuite/tools/validate-data/invalid1.ui new file mode 100644 index 0000000000..0b969c34d8 --- /dev/null +++ b/testsuite/tools/validate-data/invalid1.ui @@ -0,0 +1,5 @@ +<interface> + <child> + <object class="GtkLabel"/> + </child> +</interface> diff --git a/testsuite/tools/validate-data/invalid2.expected b/testsuite/tools/validate-data/invalid2.expected new file mode 100644 index 0000000000..c05e26fece --- /dev/null +++ b/testsuite/tools/validate-data/invalid2.expected @@ -0,0 +1 @@ +invalid2.ui:4:1 <object> is not a valid tag here diff --git a/testsuite/tools/validate-data/invalid2.ui b/testsuite/tools/validate-data/invalid2.ui new file mode 100644 index 0000000000..887b3bcd4b --- /dev/null +++ b/testsuite/tools/validate-data/invalid2.ui @@ -0,0 +1,6 @@ +<interface> + <object class="GtkBox"> + <object class="GtkButton"> + </object> + </object> +</interface> diff --git a/testsuite/tools/validate-data/invalid3.expected b/testsuite/tools/validate-data/invalid3.expected new file mode 100644 index 0000000000..824ce933e6 --- /dev/null +++ b/testsuite/tools/validate-data/invalid3.expected @@ -0,0 +1 @@ +invalid3.ui:3:1 <object> requires attribute 'class' diff --git a/testsuite/tools/validate-data/invalid3.ui b/testsuite/tools/validate-data/invalid3.ui new file mode 100644 index 0000000000..9deb45b268 --- /dev/null +++ b/testsuite/tools/validate-data/invalid3.ui @@ -0,0 +1,4 @@ +<interface> + <object> + </object> +</interface> diff --git a/testsuite/tools/validate-data/invalid4.expected b/testsuite/tools/validate-data/invalid4.expected new file mode 100644 index 0000000000..7a565ffb3b --- /dev/null +++ b/testsuite/tools/validate-data/invalid4.expected @@ -0,0 +1 @@ +Gtk-WARNING: Failed to find accessible property “text”: Could not parse enum: 'text' diff --git a/testsuite/tools/validate-data/invalid4.ui b/testsuite/tools/validate-data/invalid4.ui new file mode 100644 index 0000000000..21e3248b73 --- /dev/null +++ b/testsuite/tools/validate-data/invalid4.ui @@ -0,0 +1,7 @@ +<interface> + <object class="GtkBox"> + <accessibility> + <property name="text">Download</property> + </accessibility> + </object> +</interface> diff --git a/testsuite/tools/validate-data/valid1.expected b/testsuite/tools/validate-data/valid1.expected new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tools/validate-data/valid1.expected diff --git a/testsuite/tools/validate-data/valid1.ui b/testsuite/tools/validate-data/valid1.ui new file mode 100644 index 0000000000..2a9a3f594c --- /dev/null +++ b/testsuite/tools/validate-data/valid1.ui @@ -0,0 +1,3 @@ +<interface> + <object class="GtkLabel"/> +</interface> diff --git a/testsuite/tools/validate-data/valid2.expected b/testsuite/tools/validate-data/valid2.expected new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tools/validate-data/valid2.expected diff --git a/testsuite/tools/validate-data/valid2.ui b/testsuite/tools/validate-data/valid2.ui new file mode 100644 index 0000000000..e0f4cf75df --- /dev/null +++ b/testsuite/tools/validate-data/valid2.ui @@ -0,0 +1,4 @@ +<interface> + <template class="GtkEmojiChooser" parent="GtkPopover"> + </template> +</interface> diff --git a/testsuite/tools/validate.in b/testsuite/tools/validate.in new file mode 100755 index 0000000000..82de80e31d --- /dev/null +++ b/testsuite/tools/validate.in @@ -0,0 +1,35 @@ +#! /bin/bash + +GTK_BUILDER_TOOL=${GTK_BUILDER_TOOL:-gtk4-builder-tool} +TEST_DATA_DIR=${G_TEST_SRCDIR:-.}/validate-data +TEST_RESULT_DIR=${TEST_RESULT_DIR:-/tmp} + +shopt -s nullglob +TESTS=( "$TEST_DATA_DIR"/*.ui ) + +echo "1..${#TESTS[*]}" + +I=1 +for t in ${TESTS[*]}; do + name=$(basename $t .ui) + expected="$TEST_DATA_DIR/$name.expected" + result="$TEST_RESULT_DIR/$name.out" + diff="$TEST_RESULT_DIR/$name.diff" + ref="$TEST_RESULT_DIR/$name.ref" + + cd $TEST_DATA_DIR + + $GTK_BUILDER_TOOL validate $(basename $t) 2>$result + + cd $OLDPWD + + if diff -u "$expected" "$result" > "$diff"; then + echo "ok $I $name" + rm "$diff" + else + echo "not ok $I $name" + cp "$expected" "$ref" + fi + + I=$((I+1)) +done |