LCOV - code coverage report
Current view: top level - glib/gio/tests - basic-application.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 122 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 11 0.0 %
Branches: 0 52 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : #include <string.h>
       3                 :            : 
       4                 :            : static void
       5                 :          0 : new_activated (GSimpleAction *action,
       6                 :            :                GVariant      *parameter,
       7                 :            :                gpointer       user_data)
       8                 :            : {
       9                 :          0 :   GApplication *app = user_data;
      10                 :            : 
      11                 :          0 :   g_application_activate (app);
      12                 :          0 : }
      13                 :            : 
      14                 :            : static void
      15                 :          0 : quit_activated (GSimpleAction *action,
      16                 :            :                 GVariant      *parameter,
      17                 :            :                 gpointer       user_data)
      18                 :            : {
      19                 :          0 :   GApplication *app = user_data;
      20                 :            : 
      21                 :          0 :   g_application_quit (app);
      22                 :          0 : }
      23                 :            : 
      24                 :            : static void
      25                 :          0 : action1_activated (GSimpleAction *action,
      26                 :            :                    GVariant      *parameter,
      27                 :            :                    gpointer       user_data)
      28                 :            : {
      29                 :          0 :   g_print ("activate action1\n");
      30                 :          0 : }
      31                 :            : 
      32                 :            : static void
      33                 :          0 : action2_activated (GSimpleAction *action,
      34                 :            :                    GVariant      *parameter,
      35                 :            :                    gpointer       user_data)
      36                 :            : {
      37                 :            :   GVariant *state;
      38                 :            : 
      39                 :          0 :   state = g_action_get_state (G_ACTION (action));
      40                 :          0 :   g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
      41                 :          0 :   g_print ("activate action2 %d\n", !g_variant_get_boolean (state));
      42                 :          0 :   g_variant_unref (state);
      43                 :          0 : }
      44                 :            : 
      45                 :            : static void
      46                 :          0 : change_action2 (GSimpleAction *action,
      47                 :            :                 GVariant      *state,
      48                 :            :                 gpointer       user_data)
      49                 :            : {
      50                 :          0 :   g_print ("change action2 %d\n", g_variant_get_boolean (state));
      51                 :          0 : }
      52                 :            : 
      53                 :            : static void
      54                 :          0 : startup (GApplication *app)
      55                 :            : {
      56                 :            :   static GActionEntry actions[] = {
      57                 :            :     { "new", new_activated, NULL, NULL, NULL, { 0 } },
      58                 :            :     { "quit", quit_activated, NULL, NULL, NULL, { 0 } },
      59                 :            :     { "action1", action1_activated, NULL, NULL, NULL, { 0 } },
      60                 :            :     { "action2", action2_activated, "b", "false", change_action2, { 0 } }
      61                 :            :   };
      62                 :            : 
      63                 :          0 :   g_action_map_add_action_entries (G_ACTION_MAP (app),
      64                 :            :                                    actions, G_N_ELEMENTS (actions),
      65                 :            :                                    app);
      66                 :          0 : }
      67                 :            : 
      68                 :            : static void
      69                 :          0 : activate (GApplication *application)
      70                 :            : {
      71                 :          0 :   g_application_hold (application);
      72                 :          0 :   g_print ("activated\n");
      73                 :          0 :   g_application_release (application);
      74                 :          0 : }
      75                 :            : 
      76                 :            : static void
      77                 :          0 : app_open (GApplication  *application,
      78                 :            :           GFile        **files,
      79                 :            :           gint           n_files,
      80                 :            :           const gchar   *hint)
      81                 :            : {
      82                 :            :   gint i;
      83                 :            : 
      84                 :          0 :   g_application_hold (application);
      85                 :            : 
      86                 :          0 :   g_print ("open");
      87         [ #  # ]:          0 :   for (i = 0; i < n_files; i++)
      88                 :            :     {
      89                 :          0 :       gchar *uri = g_file_get_uri (files[i]);
      90                 :          0 :       g_print (" %s", uri);
      91                 :          0 :       g_free (uri);
      92                 :            :     }
      93                 :          0 :   g_print ("\n");
      94                 :            : 
      95                 :          0 :   g_application_release (application);
      96                 :          0 : }
      97                 :            : 
      98                 :            : static int
      99                 :          0 : command_line (GApplication            *application,
     100                 :            :               GApplicationCommandLine *cmdline)
     101                 :            : {
     102                 :            :   gchar **argv;
     103                 :            :   gint argc;
     104                 :            :   gint i;
     105                 :            : 
     106                 :          0 :   g_application_hold (application);
     107                 :          0 :   argv = g_application_command_line_get_arguments (cmdline, &argc);
     108                 :            : 
     109         [ #  # ]:          0 :   if (argc > 1)
     110                 :            :     {
     111         [ #  # ]:          0 :       if (g_strcmp0 (argv[1], "echo") == 0)
     112                 :            :         {
     113                 :          0 :           g_print ("cmdline");
     114         [ #  # ]:          0 :           for (i = 0; i < argc; i++)
     115                 :          0 :             g_print (" %s", argv[i]);
     116                 :          0 :           g_print ("\n");
     117                 :            :         }
     118         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "env") == 0)
     119                 :            :         {
     120                 :            :           const gchar * const *env;
     121                 :            : 
     122                 :          0 :           env = g_application_command_line_get_environ (cmdline);
     123                 :          0 :           g_print ("environment");
     124         [ #  # ]:          0 :           for (i = 0; env[i]; i++)
     125   [ #  #  #  #  :          0 :             if (g_str_has_prefix (env[i], "TEST="))
             #  #  #  # ]
     126                 :          0 :               g_print (" %s", env[i]);      
     127                 :          0 :           g_print ("\n");
     128                 :            :         }
     129         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "getenv") == 0)
     130                 :            :         {
     131                 :          0 :           g_print ("getenv TEST=%s\n", g_application_command_line_getenv (cmdline, "TEST"));
     132                 :            :         }
     133         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "print") == 0)
     134                 :            :         {
     135                 :          0 :           g_application_command_line_print (cmdline, "print %s\n", argv[2]);
     136                 :            :         }
     137         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "printerr") == 0)
     138                 :            :         {
     139                 :          0 :           g_application_command_line_printerr (cmdline, "printerr %s\n", argv[2]);
     140                 :            :         }
     141         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "file") == 0)
     142                 :            :         {
     143                 :            :           GFile *file;
     144                 :            : 
     145                 :          0 :           file = g_application_command_line_create_file_for_arg (cmdline, argv[2]);         
     146                 :          0 :           g_print ("file %s\n", g_file_get_path (file));
     147                 :          0 :           g_object_unref (file);
     148                 :            :         }
     149         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "properties") == 0)
     150                 :            :         {
     151                 :            :           gboolean remote;
     152                 :            :           GVariant *data;
     153                 :            : 
     154                 :          0 :           g_object_get (cmdline,
     155                 :            :                         "is-remote", &remote,
     156                 :            :                         NULL);
     157                 :            : 
     158                 :          0 :           data = g_application_command_line_get_platform_data (cmdline);
     159                 :          0 :           g_assert (remote);
     160                 :          0 :           g_assert (g_variant_is_of_type (data, G_VARIANT_TYPE ("a{sv}")));
     161                 :          0 :           g_variant_unref (data);
     162                 :          0 :           g_print ("properties ok\n");
     163                 :            :         }
     164         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "cwd") == 0)
     165                 :            :         {
     166                 :          0 :           g_print ("cwd %s\n", g_application_command_line_get_cwd (cmdline));
     167                 :            :         }
     168         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "busy") == 0)
     169                 :            :         {
     170                 :          0 :           g_application_mark_busy (g_application_get_default ());
     171                 :          0 :           g_print ("busy\n");
     172                 :            :         }
     173         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "idle") == 0)
     174                 :            :         {
     175                 :          0 :           g_application_unmark_busy (g_application_get_default ());
     176                 :          0 :           g_print ("idle\n");
     177                 :            :         }
     178         [ #  # ]:          0 :       else if (g_strcmp0 (argv[1], "stdin") == 0)
     179                 :            :         {
     180                 :            :           GInputStream *stream;
     181                 :            : 
     182                 :          0 :           stream = g_application_command_line_get_stdin (cmdline);
     183                 :            : 
     184                 :          0 :           g_assert (stream == NULL || G_IS_INPUT_STREAM (stream));
     185                 :          0 :           g_object_unref (stream);
     186                 :            : 
     187                 :          0 :           g_print ("stdin ok\n");
     188                 :            :         }
     189                 :            :       else
     190                 :          0 :         g_print ("unexpected command: %s\n", argv[1]);
     191                 :            :     }
     192                 :            :   else
     193                 :          0 :     g_print ("got ./cmd %d\n", g_application_command_line_get_is_remote (cmdline));
     194                 :            : 
     195                 :          0 :   g_strfreev (argv);
     196                 :          0 :   g_application_release (application);
     197                 :            : 
     198                 :          0 :   return 0;
     199                 :            : }
     200                 :            : 
     201                 :            : static gboolean
     202                 :          0 : action_cb (gpointer data)
     203                 :            : {
     204                 :          0 :   gchar **argv = data;
     205                 :            :   GApplication *app;
     206                 :            :   gchar **actions;
     207                 :            :   gint i;
     208                 :            : 
     209         [ #  # ]:          0 :   if (g_strcmp0 (argv[1], "./actions") == 0)
     210                 :            :     {
     211                 :          0 :       app = g_application_get_default ();
     212                 :            : 
     213         [ #  # ]:          0 :       if (g_strcmp0 (argv[2], "list") == 0)
     214                 :            :         {
     215                 :          0 :           g_print ("actions");
     216                 :          0 :           actions = g_action_group_list_actions (G_ACTION_GROUP (app));
     217         [ #  # ]:          0 :           for (i = 0; actions[i]; i++)
     218                 :          0 :             g_print (" %s", actions[i]);
     219                 :          0 :           g_print ("\n");
     220                 :          0 :           g_strfreev (actions);
     221                 :            :         }
     222         [ #  # ]:          0 :       else if (g_strcmp0 (argv[2], "activate") == 0)
     223                 :            :         {
     224                 :          0 :           g_action_group_activate_action (G_ACTION_GROUP (app),
     225                 :            :                                           "action1", NULL);
     226                 :            :         }
     227         [ #  # ]:          0 :       else if (g_strcmp0 (argv[2], "set-state") == 0)
     228                 :            :         {
     229                 :          0 :           g_action_group_change_action_state (G_ACTION_GROUP (app),
     230                 :            :                                               "action2",
     231                 :            :                                               g_variant_new_boolean (TRUE));
     232                 :            :         }
     233                 :          0 :       g_application_release (app);
     234                 :            :     }
     235                 :            : 
     236                 :          0 :   return G_SOURCE_REMOVE;
     237                 :            : }
     238                 :            : 
     239                 :            : int
     240                 :          0 : main (int argc, char **argv)
     241                 :            : {
     242                 :            :   GApplication *app;
     243                 :            :   int status;
     244                 :            : 
     245         [ #  # ]:          0 :   app = g_application_new ("org.gtk.TestApplication",
     246                 :            :                            G_APPLICATION_SEND_ENVIRONMENT |
     247                 :          0 :                            (g_strcmp0 (argv[1], "./cmd") == 0
     248                 :            :                              ? G_APPLICATION_HANDLES_COMMAND_LINE
     249                 :            :                              : G_APPLICATION_HANDLES_OPEN));
     250                 :          0 :   g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
     251                 :          0 :   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
     252                 :          0 :   g_signal_connect (app, "open", G_CALLBACK (app_open), NULL);
     253                 :          0 :   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
     254                 :            : #ifdef STANDALONE
     255                 :            :   g_application_set_inactivity_timeout (app, 10000);
     256                 :            : #else
     257                 :          0 :   g_application_set_inactivity_timeout (app, 1000);
     258                 :            : #endif
     259                 :            : 
     260         [ #  # ]:          0 :   if (g_strcmp0 (argv[1], "./actions") == 0)
     261                 :            :     {
     262                 :          0 :       g_application_set_inactivity_timeout (app, 0);
     263                 :          0 :       g_application_hold (app);
     264                 :          0 :       g_idle_add (action_cb, argv);
     265                 :            :     }
     266                 :            : 
     267                 :          0 :   status = g_application_run (app, argc - 1, argv + 1);
     268                 :            : 
     269                 :          0 :   g_object_unref (app);
     270                 :            : 
     271                 :          0 :   g_print ("exit status: %d\n", status);
     272                 :            : 
     273                 :          0 :   return 0;
     274                 :            : }

Generated by: LCOV version 1.14