Use CSIDL_LOCAL_APPDATA on Windows
[platform/upstream/glib.git] / gio / tests / testapp.c
index 8ed3091..413c1c6 100644 (file)
@@ -1,14 +1,18 @@
-#include <stdlib.h>
-#include <gio.h>
+#include <gio/gio.h>
 #include <gstdio.h>
 #include <string.h>
 
+#ifdef G_OS_UNIX
+#include <stdlib.h>
+#include <fcntl.h>
+#endif
+
 static gboolean action3_added = FALSE;
 
 static void
 on_app_action (GApplication *application,
                const gchar  *action_name,
-               guint         action_timestamp)
+               GVariant     *platform_data)
 {
   if (strcmp (action_name, "action1") == 0)
     exit (1);
@@ -22,53 +26,77 @@ on_app_action (GApplication *application,
     }
 }
 
-static gboolean
-invoke_action1 (gpointer data)
-{
-  GApplication *app = data;
-
-  g_application_invoke_action (app, "action1", 0);
-
-  return FALSE;
-}
-
 static void
 on_app_activated (GApplication  *application,
                  GVariant      *args,
                  GVariant      *platform_data)
 {
-  char *str;
+  GVariantIter iter;
+  const char *key;
+  GVariant *value;
+  char *cwd;
+
+  cwd = g_get_current_dir ();
+  g_variant_iter_init (&iter, platform_data);
+  while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
+    {
+      const char *activate_cwd;
 
-  g_print ("got args: ");
-  str = g_variant_print (args, TRUE);
-  g_print ("%s ", str);
-  g_free (str);
-  str = g_variant_print (platform_data, TRUE);
-  g_print ("%s\n", str);
-  g_free (str);
+      if (strcmp (key, "cwd") != 0)
+       continue;
+
+      activate_cwd = g_variant_get_bytestring (value);
+      g_assert_cmpstr (cwd, ==, activate_cwd);
+      g_variant_unref (value);
+    }
+
+  g_free (cwd);
+}
+
+static gboolean
+on_monitor_fd_io (GIOChannel *source,
+                 GIOCondition condition,
+                 gpointer data)
+{
+  exit (0);
+  return FALSE;
 }
 
 int
 main (int argc, char *argv[])
 {
   GApplication *app;
-  GMainLoop *loop;
 
-  app = g_application_new ("org.gtk.test.app");
+#ifdef G_OS_UNIX
+  {
+    const char *slave_fd_env = g_getenv ("_G_TEST_SLAVE_FD");
+    if (slave_fd_env)
+      {
+       int slave_fd = atoi (slave_fd_env);
+       fcntl (slave_fd, F_SETFD, FD_CLOEXEC);
+       g_io_add_watch (g_io_channel_unix_new (slave_fd), G_IO_HUP | G_IO_ERR,
+                       on_monitor_fd_io, NULL);
+      }
+  }
+#endif
+
+  app = g_application_unregistered_try_new ("org.gtk.test.app", 
+                                           argc, argv, NULL);
   if (!(argc > 1 && strcmp (argv[1], "--non-unique") == 0))
-    g_application_register_with_data (app, argc, argv, NULL);
+    {
+      if (!g_application_register (app))
+       exit (0);
+    }
 
   if (g_application_is_remote (app))
     {
-      g_timeout_add (1000, invoke_action1, app);
-      loop = g_main_loop_new (NULL, FALSE);
-      g_main_loop_run (loop);
+      g_application_invoke_action (app, "action1", 0);
     }
   else
     {
       g_application_add_action (app, "action1", "Action1");
       g_application_add_action (app, "action2", "Action2");
-      g_signal_connect (app, "action",
+      g_signal_connect (app, "action-with-data",
                         G_CALLBACK (on_app_action), NULL);
       g_signal_connect (app, "prepare-activation",
                         G_CALLBACK (on_app_activated), NULL);