Add GApplication local_command_line test
authorPaolo Borelli <pborelli@gnome.org>
Sat, 24 Nov 2012 18:12:13 +0000 (19:12 +0100)
committerPaolo Borelli <pborelli@gnome.org>
Sat, 24 Nov 2012 18:21:54 +0000 (19:21 +0100)
Assert that startup and shutdown are not called if we return TRUE from
local_command_line

gio/tests/gapplication.c

index 044bb37..6e247a8 100644 (file)
@@ -448,6 +448,61 @@ test_actions (void)
   g_object_unref (app);
 }
 
+typedef GApplication TestLocCmdApp;
+typedef GApplicationClass TestLocCmdAppClass;
+
+static GType test_loc_cmd_app_get_type (void);
+G_DEFINE_TYPE (TestLocCmdApp, test_loc_cmd_app, G_TYPE_APPLICATION)
+
+static void
+test_loc_cmd_app_init (TestLocCmdApp *app)
+{
+}
+
+static void
+test_loc_cmd_app_startup (GApplication *app)
+{
+  g_assert_not_reached ();
+}
+
+static void
+test_loc_cmd_app_shutdown (GApplication *app)
+{
+  g_assert_not_reached ();
+}
+
+static gboolean
+test_loc_cmd_app_local_command_line (GApplication   *application,
+                                     gchar        ***arguments,
+                                     gint           *exit_status)
+{
+  return TRUE;
+}
+
+static void
+test_loc_cmd_app_class_init (TestLocCmdAppClass *klass)
+{
+  G_APPLICATION_CLASS (klass)->startup = test_loc_cmd_app_startup;
+  G_APPLICATION_CLASS (klass)->shutdown = test_loc_cmd_app_shutdown;
+  G_APPLICATION_CLASS (klass)->local_command_line = test_loc_cmd_app_local_command_line;
+}
+
+static void
+test_local_command_line (void)
+{
+  gchar *argv[] = { "./unimportant", "-invalid", NULL };
+  GApplication *app;
+
+  g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
+
+  app = g_object_new (test_loc_cmd_app_get_type (),
+                      "application-id", "org.gtk.Unimportant",
+                      "flags", G_APPLICATION_FLAGS_NONE,
+                      NULL);
+  g_application_run (app, 1, argv);
+  g_object_unref (app);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -463,6 +518,7 @@ main (int argc, char **argv)
   g_test_add_func ("/gapplication/app-id", appid);
   g_test_add_func ("/gapplication/quit", test_quit);
   g_test_add_func ("/gapplication/actions", test_actions);
+  g_test_add_func ("/gapplication/local-command-line", test_local_command_line);
 
   return g_test_run ();
 }