LCOV - code coverage report
Current view: top level - glib/gio/tests - gapplication.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 774 790 98.0 %
Date: 2024-04-23 05:16:05 Functions: 54 58 93.1 %
Branches: 44 46 95.7 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : #include <stdlib.h>
       3                 :            : #include <string.h>
       4                 :            : #include <unistd.h>
       5                 :            : 
       6                 :            : #include "gdbus-tests.h"
       7                 :            : #include "gdbus-sessionbus.h"
       8                 :            : 
       9                 :            : #if 0
      10                 :            : /* These tests are racy -- there is no guarantee about the order of data
      11                 :            :  * arriving over D-Bus.
      12                 :            :  *
      13                 :            :  * They're also a bit ridiculous -- GApplication was never meant to be
      14                 :            :  * abused in this way...
      15                 :            :  *
      16                 :            :  * We need new tests.
      17                 :            :  */
      18                 :            : static gint outstanding_watches;
      19                 :            : static GMainLoop *main_loop;
      20                 :            : 
      21                 :            : typedef struct
      22                 :            : {
      23                 :            :   gchar *expected_stdout;
      24                 :            :   gint stdout_pipe;
      25                 :            :   gchar *expected_stderr;
      26                 :            :   gint stderr_pipe;
      27                 :            : } ChildData;
      28                 :            : 
      29                 :            : static void
      30                 :            : check_data (gint fd, const gchar *expected)
      31                 :            : {
      32                 :            :   gssize len, actual;
      33                 :            :   gchar *buffer;
      34                 :            :   
      35                 :            :   len = strlen (expected);
      36                 :            :   buffer = g_alloca (len + 100);
      37                 :            :   actual = read (fd, buffer, len + 100);
      38                 :            : 
      39                 :            :   g_assert_cmpint (actual, >=, 0);
      40                 :            : 
      41                 :            :   if (actual != len ||
      42                 :            :       memcmp (buffer, expected, len) != 0)
      43                 :            :     {
      44                 :            :       buffer[MIN(len + 100, actual)] = '\0';
      45                 :            : 
      46                 :            :       g_error ("\nExpected\n-----\n%s-----\nGot (%s)\n-----\n%s-----\n",
      47                 :            :                expected,
      48                 :            :                (actual > len) ? "truncated" : "full", buffer);
      49                 :            :     }
      50                 :            : }
      51                 :            : 
      52                 :            : static void
      53                 :            : child_quit (GPid     pid,
      54                 :            :             gint     status,
      55                 :            :             gpointer data)
      56                 :            : {
      57                 :            :   ChildData *child = data;
      58                 :            : 
      59                 :            :   g_assert_cmpint (status, ==, 0);
      60                 :            : 
      61                 :            :   if (--outstanding_watches == 0)
      62                 :            :     g_main_loop_quit (main_loop);
      63                 :            : 
      64                 :            :   check_data (child->stdout_pipe, child->expected_stdout);
      65                 :            :   close (child->stdout_pipe);
      66                 :            :   g_free (child->expected_stdout);
      67                 :            : 
      68                 :            :   if (child->expected_stderr)
      69                 :            :     {
      70                 :            :       check_data (child->stderr_pipe, child->expected_stderr);
      71                 :            :       close (child->stderr_pipe);
      72                 :            :       g_free (child->expected_stderr);
      73                 :            :     }
      74                 :            : 
      75                 :            :   g_slice_free (ChildData, child);
      76                 :            : }
      77                 :            : 
      78                 :            : static void
      79                 :            : spawn (const gchar *expected_stdout,
      80                 :            :        const gchar *expected_stderr,
      81                 :            :        const gchar *first_arg,
      82                 :            :        ...)
      83                 :            : {
      84                 :            :   GError *error = NULL;
      85                 :            :   const gchar *arg;
      86                 :            :   GPtrArray *array;
      87                 :            :   ChildData *data;
      88                 :            :   gchar **args;
      89                 :            :   va_list ap;
      90                 :            :   GPid pid;
      91                 :            :   GPollFD fd;
      92                 :            :   gchar **env;
      93                 :            : 
      94                 :            :   va_start (ap, first_arg);
      95                 :            :   array = g_ptr_array_new ();
      96                 :            :   g_ptr_array_add (array, g_test_build_filename (G_TEST_BUILT, "basic-application", NULL));
      97                 :            :   for (arg = first_arg; arg; arg = va_arg (ap, const gchar *))
      98                 :            :     g_ptr_array_add (array, g_strdup (arg));
      99                 :            :   g_ptr_array_add (array, NULL);
     100                 :            :   args = (gchar **) g_ptr_array_free (array, FALSE);
     101                 :            :   va_end (ap);
     102                 :            : 
     103                 :            :   env = g_environ_setenv (g_get_environ (), "TEST", "1", TRUE);
     104                 :            : 
     105                 :            :   data = g_slice_new (ChildData);
     106                 :            :   data->expected_stdout = g_strdup (expected_stdout);
     107                 :            :   data->expected_stderr = g_strdup (expected_stderr);
     108                 :            : 
     109                 :            :   g_spawn_async_with_pipes (NULL, args, env,
     110                 :            :                             G_SPAWN_DO_NOT_REAP_CHILD,
     111                 :            :                             NULL, NULL, &pid, NULL,
     112                 :            :                             &data->stdout_pipe,
     113                 :            :                             expected_stderr ? &data->stderr_pipe : NULL,
     114                 :            :                             &error);
     115                 :            :   g_assert_no_error (error);
     116                 :            : 
     117                 :            :   g_strfreev (env);
     118                 :            : 
     119                 :            :   g_child_watch_add (pid, child_quit, data);
     120                 :            :   outstanding_watches++;
     121                 :            : 
     122                 :            :   /* we block until the children write to stdout to make sure
     123                 :            :    * they have started, as they need to be executed in order;
     124                 :            :    * see https://bugzilla.gnome.org/show_bug.cgi?id=664627
     125                 :            :    */
     126                 :            :   fd.fd = data->stdout_pipe;
     127                 :            :   fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
     128                 :            :   g_poll (&fd, 1, -1);
     129                 :            : }
     130                 :            : 
     131                 :            : static void
     132                 :            : basic (void)
     133                 :            : {
     134                 :            :   GDBusConnection *c;
     135                 :            : 
     136                 :            :   g_assert (outstanding_watches == 0);
     137                 :            : 
     138                 :            :   session_bus_up ();
     139                 :            :   c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
     140                 :            : 
     141                 :            :   main_loop = g_main_loop_new (NULL, 0);
     142                 :            : 
     143                 :            :   /* spawn the main instance */
     144                 :            :   spawn ("activated\n"
     145                 :            :          "open file:///a file:///b\n"
     146                 :            :          "exit status: 0\n", NULL,
     147                 :            :          "./app", NULL);
     148                 :            : 
     149                 :            :   /* send it some files */
     150                 :            :   spawn ("exit status: 0\n", NULL,
     151                 :            :          "./app", "/a", "/b", NULL);
     152                 :            : 
     153                 :            :   g_main_loop_run (main_loop);
     154                 :            : 
     155                 :            :   g_object_unref (c);
     156                 :            :   session_bus_down ();
     157                 :            : 
     158                 :            :   g_main_loop_unref (main_loop);
     159                 :            : }
     160                 :            : 
     161                 :            : static void
     162                 :            : test_remote_command_line (void)
     163                 :            : {
     164                 :            :   GDBusConnection *c;
     165                 :            :   GFile *file;
     166                 :            :   gchar *replies;
     167                 :            :   gchar *cwd;
     168                 :            : 
     169                 :            :   g_assert (outstanding_watches == 0);
     170                 :            : 
     171                 :            :   session_bus_up ();
     172                 :            :   c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
     173                 :            : 
     174                 :            :   main_loop = g_main_loop_new (NULL, 0);
     175                 :            : 
     176                 :            :   file = g_file_new_for_commandline_arg ("foo");
     177                 :            :   cwd = g_get_current_dir ();
     178                 :            : 
     179                 :            :   replies = g_strconcat ("got ./cmd 0\n",
     180                 :            :                          "got ./cmd 1\n",
     181                 :            :                          "cmdline ./cmd echo --abc -d\n",
     182                 :            :                          "environment TEST=1\n",
     183                 :            :                          "getenv TEST=1\n",
     184                 :            :                          "file ", g_file_get_path (file), "\n",
     185                 :            :                          "properties ok\n",
     186                 :            :                          "cwd ", cwd, "\n",
     187                 :            :                          "busy\n",
     188                 :            :                          "idle\n",
     189                 :            :                          "stdin ok\n",        
     190                 :            :                          "exit status: 0\n",
     191                 :            :                          NULL);
     192                 :            :   g_object_unref (file);
     193                 :            : 
     194                 :            :   /* spawn the main instance */
     195                 :            :   spawn (replies, NULL,
     196                 :            :          "./cmd", NULL);
     197                 :            : 
     198                 :            :   g_free (replies);
     199                 :            : 
     200                 :            :   /* send it a few commandlines */
     201                 :            :   spawn ("exit status: 0\n", NULL,
     202                 :            :          "./cmd", NULL);
     203                 :            : 
     204                 :            :   spawn ("exit status: 0\n", NULL,
     205                 :            :          "./cmd", "echo", "--abc", "-d", NULL);
     206                 :            : 
     207                 :            :   spawn ("exit status: 0\n", NULL,
     208                 :            :          "./cmd", "env", NULL);
     209                 :            : 
     210                 :            :   spawn ("exit status: 0\n", NULL,
     211                 :            :          "./cmd", "getenv", NULL);
     212                 :            : 
     213                 :            :   spawn ("print test\n"
     214                 :            :          "exit status: 0\n", NULL,
     215                 :            :          "./cmd", "print", "test", NULL);
     216                 :            : 
     217                 :            :   spawn ("exit status: 0\n", "printerr test\n",
     218                 :            :          "./cmd", "printerr", "test", NULL);
     219                 :            : 
     220                 :            :   spawn ("exit status: 0\n", NULL,
     221                 :            :          "./cmd", "file", "foo", NULL);
     222                 :            : 
     223                 :            :   spawn ("exit status: 0\n", NULL,
     224                 :            :          "./cmd", "properties", NULL);
     225                 :            : 
     226                 :            :   spawn ("exit status: 0\n", NULL,
     227                 :            :          "./cmd", "cwd", NULL);
     228                 :            : 
     229                 :            :   spawn ("exit status: 0\n", NULL,
     230                 :            :          "./cmd", "busy", NULL);
     231                 :            : 
     232                 :            :   spawn ("exit status: 0\n", NULL,
     233                 :            :          "./cmd", "idle", NULL);
     234                 :            : 
     235                 :            :   spawn ("exit status: 0\n", NULL,
     236                 :            :          "./cmd", "stdin", NULL);
     237                 :            : 
     238                 :            :   g_main_loop_run (main_loop);
     239                 :            : 
     240                 :            :   g_object_unref (c);
     241                 :            :   session_bus_down ();
     242                 :            : 
     243                 :            :   g_main_loop_unref (main_loop);
     244                 :            : }
     245                 :            : 
     246                 :            : static void
     247                 :            : test_remote_actions (void)
     248                 :            : {
     249                 :            :   GDBusConnection *c;
     250                 :            : 
     251                 :            :   g_assert (outstanding_watches == 0);
     252                 :            : 
     253                 :            :   session_bus_up ();
     254                 :            :   c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
     255                 :            : 
     256                 :            :   main_loop = g_main_loop_new (NULL, 0);
     257                 :            : 
     258                 :            :   /* spawn the main instance */
     259                 :            :   spawn ("got ./cmd 0\n"
     260                 :            :          "activate action1\n"
     261                 :            :          "change action2 1\n"
     262                 :            :          "exit status: 0\n", NULL,
     263                 :            :          "./cmd", NULL);
     264                 :            : 
     265                 :            :   spawn ("actions quit new action1 action2\n"
     266                 :            :          "exit status: 0\n", NULL,
     267                 :            :          "./actions", "list", NULL);
     268                 :            : 
     269                 :            :   spawn ("exit status: 0\n", NULL,
     270                 :            :          "./actions", "activate", NULL);
     271                 :            : 
     272                 :            :   spawn ("exit status: 0\n", NULL,
     273                 :            :          "./actions", "set-state", NULL);
     274                 :            : 
     275                 :            :   g_main_loop_run (main_loop);
     276                 :            : 
     277                 :            :   g_object_unref (c);
     278                 :            :   session_bus_down ();
     279                 :            : 
     280                 :            :   g_main_loop_unref (main_loop);
     281                 :            : }
     282                 :            : #endif
     283                 :            : 
     284                 :            : #if 0
     285                 :            : /* Now that we register non-unique apps on the bus we need to fix the
     286                 :            :  * following test not to assume that it's safe to create multiple instances
     287                 :            :  * of the same app in one process.
     288                 :            :  *
     289                 :            :  * See https://bugzilla.gnome.org/show_bug.cgi?id=647986 for the patch that
     290                 :            :  * introduced this problem.
     291                 :            :  */
     292                 :            : 
     293                 :            : static GApplication *recently_activated;
     294                 :            : static GMainLoop *loop;
     295                 :            : 
     296                 :            : static void
     297                 :            : nonunique_activate (GApplication *application)
     298                 :            : {
     299                 :            :   recently_activated = application;
     300                 :            : 
     301                 :            :   if (loop != NULL)
     302                 :            :     g_main_loop_quit (loop);
     303                 :            : }
     304                 :            : 
     305                 :            : static GApplication *
     306                 :            : make_app (gboolean non_unique)
     307                 :            : {
     308                 :            :   GApplication *app;
     309                 :            :   gboolean ok;
     310                 :            : 
     311                 :            :   app = g_application_new ("org.gtk.Test-Application",
     312                 :            :                            non_unique ? G_APPLICATION_NON_UNIQUE : 0);
     313                 :            :   g_signal_connect (app, "activate", G_CALLBACK (nonunique_activate), NULL);
     314                 :            :   ok = g_application_register (app, NULL, NULL);
     315                 :            :   if (!ok)
     316                 :            :     {
     317                 :            :       g_object_unref (app);
     318                 :            :       return NULL;
     319                 :            :     }
     320                 :            : 
     321                 :            :   g_application_activate (app);
     322                 :            : 
     323                 :            :   return app;
     324                 :            : }
     325                 :            : 
     326                 :            : static void
     327                 :            : test_nonunique (void)
     328                 :            : {
     329                 :            :   GApplication *first, *second, *third, *fourth;
     330                 :            : 
     331                 :            :   session_bus_up ();
     332                 :            : 
     333                 :            :   first = make_app (TRUE);
     334                 :            :   /* non-remote because it is non-unique */
     335                 :            :   g_assert (!g_application_get_is_remote (first));
     336                 :            :   g_assert (recently_activated == first);
     337                 :            :   recently_activated = NULL;
     338                 :            : 
     339                 :            :   second = make_app (FALSE);
     340                 :            :   /* non-remote because it is first */
     341                 :            :   g_assert (!g_application_get_is_remote (second));
     342                 :            :   g_assert (recently_activated == second);
     343                 :            :   recently_activated = NULL;
     344                 :            : 
     345                 :            :   third = make_app (TRUE);
     346                 :            :   /* non-remote because it is non-unique */
     347                 :            :   g_assert (!g_application_get_is_remote (third));
     348                 :            :   g_assert (recently_activated == third);
     349                 :            :   recently_activated = NULL;
     350                 :            : 
     351                 :            :   fourth = make_app (FALSE);
     352                 :            :   /* should have failed to register due to being
     353                 :            :    * unable to register the object paths
     354                 :            :    */
     355                 :            :   g_assert (fourth == NULL);
     356                 :            :   g_assert (recently_activated == NULL);
     357                 :            : 
     358                 :            :   g_object_unref (first);
     359                 :            :   g_object_unref (second);
     360                 :            :   g_object_unref (third);
     361                 :            : 
     362                 :            :   session_bus_down ();
     363                 :            : }
     364                 :            : #endif
     365                 :            : 
     366                 :            : static void
     367                 :          1 : properties (void)
     368                 :            : {
     369                 :            :   GDBusConnection *c;
     370                 :            :   GObject *app;
     371                 :            :   gchar *id;
     372                 :            :   gchar *version;
     373                 :            :   GApplicationFlags flags;
     374                 :            :   gboolean registered;
     375                 :            :   guint timeout;
     376                 :            :   gboolean remote;
     377                 :            :   gboolean ret;
     378                 :          1 :   GError *error = NULL;
     379                 :            : 
     380                 :          1 :   session_bus_up ();
     381                 :          1 :   c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
     382                 :            : 
     383                 :          1 :   app = g_object_new (G_TYPE_APPLICATION,
     384                 :            :                       "application-id", "org.gtk.TestApplication",
     385                 :            :                       "version", "1.0",
     386                 :            :                       NULL);
     387                 :            : 
     388                 :          1 :   g_object_get (app,
     389                 :            :                 "application-id", &id,
     390                 :            :                 "version", &version,
     391                 :            :                 "flags", &flags,
     392                 :            :                 "is-registered", &registered,
     393                 :            :                 "inactivity-timeout", &timeout,
     394                 :            :                 NULL);
     395                 :            : 
     396                 :          1 :   g_assert_cmpstr (id, ==, "org.gtk.TestApplication");
     397                 :          1 :   g_assert_cmpstr (version, ==, "1.0");
     398                 :          1 :   g_assert_cmpint (flags, ==, G_APPLICATION_DEFAULT_FLAGS);
     399                 :          1 :   g_assert (!registered);
     400                 :          1 :   g_assert_cmpint (timeout, ==, 0);
     401                 :            : 
     402                 :          1 :   g_clear_pointer (&version, g_free);
     403                 :            : 
     404                 :          1 :   ret = g_application_register (G_APPLICATION (app), NULL, &error);
     405                 :          1 :   g_assert (ret);
     406                 :          1 :   g_assert_no_error (error);
     407                 :            : 
     408                 :          1 :   g_object_get (app,
     409                 :            :                 "is-registered", &registered,
     410                 :            :                 "is-remote", &remote,
     411                 :            :                 NULL);
     412                 :            : 
     413                 :          1 :   g_assert (registered);
     414                 :          1 :   g_assert (!remote);
     415                 :            : 
     416                 :          1 :   g_object_set (app,
     417                 :            :                 "inactivity-timeout", 1000,
     418                 :            :                 NULL);
     419                 :            : 
     420                 :          1 :   g_application_quit (G_APPLICATION (app));
     421                 :            : 
     422                 :          1 :   g_object_unref (c);
     423                 :          1 :   g_object_unref (app);
     424                 :          1 :   g_free (id);
     425                 :            : 
     426                 :          1 :   session_bus_down ();
     427                 :          1 : }
     428                 :            : 
     429                 :            : static void
     430                 :          1 : appid (void)
     431                 :            : {
     432                 :            :   gchar *id;
     433                 :            : 
     434                 :          1 :   g_assert_false (g_application_id_is_valid (""));
     435                 :          1 :   g_assert_false (g_application_id_is_valid ("."));
     436                 :          1 :   g_assert_false (g_application_id_is_valid ("a"));
     437                 :          1 :   g_assert_false (g_application_id_is_valid ("abc"));
     438                 :          1 :   g_assert_false (g_application_id_is_valid (".abc"));
     439                 :          1 :   g_assert_false (g_application_id_is_valid ("abc."));
     440                 :          1 :   g_assert_false (g_application_id_is_valid ("a..b"));
     441                 :          1 :   g_assert_false (g_application_id_is_valid ("a/b"));
     442                 :          1 :   g_assert_false (g_application_id_is_valid ("a\nb"));
     443                 :          1 :   g_assert_false (g_application_id_is_valid ("a\nb"));
     444                 :          1 :   g_assert_false (g_application_id_is_valid ("emoji_picker"));
     445                 :          1 :   g_assert_false (g_application_id_is_valid ("emoji-picker"));
     446                 :          1 :   g_assert_false (g_application_id_is_valid ("emojipicker"));
     447                 :          1 :   g_assert_false (g_application_id_is_valid ("my.Terminal.0123"));
     448                 :          1 :   id = g_new0 (gchar, 261);
     449                 :          1 :   memset (id, 'a', 260);
     450                 :          1 :   id[1] = '.';
     451                 :          1 :   id[260] = 0;
     452                 :          1 :   g_assert_false (g_application_id_is_valid (id));
     453                 :          1 :   g_free (id);
     454                 :            : 
     455                 :          1 :   g_assert_true (g_application_id_is_valid ("a.b"));
     456                 :          1 :   g_assert_true (g_application_id_is_valid ("A.B"));
     457                 :          1 :   g_assert_true (g_application_id_is_valid ("A-.B"));
     458                 :          1 :   g_assert_true (g_application_id_is_valid ("a_b.c-d"));
     459                 :          1 :   g_assert_true (g_application_id_is_valid ("_a.b"));
     460                 :          1 :   g_assert_true (g_application_id_is_valid ("-a.b"));
     461                 :          1 :   g_assert_true (g_application_id_is_valid ("org.gnome.SessionManager"));
     462                 :          1 :   g_assert_true (g_application_id_is_valid ("my.Terminal._0123"));
     463                 :          1 :   g_assert_true (g_application_id_is_valid ("com.example.MyApp"));
     464                 :          1 :   g_assert_true (g_application_id_is_valid ("com.example.internal_apps.Calculator"));
     465                 :          1 :   g_assert_true (g_application_id_is_valid ("org._7_zip.Archiver"));
     466                 :          1 : }
     467                 :            : 
     468                 :            : static gboolean nodbus_activated;
     469                 :            : 
     470                 :            : static gboolean
     471                 :          3 : release_app (gpointer user_data)
     472                 :            : {
     473                 :          3 :   g_application_release (user_data);
     474                 :          3 :   return G_SOURCE_REMOVE;
     475                 :            : }
     476                 :            : 
     477                 :            : static void
     478                 :          1 : nodbus_activate (GApplication *app)
     479                 :            : {
     480                 :          1 :   nodbus_activated = TRUE;
     481                 :          1 :   g_application_hold (app);
     482                 :            : 
     483                 :          1 :   g_assert (g_application_get_dbus_connection (app) == NULL);
     484                 :          1 :   g_assert (g_application_get_dbus_object_path (app) == NULL);
     485                 :            : 
     486                 :          1 :   g_idle_add (release_app, app);
     487                 :          1 : }
     488                 :            : 
     489                 :            : static void
     490                 :          1 : test_nodbus (void)
     491                 :            : {
     492                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     493                 :          1 :   gchar *argv[] = { binpath, NULL };
     494                 :            :   GApplication *app;
     495                 :            : 
     496                 :          1 :   app = g_application_new ("org.gtk.Unimportant", G_APPLICATION_DEFAULT_FLAGS);
     497                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (nodbus_activate), NULL);
     498                 :          1 :   g_application_run (app, 1, argv);
     499                 :          1 :   g_object_unref (app);
     500                 :            : 
     501                 :          1 :   g_assert (nodbus_activated);
     502                 :          1 :   g_free (binpath);
     503                 :          1 : }
     504                 :            : 
     505                 :            : static gboolean noappid_activated;
     506                 :            : 
     507                 :            : static void
     508                 :          2 : noappid_activate (GApplication *app)
     509                 :            : {
     510                 :          2 :   noappid_activated = TRUE;
     511                 :          2 :   g_application_hold (app);
     512                 :            : 
     513                 :          2 :   g_assert (g_application_get_flags (app) & G_APPLICATION_NON_UNIQUE);
     514                 :            : 
     515                 :          2 :   g_idle_add (release_app, app);
     516                 :          2 : }
     517                 :            : 
     518                 :            : /* test that no appid -> non-unique */
     519                 :            : static void
     520                 :          1 : test_noappid (void)
     521                 :            : {
     522                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     523                 :          1 :   gchar *argv[] = { binpath, NULL };
     524                 :            :   GApplication *app;
     525                 :            : 
     526                 :          1 :   app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
     527                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
     528                 :          1 :   g_application_run (app, 1, argv);
     529                 :          1 :   g_object_unref (app);
     530                 :            : 
     531                 :          1 :   g_assert (noappid_activated);
     532                 :          1 :   g_free (binpath);
     533                 :          1 : }
     534                 :            : 
     535                 :            : static gboolean activated;
     536                 :            : static gboolean quitted;
     537                 :            : 
     538                 :            : static gboolean
     539                 :          1 : quit_app (gpointer user_data)
     540                 :            : {
     541                 :          1 :   quitted = TRUE;
     542                 :          1 :   g_application_quit (user_data);
     543                 :          1 :   return G_SOURCE_REMOVE;
     544                 :            : }
     545                 :            : 
     546                 :            : static void
     547                 :          1 : quit_activate (GApplication *app)
     548                 :            : {
     549                 :          1 :   activated = TRUE;
     550                 :          1 :   g_application_hold (app);
     551                 :            : 
     552                 :          1 :   g_assert (g_application_get_dbus_connection (app) != NULL);
     553                 :          1 :   g_assert (g_application_get_dbus_object_path (app) != NULL);
     554                 :            : 
     555                 :          1 :   g_idle_add (quit_app, app);
     556                 :          1 : }
     557                 :            : 
     558                 :            : static void
     559                 :          1 : test_quit (void)
     560                 :            : {
     561                 :            :   GDBusConnection *c;
     562                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     563                 :          1 :   gchar *argv[] = { binpath, NULL };
     564                 :            :   GApplication *app;
     565                 :            : 
     566                 :          1 :   session_bus_up ();
     567                 :          1 :   c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
     568                 :            : 
     569                 :          1 :   app = g_application_new ("org.gtk.Unimportant",
     570                 :            :                            G_APPLICATION_DEFAULT_FLAGS);
     571                 :          1 :   activated = FALSE;
     572                 :          1 :   quitted = FALSE;
     573                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (quit_activate), NULL);
     574                 :          1 :   g_application_run (app, 1, argv);
     575                 :          1 :   g_object_unref (app);
     576                 :          1 :   g_object_unref (c);
     577                 :            : 
     578                 :          1 :   g_assert (activated);
     579                 :          1 :   g_assert (quitted);
     580                 :            : 
     581                 :          1 :   session_bus_down ();
     582                 :          1 :   g_free (binpath);
     583                 :          1 : }
     584                 :            : 
     585                 :            : typedef struct
     586                 :            : {
     587                 :            :   gboolean shutdown;
     588                 :            :   GParamSpec *notify_spec; /* (owned) (nullable) */
     589                 :            : } RegisteredData;
     590                 :            : 
     591                 :            : static void
     592                 :          1 : on_registered_shutdown (GApplication *app,
     593                 :            :                         gpointer user_data)
     594                 :            : {
     595                 :          1 :   RegisteredData *registered_data = user_data;
     596                 :            : 
     597                 :          1 :   registered_data->shutdown = TRUE;
     598                 :          1 : }
     599                 :            : 
     600                 :            : static void
     601                 :          3 : on_registered_notify (GApplication *app,
     602                 :            :                       GParamSpec *spec,
     603                 :            :                       gpointer user_data)
     604                 :            : {
     605                 :          3 :   RegisteredData *registered_data = user_data;
     606                 :          3 :   registered_data->notify_spec = g_param_spec_ref (spec);
     607                 :            : 
     608         [ +  + ]:          3 :   if (g_application_get_is_registered (app))
     609                 :          2 :     g_assert_false (registered_data->shutdown);
     610                 :            :   else
     611                 :          1 :     g_assert_true (registered_data->shutdown);
     612                 :          3 : }
     613                 :            : 
     614                 :            : static void
     615                 :          1 : test_registered (void)
     616                 :            : {
     617                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     618                 :          1 :   gchar *argv[] = { binpath, NULL };
     619                 :          1 :   RegisteredData registered_data = { FALSE, NULL };
     620                 :            :   GApplication *app;
     621                 :            : 
     622                 :          1 :   app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
     623                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
     624                 :          1 :   g_signal_connect (app, "shutdown", G_CALLBACK (on_registered_shutdown), &registered_data);
     625                 :          1 :   g_signal_connect (app, "notify::is-registered", G_CALLBACK (on_registered_notify), &registered_data);
     626                 :            : 
     627                 :          1 :   g_assert_null (registered_data.notify_spec);
     628                 :            : 
     629                 :          1 :   g_assert_true (g_application_register (app, NULL, NULL));
     630                 :          1 :   g_assert_true (g_application_get_is_registered (app));
     631                 :            : 
     632                 :          1 :   g_assert_nonnull (registered_data.notify_spec);
     633                 :          1 :   g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
     634                 :          1 :   g_clear_pointer (&registered_data.notify_spec, g_param_spec_unref);
     635                 :            : 
     636                 :          1 :   g_assert_false (registered_data.shutdown);
     637                 :            : 
     638                 :          1 :   g_application_run (app, 1, argv);
     639                 :            : 
     640                 :          1 :   g_assert_true (registered_data.shutdown);
     641                 :          1 :   g_assert_false (g_application_get_is_registered (app));
     642                 :          1 :   g_assert_nonnull (registered_data.notify_spec);
     643                 :          1 :   g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
     644                 :          1 :   g_clear_pointer (&registered_data.notify_spec, g_param_spec_unref);
     645                 :            : 
     646                 :            :   /* Register it again */
     647                 :          1 :   registered_data.shutdown = FALSE;
     648                 :          1 :   g_assert_true (g_application_register (app, NULL, NULL));
     649                 :          1 :   g_assert_true (g_application_get_is_registered (app));
     650                 :          1 :   g_assert_nonnull (registered_data.notify_spec);
     651                 :          1 :   g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
     652                 :          1 :   g_clear_pointer (&registered_data.notify_spec, g_param_spec_unref);
     653                 :          1 :   g_assert_false (registered_data.shutdown);
     654                 :            : 
     655                 :          1 :   g_object_unref (app);
     656                 :            : 
     657                 :          1 :   g_free (binpath);
     658                 :          1 : }
     659                 :            : 
     660                 :            : static void
     661                 :          1 : on_activate (GApplication *app)
     662                 :            : {
     663                 :            :   gchar **actions;
     664                 :            :   GAction *action;
     665                 :            :   GVariant *state;
     666                 :            : 
     667                 :          1 :   g_assert (!g_application_get_is_remote (app));
     668                 :            : 
     669                 :          1 :   actions = g_action_group_list_actions (G_ACTION_GROUP (app));
     670                 :          1 :   g_assert (g_strv_length (actions) == 0);
     671                 :          1 :   g_strfreev (actions);
     672                 :            : 
     673                 :          1 :   action = (GAction*)g_simple_action_new_stateful ("test", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean (FALSE));
     674                 :          1 :   g_action_map_add_action (G_ACTION_MAP (app), action);
     675                 :            : 
     676                 :          1 :   actions = g_action_group_list_actions (G_ACTION_GROUP (app));
     677                 :          1 :   g_assert (g_strv_length (actions) == 1);
     678                 :          1 :   g_strfreev (actions);
     679                 :            : 
     680                 :          1 :   g_action_group_change_action_state (G_ACTION_GROUP (app), "test", g_variant_new_boolean (TRUE));
     681                 :          1 :   state = g_action_group_get_action_state (G_ACTION_GROUP (app), "test");
     682                 :          1 :   g_assert (g_variant_get_boolean (state) == TRUE);
     683                 :            : 
     684                 :          1 :   action = g_action_map_lookup_action (G_ACTION_MAP (app), "test");
     685                 :          1 :   g_assert (action != NULL);
     686                 :            : 
     687                 :          1 :   g_action_map_remove_action (G_ACTION_MAP (app), "test");
     688                 :            : 
     689                 :          1 :   actions = g_action_group_list_actions (G_ACTION_GROUP (app));
     690                 :          1 :   g_assert (g_strv_length (actions) == 0);
     691                 :          1 :   g_strfreev (actions);
     692                 :          1 : }
     693                 :            : 
     694                 :            : static void
     695                 :          1 : test_local_actions (void)
     696                 :            : {
     697                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     698                 :          1 :   gchar *argv[] = { binpath, NULL };
     699                 :            :   GApplication *app;
     700                 :            : 
     701                 :          1 :   app = g_application_new ("org.gtk.Unimportant",
     702                 :            :                            G_APPLICATION_DEFAULT_FLAGS);
     703                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
     704                 :          1 :   g_application_run (app, 1, argv);
     705                 :          1 :   g_object_unref (app);
     706                 :          1 :   g_free (binpath);
     707                 :          1 : }
     708                 :            : 
     709                 :            : typedef GApplication TestLocCmdApp;
     710                 :            : typedef GApplicationClass TestLocCmdAppClass;
     711                 :            : 
     712                 :            : static GType test_loc_cmd_app_get_type (void);
     713   [ +  +  +  -  :          3 : G_DEFINE_TYPE (TestLocCmdApp, test_loc_cmd_app, G_TYPE_APPLICATION)
                   +  - ]
     714                 :            : 
     715                 :            : static void
     716                 :          1 : test_loc_cmd_app_init (TestLocCmdApp *app)
     717                 :            : {
     718                 :          1 : }
     719                 :            : 
     720                 :            : static void
     721                 :          0 : test_loc_cmd_app_startup (GApplication *app)
     722                 :            : {
     723                 :            :   g_assert_not_reached ();
     724                 :            : }
     725                 :            : 
     726                 :            : static void
     727                 :          0 : test_loc_cmd_app_shutdown (GApplication *app)
     728                 :            : {
     729                 :            :   g_assert_not_reached ();
     730                 :            : }
     731                 :            : 
     732                 :            : static gboolean
     733                 :          1 : test_loc_cmd_app_local_command_line (GApplication   *application,
     734                 :            :                                      gchar        ***arguments,
     735                 :            :                                      gint           *exit_status)
     736                 :            : {
     737                 :          1 :   return TRUE;
     738                 :            : }
     739                 :            : 
     740                 :            : static void
     741                 :          1 : test_loc_cmd_app_class_init (TestLocCmdAppClass *klass)
     742                 :            : {
     743                 :          1 :   G_APPLICATION_CLASS (klass)->startup = test_loc_cmd_app_startup;
     744                 :          1 :   G_APPLICATION_CLASS (klass)->shutdown = test_loc_cmd_app_shutdown;
     745                 :          1 :   G_APPLICATION_CLASS (klass)->local_command_line = test_loc_cmd_app_local_command_line;
     746                 :          1 : }
     747                 :            : 
     748                 :            : static void
     749                 :          1 : test_local_command_line (void)
     750                 :            : {
     751                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     752                 :          1 :   gchar *argv[] = { binpath, "-invalid", NULL };
     753                 :            :   GApplication *app;
     754                 :            : 
     755                 :          1 :   app = g_object_new (test_loc_cmd_app_get_type (),
     756                 :            :                       "application-id", "org.gtk.Unimportant",
     757                 :            :                       "flags", G_APPLICATION_DEFAULT_FLAGS,
     758                 :            :                       NULL);
     759                 :          1 :   g_application_run (app, 1, argv);
     760                 :          1 :   g_object_unref (app);
     761                 :          1 :   g_free (binpath);
     762                 :          1 : }
     763                 :            : 
     764                 :            : static void
     765                 :          1 : test_resource_path (void)
     766                 :            : {
     767                 :            :   GApplication *app;
     768                 :            : 
     769                 :          1 :   app = g_application_new ("x.y.z", 0);
     770                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x/y/z");
     771                 :            : 
     772                 :            :   /* this should not change anything */
     773                 :          1 :   g_application_set_application_id (app, "a.b.c");
     774                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x/y/z");
     775                 :            : 
     776                 :            :   /* but this should... */
     777                 :          1 :   g_application_set_resource_base_path (app, "/x");
     778                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x");
     779                 :            : 
     780                 :            :   /* ... and this */
     781                 :          1 :   g_application_set_resource_base_path (app, NULL);
     782                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, NULL);
     783                 :            : 
     784                 :          1 :   g_object_unref (app);
     785                 :            : 
     786                 :            :   /* Make sure that overriding at construction time works properly */
     787                 :          1 :   app = g_object_new (G_TYPE_APPLICATION, "application-id", "x.y.z", "resource-base-path", "/a", NULL);
     788                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/a");
     789                 :          1 :   g_object_unref (app);
     790                 :            : 
     791                 :            :   /* ... particularly if we override to NULL */
     792                 :          1 :   app = g_object_new (G_TYPE_APPLICATION, "application-id", "x.y.z", "resource-base-path", NULL, NULL);
     793                 :          1 :   g_assert_cmpstr (g_application_get_resource_base_path (app), ==, NULL);
     794                 :          1 :   g_object_unref (app);
     795                 :          1 : }
     796                 :            : 
     797                 :            : static gint
     798                 :          0 : test_help_command_line (GApplication            *app,
     799                 :            :                         GApplicationCommandLine *command_line,
     800                 :            :                         gpointer                 user_data)
     801                 :            : {
     802                 :          0 :   gboolean *called = user_data;
     803                 :            : 
     804                 :          0 :   *called = TRUE;
     805                 :            : 
     806                 :          0 :   return 0;
     807                 :            : }
     808                 :            : 
     809                 :            : /* Test whether --help is handled when HANDLES_COMMND_LINE is set and
     810                 :            :  * options have been added.
     811                 :            :  */
     812                 :            : static void
     813                 :          2 : test_help (void)
     814                 :            : {
     815         [ +  + ]:          2 :   if (g_test_subprocess ())
     816                 :            :     {
     817                 :          1 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     818                 :          1 :       gchar *argv[] = { binpath, "--help", NULL };
     819                 :            :       GApplication *app;
     820                 :          1 :       gboolean called = FALSE;
     821                 :            :       int status;
     822                 :            : 
     823                 :          1 :       app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE);
     824                 :          1 :       g_application_add_main_option (app, "foo", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
     825                 :          1 :       g_signal_connect (app, "command-line", G_CALLBACK (test_help_command_line), &called);
     826                 :            : 
     827                 :          1 :       status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
     828                 :          0 :       g_assert (called == TRUE);
     829                 :          0 :       g_assert_cmpint (status, ==, 0);
     830                 :            : 
     831                 :          0 :       g_object_unref (app);
     832                 :          0 :       g_free (binpath);
     833                 :          0 :       return;
     834                 :            :     }
     835                 :            : 
     836                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     837                 :          1 :   g_test_trap_assert_passed ();
     838                 :          1 :   g_test_trap_assert_stdout ("*Application options*");
     839                 :            : }
     840                 :            : 
     841                 :            : static gint
     842                 :          1 : command_line_done_callback (GApplication            *app,
     843                 :            :                             GApplicationCommandLine *command_line,
     844                 :            :                             gpointer                 user_data)
     845                 :            : {
     846                 :          1 :   gboolean *called = user_data;
     847                 :            : 
     848                 :          1 :   *called = TRUE;
     849                 :            : 
     850                 :          1 :   g_application_command_line_set_exit_status (command_line, 42);
     851                 :          1 :   g_application_command_line_done (command_line);
     852                 :            : 
     853                 :          1 :   return 0;
     854                 :            : }
     855                 :            : 
     856                 :            : /* Test whether 'command-line' handler return value is ignored
     857                 :            :  * after g_application_command_line_done()
     858                 :            :  */
     859                 :            : static void
     860                 :          1 : test_command_line_done (void)
     861                 :            : {
     862                 :          1 :   char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     863                 :          1 :   const gchar *const argv[] = { binpath, "arg", NULL };
     864                 :            :   GApplication *app;
     865                 :          1 :   gboolean called = FALSE;
     866                 :            :   int status;
     867                 :            :   gulong command_line_id;
     868                 :            : 
     869                 :          1 :   app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE);
     870                 :          1 :   command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (command_line_done_callback), &called);
     871                 :            : 
     872                 :          1 :   status = g_application_run (app, G_N_ELEMENTS (argv) - 1, (gchar **) argv);
     873                 :            : 
     874                 :          1 :   g_signal_handler_disconnect (app, command_line_id);
     875                 :          1 :   g_object_unref (app);
     876                 :          1 :   g_free (binpath);
     877                 :            : 
     878                 :          1 :   g_assert_true (called);
     879                 :          1 :   g_assert_cmpint (status, ==, 42);
     880                 :          1 : }
     881                 :            : 
     882                 :            : static void
     883                 :          1 : test_busy (void)
     884                 :            : {
     885                 :            :   GApplication *app;
     886                 :            : 
     887                 :            :   /* use GSimpleAction to bind to the busy state, because it's easy to
     888                 :            :    * create and has an easily modifiable boolean property */
     889                 :            :   GSimpleAction *action1;
     890                 :            :   GSimpleAction *action2;
     891                 :            : 
     892                 :          1 :   session_bus_up ();
     893                 :            : 
     894                 :          1 :   app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_NON_UNIQUE);
     895                 :          1 :   g_assert (g_application_register (app, NULL, NULL));
     896                 :            : 
     897                 :          1 :   g_assert (!g_application_get_is_busy (app));
     898                 :          1 :   g_application_mark_busy (app);
     899                 :          1 :   g_assert (g_application_get_is_busy (app));
     900                 :          1 :   g_application_unmark_busy (app);
     901                 :          1 :   g_assert (!g_application_get_is_busy (app));
     902                 :            : 
     903                 :          1 :   action1 = g_simple_action_new ("action", NULL);
     904                 :          1 :   g_application_bind_busy_property (app, action1, "enabled");
     905                 :          1 :   g_assert (g_application_get_is_busy (app));
     906                 :            : 
     907                 :          1 :   g_simple_action_set_enabled (action1, FALSE);
     908                 :          1 :   g_assert (!g_application_get_is_busy (app));
     909                 :            : 
     910                 :          1 :   g_application_mark_busy (app);
     911                 :          1 :   g_assert (g_application_get_is_busy (app));
     912                 :            : 
     913                 :          1 :   action2 = g_simple_action_new ("action", NULL);
     914                 :          1 :   g_application_bind_busy_property (app, action2, "enabled");
     915                 :          1 :   g_assert (g_application_get_is_busy (app));
     916                 :            : 
     917                 :          1 :   g_application_unmark_busy (app);
     918                 :          1 :   g_assert (g_application_get_is_busy (app));
     919                 :            : 
     920                 :          1 :   g_object_unref (action2);
     921                 :          1 :   g_assert (!g_application_get_is_busy (app));
     922                 :            : 
     923                 :          1 :   g_simple_action_set_enabled (action1, TRUE);
     924                 :          1 :   g_assert (g_application_get_is_busy (app));
     925                 :            : 
     926                 :          1 :   g_application_mark_busy (app);
     927                 :          1 :   g_assert (g_application_get_is_busy (app));
     928                 :            : 
     929                 :          1 :   g_application_unbind_busy_property (app, action1, "enabled");
     930                 :          1 :   g_assert (g_application_get_is_busy (app));
     931                 :            : 
     932                 :          1 :   g_application_unmark_busy (app);
     933                 :          1 :   g_assert (!g_application_get_is_busy (app));
     934                 :            : 
     935                 :          1 :   g_object_unref (action1);
     936                 :          1 :   g_object_unref (app);
     937                 :            : 
     938                 :          1 :   session_bus_down ();
     939                 :          1 : }
     940                 :            : 
     941                 :            : /*
     942                 :            :  * Test that handle-local-options works as expected
     943                 :            :  */
     944                 :            : 
     945                 :            : static gint
     946                 :          3 : test_local_options (GApplication *app,
     947                 :            :                     GVariantDict *options,
     948                 :            :                     gpointer      data)
     949                 :            : {
     950                 :          3 :   gboolean *called = data;
     951                 :            : 
     952                 :          3 :   *called = TRUE;
     953                 :            : 
     954         [ +  + ]:          3 :   if (g_variant_dict_contains (options, "success"))
     955                 :          1 :     return 0;
     956         [ +  + ]:          2 :   else if (g_variant_dict_contains (options, "failure"))
     957                 :          1 :     return 1;
     958                 :            :   else
     959                 :          1 :     return -1;
     960                 :            : }
     961                 :            : 
     962                 :            : static gint
     963                 :          1 : second_handler (GApplication *app,
     964                 :            :                 GVariantDict *options,
     965                 :            :                 gpointer      data)
     966                 :            : {
     967                 :          1 :   gboolean *called = data;
     968                 :            : 
     969                 :          1 :   *called = TRUE;
     970                 :            : 
     971                 :          1 :   return 2;
     972                 :            : }
     973                 :            : 
     974                 :            : static void
     975                 :          2 : test_handle_local_options_success (void)
     976                 :            : {
     977         [ +  + ]:          2 :   if (g_test_subprocess ())
     978                 :            :     {
     979                 :          1 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
     980                 :          1 :       gchar *argv[] = { binpath, "--success", NULL };
     981                 :            :       GApplication *app;
     982                 :          1 :       gboolean called = FALSE;
     983                 :          1 :       gboolean called2 = FALSE;
     984                 :            :       int status;
     985                 :            : 
     986                 :          1 :       app = g_application_new ("org.gtk.TestApplication", 0);
     987                 :          1 :       g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
     988                 :          1 :       g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
     989                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
     990                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
     991                 :            : 
     992                 :          1 :       status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
     993                 :          1 :       g_assert (called);
     994                 :          1 :       g_assert (!called2);
     995                 :          1 :       g_assert_cmpint (status, ==, 0);
     996                 :            : 
     997                 :          1 :       g_object_unref (app);
     998                 :          1 :       g_free (binpath);
     999                 :          1 :       return;
    1000                 :            :     }
    1001                 :            : 
    1002                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
    1003                 :          1 :   g_test_trap_assert_passed ();
    1004                 :            : }
    1005                 :            : 
    1006                 :            : static void
    1007                 :          2 : test_handle_local_options_failure (void)
    1008                 :            : {
    1009         [ +  + ]:          2 :   if (g_test_subprocess ())
    1010                 :            :     {
    1011                 :          1 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
    1012                 :          1 :       gchar *argv[] = { binpath, "--failure", NULL };
    1013                 :            :       GApplication *app;
    1014                 :          1 :       gboolean called = FALSE;
    1015                 :          1 :       gboolean called2 = FALSE;
    1016                 :            :       int status;
    1017                 :            : 
    1018                 :          1 :       app = g_application_new ("org.gtk.TestApplication", 0);
    1019                 :          1 :       g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
    1020                 :          1 :       g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
    1021                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
    1022                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
    1023                 :            : 
    1024                 :          1 :       status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
    1025                 :          1 :       g_assert (called);
    1026                 :          1 :       g_assert (!called2);
    1027                 :          1 :       g_assert_cmpint (status, ==, 1);
    1028                 :            : 
    1029                 :          1 :       g_object_unref (app);
    1030                 :          1 :       g_free (binpath);
    1031                 :          1 :       return;
    1032                 :            :     }
    1033                 :            : 
    1034                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
    1035                 :          1 :   g_test_trap_assert_passed ();
    1036                 :            : }
    1037                 :            : 
    1038                 :            : static void
    1039                 :          2 : test_handle_local_options_passthrough (void)
    1040                 :            : {
    1041         [ +  + ]:          2 :   if (g_test_subprocess ())
    1042                 :            :     {
    1043                 :          1 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
    1044                 :          1 :       gchar *argv[] = { binpath, NULL };
    1045                 :            :       GApplication *app;
    1046                 :          1 :       gboolean called = FALSE;
    1047                 :          1 :       gboolean called2 = FALSE;
    1048                 :            :       int status;
    1049                 :            : 
    1050                 :          1 :       app = g_application_new ("org.gtk.TestApplication", 0);
    1051                 :          1 :       g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
    1052                 :          1 :       g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
    1053                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
    1054                 :          1 :       g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
    1055                 :            : 
    1056                 :          1 :       status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
    1057                 :          1 :       g_assert (called);
    1058                 :          1 :       g_assert (called2);
    1059                 :          1 :       g_assert_cmpint (status, ==, 2);
    1060                 :            : 
    1061                 :          1 :       g_object_unref (app);
    1062                 :          1 :       g_free (binpath);
    1063                 :          1 :       return;
    1064                 :            :     }
    1065                 :            : 
    1066                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
    1067                 :          1 :   g_test_trap_assert_passed ();
    1068                 :            : }
    1069                 :            : 
    1070                 :            : static void
    1071                 :          1 : test_api (void)
    1072                 :            : {
    1073                 :            :   GApplication *app;
    1074                 :            :   GSimpleAction *action;
    1075                 :            : 
    1076                 :          1 :   app = g_application_new ("org.gtk.TestApplication", 0);
    1077                 :            : 
    1078                 :            :   /* add an action without a name */
    1079                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*assertion*failed*");
    1080                 :          1 :   action = g_simple_action_new (NULL, NULL);
    1081                 :          1 :   g_assert (action == NULL);
    1082                 :          1 :   g_test_assert_expected_messages ();
    1083                 :            : 
    1084                 :            :   /* also, gapplication shouldn't accept actions without names */
    1085                 :          1 :   action = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
    1086                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*action has no name*");
    1087                 :          1 :   g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
    1088                 :          1 :   g_test_assert_expected_messages ();
    1089                 :            : 
    1090                 :          1 :   g_object_unref (action);
    1091                 :          1 :   g_object_unref (app);
    1092                 :          1 : }
    1093                 :            : 
    1094                 :            : static void
    1095                 :          1 : test_version (void)
    1096                 :            : {
    1097                 :            :   GApplication *app;
    1098                 :          1 :   gchar *version = NULL;
    1099                 :          1 :   gchar *version_orig = NULL;
    1100                 :            : 
    1101                 :          1 :   app = g_application_new ("org.gtk.TestApplication", 0);
    1102                 :            : 
    1103                 :          1 :   version_orig = "1.2";
    1104                 :          1 :   g_object_set (G_OBJECT (app), "version", version_orig, NULL);
    1105                 :          1 :   g_object_get (app, "version", &version, NULL);
    1106                 :          1 :   g_assert_cmpstr (version, ==, version_orig);
    1107                 :          1 :   g_free (version);
    1108                 :            : 
    1109                 :            :   /* test attempting to set the same version again */
    1110                 :          1 :   version_orig = "1.2";
    1111                 :          1 :   g_object_set (G_OBJECT (app), "version", version_orig, NULL);
    1112                 :          1 :   g_object_get (app, "version", &version, NULL);
    1113                 :          1 :   g_assert_cmpstr (version, ==, version_orig);
    1114                 :          1 :   g_free (version);
    1115                 :            : 
    1116                 :          1 :   version_orig = "2.4";
    1117                 :          1 :   g_object_set (G_OBJECT (app), "version", version_orig, NULL);
    1118                 :          1 :   g_object_get (app, "version", &version, NULL);
    1119                 :          1 :   g_assert_cmpstr (version, ==, version_orig);
    1120                 :          1 :   g_free (version);
    1121                 :            : 
    1122                 :          1 :   g_object_unref (app);
    1123                 :          1 : }
    1124                 :            : 
    1125                 :            : /* Check that G_APPLICATION_ALLOW_REPLACEMENT works. To do so, we launch
    1126                 :            :  * a GApplication in this process that allows replacement, and then
    1127                 :            :  * launch a subprocess with --gapplication-replace. We have to do our
    1128                 :            :  * own async version of g_test_trap_subprocess() here since we need
    1129                 :            :  * the main process to keep spinning its mainloop.
    1130                 :            :  */
    1131                 :            : 
    1132                 :            : static gboolean
    1133                 :          1 : name_was_lost (GApplication *app,
    1134                 :            :                gboolean     *called)
    1135                 :            : {
    1136                 :          1 :   *called = TRUE;
    1137                 :          1 :   g_application_quit (app);
    1138                 :          1 :   return TRUE;
    1139                 :            : }
    1140                 :            : 
    1141                 :            : static void
    1142                 :          1 : startup_in_subprocess (GApplication *app,
    1143                 :            :                        gboolean     *called)
    1144                 :            : {
    1145                 :          1 :   *called = TRUE;
    1146                 :          1 : }
    1147                 :            : 
    1148                 :            : typedef struct
    1149                 :            : {
    1150                 :            :   gboolean allow_replacement;
    1151                 :            :   GSubprocess *subprocess;
    1152                 :            :   GApplication *app;  /* (not owned) */
    1153                 :            :   guint timeout_id;
    1154                 :            : } TestReplaceData;
    1155                 :            : 
    1156                 :            : static void
    1157                 :          2 : startup_cb (GApplication *app,
    1158                 :            :             TestReplaceData *data)
    1159                 :            : {
    1160                 :          2 :   const char *argv[] = { NULL, "--verbose", "--quiet", "-p", NULL, "--GTestSubprocess", NULL };
    1161                 :            :   GSubprocessLauncher *launcher;
    1162                 :          2 :   GError *local_error = NULL;
    1163                 :            : 
    1164                 :          2 :   g_application_hold (app);
    1165                 :            : 
    1166                 :          2 :   argv[0] = g_get_prgname ();
    1167                 :            : 
    1168         [ +  + ]:          2 :   if (data->allow_replacement)
    1169                 :          1 :     argv[4] = "/gapplication/replace";
    1170                 :            :   else
    1171                 :          1 :     argv[4] = "/gapplication/no-replace";
    1172                 :            : 
    1173                 :            :   /* Now that we are the primary instance, launch our replacement.
    1174                 :            :    * We inherit the environment to share the test session bus.
    1175                 :            :    */
    1176                 :          2 :   g_test_message ("launching subprocess");
    1177                 :            : 
    1178                 :          2 :   launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
    1179                 :          2 :   g_subprocess_launcher_set_environ (launcher, NULL);
    1180                 :          2 :   data->subprocess = g_subprocess_launcher_spawnv (launcher, argv, &local_error);
    1181                 :          2 :   g_assert_no_error (local_error);
    1182                 :          2 :   g_object_unref (launcher);
    1183                 :            : 
    1184         [ +  + ]:          2 :   if (!data->allow_replacement)
    1185                 :            :     {
    1186                 :            :       /* make sure we exit after a bit, if the subprocess is not replacing us */
    1187                 :          1 :       g_application_set_inactivity_timeout (app, 500);
    1188                 :          1 :       g_application_release (app);
    1189                 :            :     }
    1190                 :          2 : }
    1191                 :            : 
    1192                 :            : static void
    1193                 :          4 : activate (gpointer data)
    1194                 :            : {
    1195                 :            :   /* GApplication complains if we don't connect to ::activate */
    1196                 :          4 : }
    1197                 :            : 
    1198                 :            : static void
    1199                 :          0 : quit_already (gpointer user_data)
    1200                 :            : {
    1201                 :          0 :   TestReplaceData *data = user_data;
    1202                 :            : 
    1203                 :          0 :   g_application_quit (data->app);
    1204                 :          0 :   data->timeout_id = 0;
    1205                 :          0 : }
    1206                 :            : 
    1207                 :            : static void
    1208                 :          4 : test_replace (gconstpointer data)
    1209                 :            : {
    1210                 :          4 :   gboolean allow = GPOINTER_TO_INT (data);
    1211                 :            : 
    1212         [ +  + ]:          4 :   if (g_test_subprocess ())
    1213                 :            :     {
    1214                 :          2 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
    1215                 :          2 :       char *argv[] = { binpath, "--gapplication-replace", NULL };
    1216                 :            :       GApplication *app;
    1217                 :          2 :       gboolean startup = FALSE;
    1218                 :            : 
    1219                 :          2 :       app = g_application_new ("org.gtk.TestApplication.Replace", G_APPLICATION_ALLOW_REPLACEMENT);
    1220                 :          2 :       g_signal_connect (app, "startup", G_CALLBACK (startup_in_subprocess), &startup);
    1221                 :          2 :       g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    1222                 :            : 
    1223                 :          2 :       g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
    1224                 :            : 
    1225         [ +  + ]:          2 :       if (allow)
    1226                 :          1 :         g_assert_true (startup);
    1227                 :            :       else
    1228                 :          1 :         g_assert_false (startup);
    1229                 :            : 
    1230                 :          2 :       g_object_unref (app);
    1231                 :          2 :       g_free (binpath);
    1232                 :            :     }
    1233                 :            :   else
    1234                 :            :     {
    1235                 :          2 :       char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
    1236                 :          2 :       gchar *argv[] = { binpath, NULL };
    1237                 :            :       GApplication *app;
    1238                 :          2 :       gboolean name_lost = FALSE;
    1239                 :            :       TestReplaceData data;
    1240                 :            :       GTestDBus *bus;
    1241                 :            : 
    1242                 :          2 :       data.allow_replacement = allow;
    1243                 :          2 :       data.subprocess = NULL;
    1244                 :          2 :       data.timeout_id = 0;
    1245                 :            : 
    1246                 :          2 :       bus = g_test_dbus_new (0);
    1247                 :          2 :       g_test_dbus_up (bus);
    1248                 :            : 
    1249         [ +  + ]:          2 :       app = data.app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
    1250                 :          2 :       g_application_set_inactivity_timeout (app, 500);
    1251                 :          2 :       g_signal_connect (app, "name-lost", G_CALLBACK (name_was_lost), &name_lost);
    1252                 :          2 :       g_signal_connect (app, "startup", G_CALLBACK (startup_cb), &data);
    1253                 :          2 :       g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    1254                 :            : 
    1255         [ +  + ]:          2 :       if (!allow)
    1256                 :          1 :         data.timeout_id = g_timeout_add_seconds_once (1, quit_already, &data);
    1257                 :            : 
    1258                 :          2 :       g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
    1259                 :            : 
    1260                 :          2 :       g_assert_nonnull (data.subprocess);
    1261         [ +  + ]:          2 :       if (allow)
    1262                 :          1 :         g_assert_true (name_lost);
    1263                 :            :       else
    1264                 :          1 :         g_assert_false (name_lost);
    1265                 :            : 
    1266                 :          2 :       g_clear_handle_id (&data.timeout_id, g_source_remove);
    1267                 :          2 :       g_object_unref (app);
    1268                 :          2 :       g_free (binpath);
    1269                 :            : 
    1270                 :          2 :       g_subprocess_wait (data.subprocess, NULL, NULL);
    1271                 :          2 :       g_clear_object (&data.subprocess);
    1272                 :            : 
    1273                 :          2 :       g_test_dbus_down (bus);
    1274                 :          2 :       g_object_unref (bus);
    1275                 :            :     }
    1276                 :          4 : }
    1277                 :            : 
    1278                 :            : static void
    1279                 :          6 : dbus_activate_cb (GApplication *app,
    1280                 :            :                   gpointer      user_data)
    1281                 :            : {
    1282                 :          6 :   guint *n_activations = user_data;
    1283                 :            : 
    1284                 :          6 :   *n_activations = *n_activations + 1;
    1285                 :          6 :   g_main_context_wakeup (NULL);
    1286                 :          6 : }
    1287                 :            : 
    1288                 :            : static void dbus_startup_reply_cb (GObject      *source_object,
    1289                 :            :                                    GAsyncResult *result,
    1290                 :            :                                    gpointer      user_data);
    1291                 :            : static gboolean dbus_startup_reply_idle_cb (gpointer user_data);
    1292                 :            : 
    1293                 :            : static void
    1294                 :         17 : dbus_startup_cb (GApplication *app,
    1295                 :            :                  gpointer      user_data)
    1296                 :            : {
    1297                 :         17 :   GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
    1298                 :         17 :   GDBusMessage *message = G_DBUS_MESSAGE (user_data);
    1299                 :            : 
    1300                 :         17 :   g_assert_nonnull (connection);
    1301                 :            : 
    1302                 :         17 :   g_dbus_connection_send_message_with_reply (connection, message,
    1303                 :            :                                              G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1,
    1304                 :            :                                              NULL, NULL,
    1305                 :            :                                              dbus_startup_reply_cb, g_object_ref (app));
    1306                 :            : 
    1307                 :         17 :   g_clear_object (&connection);
    1308                 :         17 : }
    1309                 :            : 
    1310                 :            : static void
    1311                 :         17 : dbus_startup_reply_cb (GObject      *source_object,
    1312                 :            :                        GAsyncResult *result,
    1313                 :            :                        gpointer      user_data)
    1314                 :            : {
    1315                 :         17 :   GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
    1316                 :         17 :   GApplication *app = G_APPLICATION (user_data);
    1317                 :         17 :   GDBusMessage *reply = NULL;
    1318                 :         17 :   GError *local_error = NULL;
    1319                 :            : 
    1320                 :         17 :   reply = g_dbus_connection_send_message_with_reply_finish (connection, result, &local_error);
    1321                 :         17 :   g_assert_no_error (local_error);
    1322                 :            : 
    1323                 :         17 :   g_object_set_data_full (G_OBJECT (app), "dbus-command-line-reply", g_steal_pointer (&reply), g_object_unref);
    1324                 :            : 
    1325                 :            :   /* Release the app in an idle callback, so there’s time to process other
    1326                 :            :    * pending sources first. */
    1327                 :         17 :   g_idle_add_full (G_PRIORITY_LOW, dbus_startup_reply_idle_cb, g_steal_pointer (&app), g_object_unref);
    1328                 :         17 : }
    1329                 :            : 
    1330                 :            : static gboolean
    1331                 :         17 : dbus_startup_reply_idle_cb (gpointer user_data)
    1332                 :            : {
    1333                 :         17 :   GApplication *app = G_APPLICATION (user_data);
    1334                 :            : 
    1335                 :         17 :   g_application_release (app);
    1336                 :            : 
    1337                 :         17 :   return G_SOURCE_REMOVE;
    1338                 :            : }
    1339                 :            : 
    1340                 :            : static void
    1341                 :          1 : test_dbus_activate (void)
    1342                 :            : {
    1343                 :          1 :   GTestDBus *bus = NULL;
    1344                 :            :   GVariantBuilder builder;
    1345                 :          1 :   GDBusMessage *message = NULL;
    1346                 :          1 :   GPtrArray *messages = NULL;  /* (element-type GDBusMessage) (owned) */
    1347                 :            :   gsize i;
    1348                 :            : 
    1349                 :          1 :   g_test_summary ("Test that calling the Activate D-Bus method works");
    1350                 :            : 
    1351                 :            :   /* Try various different messages */
    1352                 :          1 :   messages = g_ptr_array_new_with_free_func (g_object_unref);
    1353                 :            : 
    1354                 :            :   /* Via org.gtk.Application */
    1355                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
    1356                 :            :                                             "/org/gtk/TestApplication/Activate",
    1357                 :            :                                             "org.gtk.Application",
    1358                 :            :                                             "Activate");
    1359                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
    1360                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1361                 :            : 
    1362                 :            :   /* Via org.freedesktop.Application */
    1363                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
    1364                 :            :                                             "/org/gtk/TestApplication/Activate",
    1365                 :            :                                             "org.freedesktop.Application",
    1366                 :            :                                             "Activate");
    1367                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
    1368                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1369                 :            : 
    1370                 :            :   /* With some platform data */
    1371                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
    1372                 :          1 :   g_variant_builder_add (&builder, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
    1373                 :            : 
    1374                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
    1375                 :            :                                             "/org/gtk/TestApplication/Activate",
    1376                 :            :                                             "org.gtk.Application",
    1377                 :            :                                             "Activate");
    1378                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(a{sv})", &builder));
    1379                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1380                 :            : 
    1381                 :            :   /* Try each message */
    1382                 :          1 :   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
    1383                 :          1 :   g_test_dbus_up (bus);
    1384                 :            : 
    1385         [ +  + ]:          4 :   for (i = 0; i < messages->len; i++)
    1386                 :            :     {
    1387                 :          3 :       GApplication *app = NULL;
    1388                 :            :       gulong activate_id, startup_id;
    1389                 :          3 :       guint n_activations = 0;
    1390                 :            : 
    1391                 :          3 :       g_test_message ("Message %" G_GSIZE_FORMAT, i);
    1392                 :            : 
    1393                 :          3 :       app = g_application_new ("org.gtk.TestApplication.Activate", G_APPLICATION_DEFAULT_FLAGS);
    1394                 :          3 :       activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_cb), &n_activations);
    1395                 :          3 :       startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
    1396                 :            : 
    1397                 :          3 :       g_application_hold (app);
    1398                 :          3 :       g_application_run (app, 0, NULL);
    1399                 :            : 
    1400                 :            :       /* It’ll be activated once as normal, and once due to the D-Bus call */
    1401                 :          3 :       g_assert_cmpuint (n_activations, ==, 2);
    1402                 :            : 
    1403                 :          3 :       g_signal_handler_disconnect (app, startup_id);
    1404                 :          3 :       g_signal_handler_disconnect (app, activate_id);
    1405                 :          3 :       g_clear_object (&app);
    1406                 :            :     }
    1407                 :            : 
    1408                 :          1 :   g_ptr_array_unref (messages);
    1409                 :            : 
    1410                 :          1 :   g_test_dbus_down (bus);
    1411                 :          1 :   g_clear_object (&bus);
    1412                 :          1 : }
    1413                 :            : 
    1414                 :            : static void
    1415                 :         10 : dbus_activate_noop_cb (GApplication *app,
    1416                 :            :                        gpointer      user_data)
    1417                 :            : {
    1418                 :            :   /* noop */
    1419                 :         10 : }
    1420                 :            : 
    1421                 :            : static void
    1422                 :          4 : dbus_open_cb (GApplication *app,
    1423                 :            :               gpointer      files,
    1424                 :            :               int           n_files,
    1425                 :            :               char         *hint,
    1426                 :            :               gpointer      user_data)
    1427                 :            : {
    1428                 :          4 :   guint *n_opens = user_data;
    1429                 :            : 
    1430                 :          4 :   *n_opens = *n_opens + 1;
    1431                 :          4 :   g_main_context_wakeup (NULL);
    1432                 :          4 : }
    1433                 :            : 
    1434                 :            : static void
    1435                 :          1 : test_dbus_open (void)
    1436                 :            : {
    1437                 :          1 :   GTestDBus *bus = NULL;
    1438                 :            :   GVariantBuilder builder, builder2;
    1439                 :          1 :   GDBusMessage *message = NULL;
    1440                 :          1 :   GPtrArray *messages = NULL;  /* (element-type GDBusMessage) (owned) */
    1441                 :            :   gsize i;
    1442                 :            : 
    1443                 :          1 :   g_test_summary ("Test that calling the Open D-Bus method works");
    1444                 :            : 
    1445                 :            :   /* Try various different messages */
    1446                 :          1 :   messages = g_ptr_array_new_with_free_func (g_object_unref);
    1447                 :            : 
    1448                 :            :   /* Via org.gtk.Application */
    1449                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
    1450                 :          1 :   g_variant_builder_add (&builder, "s", "file:///home/henry/test");
    1451                 :            : 
    1452                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
    1453                 :            :                                             "/org/gtk/TestApplication/Open",
    1454                 :            :                                             "org.gtk.Application",
    1455                 :            :                                             "Open");
    1456                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "hint", NULL));
    1457                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1458                 :            : 
    1459                 :            :   /* Via org.freedesktop.Application (which has no hint parameter) */
    1460                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
    1461                 :          1 :   g_variant_builder_add (&builder, "s", "file:///home/henry/test");
    1462                 :            : 
    1463                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
    1464                 :            :                                             "/org/gtk/TestApplication/Open",
    1465                 :            :                                             "org.freedesktop.Application",
    1466                 :            :                                             "Open");
    1467                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(asa{sv})", &builder, NULL));
    1468                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1469                 :            : 
    1470                 :            :   /* With some platform data and more than one file */
    1471                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
    1472                 :          1 :   g_variant_builder_add (&builder, "s", "file:///home/henry/test");
    1473                 :          1 :   g_variant_builder_add (&builder, "s", "file:///home/henry/test2");
    1474                 :            : 
    1475                 :          1 :   g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
    1476                 :          1 :   g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
    1477                 :            : 
    1478                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
    1479                 :            :                                             "/org/gtk/TestApplication/Open",
    1480                 :            :                                             "org.gtk.Application",
    1481                 :            :                                             "Open");
    1482                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "", &builder2));
    1483                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1484                 :            : 
    1485                 :            :   /* No files */
    1486                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
    1487                 :            :                                             "/org/gtk/TestApplication/Open",
    1488                 :            :                                             "org.gtk.Application",
    1489                 :            :                                             "Open");
    1490                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", NULL, "", NULL));
    1491                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1492                 :            : 
    1493                 :            :   /* Try each message */
    1494                 :          1 :   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
    1495                 :          1 :   g_test_dbus_up (bus);
    1496                 :            : 
    1497         [ +  + ]:          5 :   for (i = 0; i < messages->len; i++)
    1498                 :            :     {
    1499                 :          4 :       GApplication *app = NULL;
    1500                 :            :       gulong activate_id, open_id, startup_id;
    1501                 :          4 :       guint n_opens = 0;
    1502                 :            : 
    1503                 :          4 :       g_test_message ("Message %" G_GSIZE_FORMAT, i);
    1504                 :            : 
    1505                 :          4 :       app = g_application_new ("org.gtk.TestApplication.Open", G_APPLICATION_HANDLES_OPEN);
    1506                 :          4 :       activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
    1507                 :          4 :       open_id = g_signal_connect (app, "open", G_CALLBACK (dbus_open_cb), &n_opens);
    1508                 :          4 :       startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
    1509                 :            : 
    1510                 :          4 :       g_application_hold (app);
    1511                 :          4 :       g_application_run (app, 0, NULL);
    1512                 :            : 
    1513                 :          4 :       g_assert_cmpuint (n_opens, ==, 1);
    1514                 :            : 
    1515                 :          4 :       g_signal_handler_disconnect (app, startup_id);
    1516                 :          4 :       g_signal_handler_disconnect (app, open_id);
    1517                 :          4 :       g_signal_handler_disconnect (app, activate_id);
    1518                 :          4 :       g_clear_object (&app);
    1519                 :            :     }
    1520                 :            : 
    1521                 :          1 :   g_ptr_array_unref (messages);
    1522                 :            : 
    1523                 :          1 :   g_test_dbus_down (bus);
    1524                 :          1 :   g_clear_object (&bus);
    1525                 :          1 : }
    1526                 :            : 
    1527                 :            : static void
    1528                 :          6 : dbus_command_line_cb (GApplication            *app,
    1529                 :            :                       GApplicationCommandLine *command_line,
    1530                 :            :                       gpointer                 user_data)
    1531                 :            : {
    1532                 :          6 :   guint *n_command_lines = user_data;
    1533                 :            : 
    1534                 :          6 :   *n_command_lines = *n_command_lines + 1;
    1535                 :          6 :   g_main_context_wakeup (NULL);
    1536                 :          6 : }
    1537                 :            : 
    1538                 :            : static void
    1539                 :          1 : test_dbus_command_line (void)
    1540                 :            : {
    1541                 :          1 :   GTestDBus *bus = NULL;
    1542                 :            :   GVariantBuilder builder, builder2;
    1543                 :          1 :   GDBusMessage *message = NULL;
    1544                 :          1 :   GPtrArray *messages = NULL;  /* (element-type GDBusMessage) (owned) */
    1545                 :            :   gsize i;
    1546                 :            : 
    1547                 :          1 :   g_test_summary ("Test that calling the CommandLine D-Bus method works");
    1548                 :            : 
    1549                 :            :   /* Try various different messages */
    1550                 :          1 :   messages = g_ptr_array_new_with_free_func (g_object_unref);
    1551                 :            : 
    1552                 :            :   /* Via org.gtk.Application */
    1553                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
    1554                 :          1 :   g_variant_builder_add (&builder, "^ay", "test-program");
    1555                 :          1 :   g_variant_builder_add (&builder, "^ay", "--open");
    1556                 :          1 :   g_variant_builder_add (&builder, "^ay", "/path/to/something");
    1557                 :            : 
    1558                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
    1559                 :            :                                             "/org/gtk/TestApplication/CommandLine",
    1560                 :            :                                             "org.gtk.Application",
    1561                 :            :                                             "CommandLine");
    1562                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
    1563                 :            :                                                    "/my/org/gtk/private/CommandLine",
    1564                 :            :                                                    &builder, NULL));
    1565                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1566                 :            : 
    1567                 :            :   /* With platform data */
    1568                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
    1569                 :          1 :   g_variant_builder_add (&builder, "^ay", "test-program");
    1570                 :          1 :   g_variant_builder_add (&builder, "^ay", "--open");
    1571                 :          1 :   g_variant_builder_add (&builder, "^ay", "/path/to/something");
    1572                 :            : 
    1573                 :          1 :   g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
    1574                 :          1 :   g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home"));
    1575                 :          1 :   g_variant_builder_add_parsed (&builder2, "{'environ', <@aay [ b'HOME=/home/bloop', b'PATH=/blah']>}");
    1576                 :          1 :   g_variant_builder_add_parsed (&builder2, "{'options', <{'a': <@u 32>, 'b': <'bloop'>}>}");
    1577                 :            : 
    1578                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
    1579                 :            :                                             "/org/gtk/TestApplication/CommandLine",
    1580                 :            :                                             "org.gtk.Application",
    1581                 :            :                                             "CommandLine");
    1582                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
    1583                 :            :                                                    "/my/org/gtk/private/CommandLine",
    1584                 :            :                                                    &builder, &builder2));
    1585                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1586                 :            : 
    1587                 :            :   /* With invalid typed platform data */
    1588                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
    1589                 :          1 :   g_variant_builder_add (&builder, "^ay", "test-program");
    1590                 :          1 :   g_variant_builder_add (&builder, "^ay", "--open");
    1591                 :          1 :   g_variant_builder_add (&builder, "^ay", "/path/to/something");
    1592                 :            : 
    1593                 :          1 :   g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
    1594                 :          1 :   g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_string ("/home should be a bytestring"));
    1595                 :          1 :   g_variant_builder_add_parsed (&builder2, "{'environ', <['HOME=should be a bytestring', 'PATH=this also']>}");
    1596                 :          1 :   g_variant_builder_add_parsed (&builder2, "{'options', <['should be a', 'dict']>}");
    1597                 :            : 
    1598                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
    1599                 :            :                                             "/org/gtk/TestApplication/CommandLine",
    1600                 :            :                                             "org.gtk.Application",
    1601                 :            :                                             "CommandLine");
    1602                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
    1603                 :            :                                                    "/my/org/gtk/private/CommandLine",
    1604                 :            :                                                    &builder, &builder2));
    1605                 :          1 :   g_ptr_array_add (messages, g_steal_pointer (&message));
    1606                 :            : 
    1607                 :            :   /* Try each message */
    1608                 :          1 :   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
    1609                 :          1 :   g_test_dbus_up (bus);
    1610                 :            : 
    1611         [ +  + ]:          4 :   for (i = 0; i < messages->len; i++)
    1612                 :            :     {
    1613                 :          3 :       GApplication *app = NULL;
    1614                 :            :       gulong activate_id, command_line_id, startup_id;
    1615                 :          3 :       guint n_command_lines = 0;
    1616                 :            : 
    1617                 :          3 :       g_test_message ("Message %" G_GSIZE_FORMAT, i);
    1618                 :            : 
    1619                 :          3 :       app = g_application_new ("org.gtk.TestApplication.CommandLine", G_APPLICATION_HANDLES_COMMAND_LINE);
    1620                 :          3 :       activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
    1621                 :          3 :       command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (dbus_command_line_cb), &n_command_lines);
    1622                 :          3 :       startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
    1623                 :            : 
    1624                 :          3 :       g_application_hold (app);
    1625                 :          3 :       g_application_run (app, 0, NULL);
    1626                 :            : 
    1627                 :            :       /* It’s called once for handling the local command line on startup, and again
    1628                 :            :        * for the D-Bus call */
    1629                 :          3 :       g_assert_cmpuint (n_command_lines, ==, 2);
    1630                 :            : 
    1631                 :          3 :       g_signal_handler_disconnect (app, startup_id);
    1632                 :          3 :       g_signal_handler_disconnect (app, command_line_id);
    1633                 :          3 :       g_signal_handler_disconnect (app, activate_id);
    1634                 :          3 :       g_clear_object (&app);
    1635                 :            :     }
    1636                 :            : 
    1637                 :          1 :   g_ptr_array_unref (messages);
    1638                 :            : 
    1639                 :          1 :   g_test_dbus_down (bus);
    1640                 :          1 :   g_clear_object (&bus);
    1641                 :          1 : }
    1642                 :            : 
    1643                 :            : static gint
    1644                 :          2 : dbus_command_line_done_cb (GApplication            *app,
    1645                 :            :                            GApplicationCommandLine *command_line,
    1646                 :            :                            gpointer                 user_data)
    1647                 :            : {
    1648                 :          2 :   guint *n_command_lines = user_data;
    1649                 :            : 
    1650                 :          2 :   *n_command_lines = *n_command_lines + 1;
    1651                 :            : 
    1652         [ +  + ]:          2 :   if (*n_command_lines == 1)
    1653                 :          1 :     return 0;
    1654                 :            : 
    1655                 :          1 :   g_object_set_data_full (G_OBJECT (app), "command-line", g_object_ref (command_line), g_object_unref);
    1656                 :            : 
    1657                 :          1 :   g_application_command_line_set_exit_status (command_line, 42);
    1658                 :          1 :   g_application_command_line_done (command_line);
    1659                 :            : 
    1660                 :          1 :   return 1; /* ignored - after g_application_command_line_done () */
    1661                 :            : }
    1662                 :            : 
    1663                 :            : static void
    1664                 :          1 : test_dbus_command_line_done (void)
    1665                 :            : {
    1666                 :          1 :   GTestDBus *bus = NULL;
    1667                 :            :   GVariantBuilder builder;
    1668                 :          1 :   GDBusMessage *message = NULL;
    1669                 :          1 :   GDBusMessage *reply = NULL;
    1670                 :          1 :   GApplication *app = NULL;
    1671                 :          1 :   guint n_command_lines = 0;
    1672                 :            :   gint exit_status;
    1673                 :            : 
    1674                 :          1 :   g_test_summary ("Test that GDBusCommandLine.done() works");
    1675                 :            : 
    1676                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
    1677                 :          1 :   g_variant_builder_add (&builder, "^ay", "test-program");
    1678                 :          1 :   g_variant_builder_add (&builder, "^ay", "/path/to/something");
    1679                 :            : 
    1680                 :          1 :   message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
    1681                 :            :                                             "/org/gtk/TestApplication/CommandLine",
    1682                 :            :                                             "org.gtk.Application",
    1683                 :            :                                             "CommandLine");
    1684                 :          1 :   g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
    1685                 :            :                                                    "/my/org/gtk/private/CommandLine",
    1686                 :            :                                                    &builder, NULL));
    1687                 :            : 
    1688                 :          1 :   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
    1689                 :          1 :   g_test_dbus_up (bus);
    1690                 :            : 
    1691                 :          1 :   app = g_application_new ("org.gtk.TestApplication.CommandLine", G_APPLICATION_HANDLES_COMMAND_LINE);
    1692                 :          1 :   g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
    1693                 :          1 :   g_signal_connect (app, "command-line", G_CALLBACK (dbus_command_line_done_cb), &n_command_lines);
    1694                 :          1 :   g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), message);
    1695                 :            : 
    1696                 :          1 :   g_application_hold (app);
    1697                 :          1 :   exit_status = g_application_run (app, 0, NULL);
    1698                 :            : 
    1699                 :          1 :   g_assert_cmpuint (n_command_lines, ==, 2);
    1700                 :          1 :   g_assert_cmpint (exit_status, ==, 0);
    1701                 :            : 
    1702                 :          1 :   reply = g_object_get_data (G_OBJECT (app), "dbus-command-line-reply");
    1703                 :          1 :   g_variant_get (g_dbus_message_get_body (reply), "(i)", &exit_status);
    1704                 :          1 :   g_assert_cmpint (exit_status, ==, 42);
    1705                 :            : 
    1706                 :          1 :   g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_activate_noop_cb), NULL);
    1707                 :          1 :   g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_command_line_done_cb), &n_command_lines);
    1708                 :          1 :   g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_startup_cb), message);
    1709                 :            : 
    1710                 :          1 :   g_clear_object (&app);
    1711                 :          1 :   g_clear_object (&message);
    1712                 :            : 
    1713                 :          1 :   g_test_dbus_down (bus);
    1714                 :          1 :   g_clear_object (&bus);
    1715                 :          1 : }
    1716                 :            : 
    1717                 :            : static void
    1718                 :          2 : dbus_activate_action_cb (GSimpleAction *action,
    1719                 :            :                          GVariant      *parameter,
    1720                 :            :                          gpointer       user_data)
    1721                 :            : {
    1722                 :          2 :   guint *n_activations = user_data;
    1723                 :            : 
    1724                 :          2 :   *n_activations = *n_activations + 1;
    1725                 :          2 :   g_main_context_wakeup (NULL);
    1726                 :          2 : }
    1727                 :            : 
    1728                 :            : static void
    1729                 :          1 : test_dbus_activate_action (void)
    1730                 :            : {
    1731                 :          1 :   GTestDBus *bus = NULL;
    1732                 :            :   GVariantBuilder builder;
    1733                 :            :   struct
    1734                 :            :     {
    1735                 :            :       GDBusMessage *message;  /* (not nullable) (owned) */
    1736                 :            :       guint n_expected_activations;
    1737                 :            :     } messages[6];
    1738                 :            :   gsize i;
    1739                 :            : 
    1740                 :          1 :   g_test_summary ("Test that calling the ActivateAction D-Bus method works");
    1741                 :            : 
    1742                 :            :   /* Action without parameter */
    1743                 :          1 :   messages[0].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1744                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1745                 :            :                                                         "org.freedesktop.Application",
    1746                 :            :                                                         "ActivateAction");
    1747                 :          1 :   g_dbus_message_set_body (messages[0].message, g_variant_new ("(sava{sv})", "undo", NULL, NULL));
    1748                 :          1 :   messages[0].n_expected_activations = 1;
    1749                 :            : 
    1750                 :            :   /* Action with parameter */
    1751                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
    1752                 :          1 :   g_variant_builder_add (&builder, "v", g_variant_new_string ("spanish"));
    1753                 :            : 
    1754                 :          1 :   messages[1].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1755                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1756                 :            :                                                         "org.freedesktop.Application",
    1757                 :            :                                                         "ActivateAction");
    1758                 :          1 :   g_dbus_message_set_body (messages[1].message, g_variant_new ("(sava{sv})", "lang", &builder, NULL));
    1759                 :          1 :   messages[1].n_expected_activations = 1;
    1760                 :            : 
    1761                 :            :   /* Action with unexpected parameter */
    1762                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
    1763                 :          1 :   g_variant_builder_add (&builder, "v", g_variant_new_string ("should not be passed"));
    1764                 :            : 
    1765                 :          1 :   messages[2].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1766                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1767                 :            :                                                         "org.freedesktop.Application",
    1768                 :            :                                                         "ActivateAction");
    1769                 :          1 :   g_dbus_message_set_body (messages[2].message, g_variant_new ("(sava{sv})", "undo", &builder, NULL));
    1770                 :          1 :   messages[2].n_expected_activations = 0;
    1771                 :            : 
    1772                 :            :   /* Action without required parameter */
    1773                 :          1 :   messages[3].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1774                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1775                 :            :                                                         "org.freedesktop.Application",
    1776                 :            :                                                         "ActivateAction");
    1777                 :          1 :   g_dbus_message_set_body (messages[3].message, g_variant_new ("(sava{sv})", "lang", NULL, NULL));
    1778                 :          1 :   messages[3].n_expected_activations = 0;
    1779                 :            : 
    1780                 :            :   /* Action with wrong parameter type */
    1781                 :          1 :   g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
    1782                 :          1 :   g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
    1783                 :            : 
    1784                 :          1 :   messages[4].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1785                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1786                 :            :                                                         "org.freedesktop.Application",
    1787                 :            :                                                         "ActivateAction");
    1788                 :          1 :   g_dbus_message_set_body (messages[4].message, g_variant_new ("(sava{sv})", "lang", &builder, NULL));
    1789                 :          1 :   messages[4].n_expected_activations = 0;
    1790                 :            : 
    1791                 :            :   /* Nonexistent action */
    1792                 :          1 :   messages[5].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
    1793                 :            :                                                         "/org/gtk/TestApplication/ActivateAction",
    1794                 :            :                                                         "org.freedesktop.Application",
    1795                 :            :                                                         "ActivateAction");
    1796                 :          1 :   g_dbus_message_set_body (messages[5].message, g_variant_new ("(sava{sv})", "nonexistent", NULL, NULL));
    1797                 :          1 :   messages[5].n_expected_activations = 0;
    1798                 :            : 
    1799                 :            :   /* Try each message */
    1800                 :          1 :   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
    1801                 :          1 :   g_test_dbus_up (bus);
    1802                 :            : 
    1803         [ +  + ]:          7 :   for (i = 0; i < G_N_ELEMENTS (messages); i++)
    1804                 :            :     {
    1805                 :          6 :       GApplication *app = NULL;
    1806                 :            :       gulong activate_id, startup_id;
    1807                 :          6 :       const GActionEntry entries[] =
    1808                 :            :         {
    1809                 :            :           { "undo", dbus_activate_action_cb, NULL, NULL,      NULL, { 0 } },
    1810                 :            :           { "lang", dbus_activate_action_cb,  "s",  "'latin'", NULL, { 0 } },
    1811                 :            :         };
    1812                 :          6 :       guint n_activations = 0;
    1813                 :            : 
    1814                 :          6 :       g_test_message ("Message %" G_GSIZE_FORMAT, i);
    1815                 :            : 
    1816                 :          6 :       app = g_application_new ("org.gtk.TestApplication.ActivateAction", G_APPLICATION_DEFAULT_FLAGS);
    1817                 :          6 :       activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
    1818                 :          6 :       startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages[i].message);
    1819                 :            : 
    1820                 :            :       /* Export some actions. */
    1821                 :          6 :       g_action_map_add_action_entries (G_ACTION_MAP (app), entries, G_N_ELEMENTS (entries), &n_activations);
    1822                 :            : 
    1823                 :          6 :       g_application_hold (app);
    1824                 :          6 :       g_application_run (app, 0, NULL);
    1825                 :            : 
    1826                 :          6 :       g_assert_cmpuint (n_activations, ==, messages[i].n_expected_activations);
    1827                 :            : 
    1828                 :          6 :       g_signal_handler_disconnect (app, startup_id);
    1829                 :          6 :       g_signal_handler_disconnect (app, activate_id);
    1830                 :          6 :       g_clear_object (&app);
    1831                 :          6 :       g_clear_object (&messages[i].message);
    1832                 :            :     }
    1833                 :            : 
    1834                 :          1 :   g_test_dbus_down (bus);
    1835                 :          1 :   g_clear_object (&bus);
    1836                 :          1 : }
    1837                 :            : 
    1838                 :            : int
    1839                 :          7 : main (int argc, char **argv)
    1840                 :            : {
    1841                 :          7 :   g_setenv ("LC_ALL", "C", TRUE);
    1842                 :            : 
    1843                 :          7 :   g_log_writer_default_set_use_stderr (TRUE);
    1844                 :            : 
    1845                 :          7 :   g_test_init (&argc, &argv, NULL);
    1846                 :            : 
    1847         [ +  + ]:          7 :   if (!g_test_subprocess ())
    1848                 :          1 :     g_test_dbus_unset ();
    1849                 :            : 
    1850                 :          7 :   g_test_add_func ("/gapplication/no-dbus", test_nodbus);
    1851                 :            : /*  g_test_add_func ("/gapplication/basic", basic); */
    1852                 :          7 :   g_test_add_func ("/gapplication/no-appid", test_noappid);
    1853                 :            : /*  g_test_add_func ("/gapplication/non-unique", test_nonunique); */
    1854                 :          7 :   g_test_add_func ("/gapplication/properties", properties);
    1855                 :          7 :   g_test_add_func ("/gapplication/app-id", appid);
    1856                 :          7 :   g_test_add_func ("/gapplication/quit", test_quit);
    1857                 :          7 :   g_test_add_func ("/gapplication/registered", test_registered);
    1858                 :          7 :   g_test_add_func ("/gapplication/local-actions", test_local_actions);
    1859                 :            : /*  g_test_add_func ("/gapplication/remote-actions", test_remote_actions); */
    1860                 :          7 :   g_test_add_func ("/gapplication/local-command-line", test_local_command_line);
    1861                 :            : /*  g_test_add_func ("/gapplication/remote-command-line", test_remote_command_line); */
    1862                 :          7 :   g_test_add_func ("/gapplication/resource-path", test_resource_path);
    1863                 :          7 :   g_test_add_func ("/gapplication/test-help", test_help);
    1864                 :          7 :   g_test_add_func ("/gapplication/command-line-done", test_command_line_done);
    1865                 :          7 :   g_test_add_func ("/gapplication/test-busy", test_busy);
    1866                 :          7 :   g_test_add_func ("/gapplication/test-handle-local-options1", test_handle_local_options_success);
    1867                 :          7 :   g_test_add_func ("/gapplication/test-handle-local-options2", test_handle_local_options_failure);
    1868                 :          7 :   g_test_add_func ("/gapplication/test-handle-local-options3", test_handle_local_options_passthrough);
    1869                 :          7 :   g_test_add_func ("/gapplication/api", test_api);
    1870                 :          7 :   g_test_add_func ("/gapplication/version", test_version);
    1871                 :          7 :   g_test_add_data_func ("/gapplication/replace", GINT_TO_POINTER (TRUE), test_replace);
    1872                 :          7 :   g_test_add_data_func ("/gapplication/no-replace", GINT_TO_POINTER (FALSE), test_replace);
    1873                 :          7 :   g_test_add_func ("/gapplication/dbus/activate", test_dbus_activate);
    1874                 :          7 :   g_test_add_func ("/gapplication/dbus/open", test_dbus_open);
    1875                 :          7 :   g_test_add_func ("/gapplication/dbus/command-line", test_dbus_command_line);
    1876                 :          7 :   g_test_add_func ("/gapplication/dbus/command-line-done", test_dbus_command_line_done);
    1877                 :          7 :   g_test_add_func ("/gapplication/dbus/activate-action", test_dbus_activate_action);
    1878                 :            : 
    1879                 :          7 :   return g_test_run ();
    1880                 :            : }

Generated by: LCOV version 1.14