[gtk: 14/40] icon-theme: Use gtk_icon_theme_choose_icon_async in tests



commit 0d666f0cec38b53f5c181b43c948892b906768f7
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Jan 28 14:38:53 2020 +0100

    icon-theme: Use gtk_icon_theme_choose_icon_async in tests

 tests/testicontheme.c     | 29 ++++++++-------------
 testsuite/gtk/icontheme.c | 64 +++++++++--------------------------------------
 2 files changed, 23 insertions(+), 70 deletions(-)
---
diff --git a/tests/testicontheme.c b/tests/testicontheme.c
index c6211be8e0..4624017883 100644
--- a/tests/testicontheme.c
+++ b/tests/testicontheme.c
@@ -29,6 +29,8 @@ usage (void)
           "usage: test-icon-theme list <theme name> [context]\n"
           " or\n"
           "usage: test-icon-theme display <theme name> <icon name> [size] [scale]\n"
+          " or\n"
+          "usage: test-icon-theme display-async <theme name> <icon name> [size] [scale]\n"
           );
 }
 
@@ -37,24 +39,23 @@ icon_loaded_cb (GObject *source_object,
                GAsyncResult *res,
                gpointer user_data)
 {
-  GdkPaintable *paintable;
+  GtkIconInfo *icon;
   GError *error;
 
   error = NULL;
-  paintable = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object),
-                                              res, &error);
+  icon = gtk_icon_theme_choose_icon_finish (GTK_ICON_THEME (source_object),
+                                           res, &error);
 
-  if (paintable == NULL)
+  if (icon == NULL)
     {
       g_print ("%s\n", error->message);
       exit (1);
     }
 
-  gtk_image_set_from_paintable (GTK_IMAGE (user_data), paintable);
-  g_object_unref (paintable);
+  gtk_image_set_from_paintable (GTK_IMAGE (user_data), GDK_PAINTABLE (icon));
+  g_object_unref (icon);
 }
 
-
 int
 main (int argc, char *argv[])
 {
@@ -126,7 +127,7 @@ main (int argc, char *argv[])
   else if (strcmp (argv[1], "display-async") == 0)
     {
       GtkWidget *window, *image;
-      GtkIconInfo *info;
+      const char *icons[2] = { NULL, NULL };
 
       if (argc < 4)
        {
@@ -147,16 +148,8 @@ main (int argc, char *argv[])
       g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
       gtk_widget_show (window);
 
-      info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, argv[3], size, scale, flags);
-
-      if (info == NULL)
-       {
-          g_print ("Icon not found\n");
-          return 1;
-       }
-
-      gtk_icon_info_load_icon_async (info,
-                                    NULL, icon_loaded_cb, image);
+      icons[0] = argv[3];
+      gtk_icon_theme_choose_icon_async (icon_theme, icons, size, scale, flags, NULL, icon_loaded_cb, image);
 
       gtk_main ();
     }
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index b23e5424b7..7999b64295 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -596,77 +596,37 @@ load_icon (GObject      *source,
            GAsyncResult *res,
            gpointer      data)
 {
-  GtkIconInfo *info = (GtkIconInfo *)source;
-  GError *error = NULL;
-  GdkPaintable *paintable;
-
-  paintable = gtk_icon_info_load_icon_finish (info, res, &error);
-  g_assert (paintable != NULL);
-  g_assert_no_error (error);
-  g_object_unref (paintable);
-
-  loaded++;
-}
-
-static void
-load_symbolic (GObject      *source,
-               GAsyncResult *res,
-               gpointer      data)
-{
-  GtkIconInfo *info = (GtkIconInfo *)source;
+  GMainLoop *loop = data;
+  GtkIconTheme *theme = GTK_ICON_THEME (source);
   GError *error = NULL;
-  gboolean symbolic;
-  GdkPaintable *paintable;
+  GtkIconInfo *icon;
 
-  paintable = gtk_icon_info_load_symbolic_finish (info, res, &symbolic, &error);
-  g_assert (paintable != NULL);
+  icon = gtk_icon_theme_choose_icon_finish (theme, res, &error);
+  g_assert (icon != NULL);
   g_assert_no_error (error);
-  g_object_unref (paintable);
+  g_object_unref (icon);
 
   loaded++;
-}
-
-static gboolean
-quit_loop (gpointer data)
-{
-  GMainLoop *loop = data;
-
   if (loaded == 2)
-    {
-      g_main_loop_quit (loop);
-      return G_SOURCE_REMOVE;
-    }
-  return G_SOURCE_CONTINUE;
+    g_main_loop_quit (loop);
 }
 
 static void
 test_async (void)
 {
-  GtkIconInfo *info1, *info2;
   GtkIconTheme *theme;
   GMainLoop *loop;
-  GdkRGBA fg, red, green, blue;
-
-  gdk_rgba_parse (&fg, "white");
-  gdk_rgba_parse (&red, "red");
-  gdk_rgba_parse (&green, "green");
-  gdk_rgba_parse (&blue, "blue");
+  const char *icons[] = { "twosize-fixed", NULL };
 
   loop = g_main_loop_new (NULL, FALSE);
-  g_idle_add_full (G_PRIORITY_LOW, quit_loop, loop, NULL);
 
+  g_printerr ("test_async\n");
   theme = get_test_icontheme (TRUE);
-  info1 = gtk_icon_theme_lookup_icon (theme, "twosize-fixed", 32, 0);
-  info2 = gtk_icon_theme_lookup_icon (theme, "only32-symbolic", 32, 0);
-  g_assert (info1);
-  g_assert (info2);
-  gtk_icon_info_load_icon_async (info1, NULL, load_icon, NULL);
-  gtk_icon_info_load_symbolic_async (info2, &fg, &red, &green, &blue, NULL, load_symbolic, NULL);
-  g_object_unref (info1);
-  g_object_unref (info2);
+  gtk_icon_theme_choose_icon_async (theme, icons, 32, 1, 0, NULL, load_icon, loop);
+  gtk_icon_theme_choose_icon_async (theme, icons, 48, 1, 0, NULL, load_icon, loop);
 
   g_main_loop_run (loop);
-  g_main_loop_unref (loop);  
+  g_main_loop_unref (loop);
 
   g_assert (loaded == 2);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]