widget-factory: Add a way to quit automatically
authorMatthias Clasen <mclasen@redhat.com>
Tue, 21 Jan 2020 21:57:20 +0000 (16:57 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 21 Jan 2020 22:31:48 +0000 (17:31 -0500)
This can be used to measure startup cost in tests.

demos/widget-factory/widget-factory.c

index 559fb82c87bf4c5acf913c8f32baad73ee501815..d50143deda2d433816bc946c4027ad9c0678dbd9 100644 (file)
@@ -2000,6 +2000,13 @@ toggle_action (GSimpleAction *action,
                              g_variant_new_boolean (!g_variant_get_boolean (state)));
 }
 
+static gboolean
+quit_timeout (gpointer data)
+{
+  exit (0);
+  return G_SOURCE_REMOVE;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -2065,6 +2072,9 @@ main (int argc, char *argv[])
 
   g_application_add_main_option (G_APPLICATION (app), "version", 0, 0, G_OPTION_ARG_NONE, "Show program version", NULL);
 
+  if (g_getenv ("GTK_DEBUG_AUTO_QUIT"))
+    g_timeout_add (500, quit_timeout, NULL);
+
   g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);
   status = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);