apps test: add new "monitor" subcommand
[platform/upstream/glib.git] / gio / tests / apps.c
index 6597966..191edd4 100644 (file)
@@ -1,6 +1,7 @@
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
 #include <locale.h>
+#include <stdlib.h>
 
 static void
 print (const gchar *str)
@@ -20,6 +21,13 @@ print_app_list (GList *list)
     }
 }
 
+static void
+quit (gpointer user_data)
+{
+  g_print ("appinfo database changed.\n");
+  exit (0);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -51,6 +59,13 @@ main (int argc, char **argv)
         }
       g_free (results);
     }
+  else if (g_str_equal (argv[1], "implementations"))
+    {
+      GList *results;
+
+      results = g_desktop_app_info_get_implementations (argv[2]);
+      print_app_list (results);
+    }
   else if (g_str_equal (argv[1], "show-info"))
     {
       GAppInfo *info;
@@ -100,5 +115,33 @@ main (int argc, char **argv)
       print_app_list (list);
     }
 
+  else if (g_str_equal (argv[1], "should-show"))
+    {
+      GAppInfo *info;
+
+      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
+      if (info)
+        {
+          g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
+          g_object_unref (info);
+        }
+    }
+
+  else if (g_str_equal (argv[1], "monitor"))
+    {
+      GAppInfoMonitor *monitor;
+      GAppInfo *info;
+
+      monitor = g_app_info_monitor_get ();
+
+      info = (GAppInfo *) g_desktop_app_info_new ("this-desktop-file-does-not-exist");
+      g_assert (!info);
+
+      g_signal_connect (monitor, "changed", G_CALLBACK (quit), NULL);
+
+      while (1)
+        g_main_context_iteration (NULL, TRUE);
+    }
+
   return 0;
 }