From 0093b156d72cdf1ed4156c746236efb0de6d03df Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 10 Jun 2015 20:52:14 -0700 Subject: [PATCH] testsuite: add a test for non-square symbolic icons To verify the previous fix. https://bugzilla.gnome.org/show_bug.cgi?id=750605 --- testsuite/gtk/Makefile.am | 1 + .../gtk/icons/scalable/nonsquare-symbolic.svg | 12 ++++ testsuite/gtk/icontheme.c | 55 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 testsuite/gtk/icons/scalable/nonsquare-symbolic.svg diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am index ea828ce5ac..9a3809e4f4 100644 --- a/testsuite/gtk/Makefile.am +++ b/testsuite/gtk/Makefile.am @@ -153,6 +153,7 @@ test_icontheme = \ icons/scalable/everything-justsymbolic-symbolic.svg \ icons/scalable/everything.svg \ icons/scalable/everything-symbolic.svg \ + icons/scalable/nonsquare-symbolic.svg \ icons/15/size-test.png \ icons/16-22/size-test.png \ icons/25+/size-test.svg \ diff --git a/testsuite/gtk/icons/scalable/nonsquare-symbolic.svg b/testsuite/gtk/icons/scalable/nonsquare-symbolic.svg new file mode 100644 index 0000000000..2df92d0f20 --- /dev/null +++ b/testsuite/gtk/icons/scalable/nonsquare-symbolic.svg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c index de895c29d3..7fcb1609f1 100644 --- a/testsuite/gtk/icontheme.c +++ b/testsuite/gtk/icontheme.c @@ -698,6 +698,60 @@ test_inherit (void) "/icons2/scalable/one-two-symbolic-rtl.svg"); } +static void +test_nonsquare_symbolic (void) +{ + gint width, height; + GtkIconTheme *icon_theme; + GtkIconInfo *info; + GFile *file; + GIcon *icon; + GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; + gboolean was_symbolic = FALSE; + GError *error = NULL; + gchar *path = g_build_filename (g_test_get_dir (G_TEST_DIST), + "icons", + "scalable", + "nonsquare-symbolic.svg", + NULL); + + /* load the original image for reference */ + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (path, &error); + g_assert_no_error (error); + g_assert_nonnull (pixbuf); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + g_assert_cmpint (width, !=, height); + + /* now load it through GtkIconTheme */ + icon_theme = gtk_icon_theme_get_default (); + file = g_file_new_for_path (path); + icon = g_file_icon_new (file); + info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, icon, + height, 1, 0); + g_assert_nonnull (info); + + g_object_unref (pixbuf); + pixbuf = gtk_icon_info_load_symbolic (info, &black, NULL, NULL, NULL, + &was_symbolic, &error); + + /* we are loaded successfully */ + g_assert_no_error (error); + g_assert_nonnull (pixbuf); + g_assert_true (was_symbolic); + + /* the original dimensions have been preserved */ + g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, width); + g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, height); + + g_free (path); + g_object_unref (pixbuf); + g_object_unref (file); + g_object_unref (icon); + g_object_unref (info); +} + int main (int argc, char *argv[]) { @@ -716,6 +770,7 @@ main (int argc, char *argv[]) g_test_add_func ("/icontheme/list", test_list); g_test_add_func ("/icontheme/async", test_async); g_test_add_func ("/icontheme/inherit", test_inherit); + g_test_add_func ("/icontheme/nonsquare-symbolic", test_nonsquare_symbolic); return g_test_run(); }