LCOV - code coverage report
Current view: top level - glib/gio/tests - gapplication-example-cmdline4.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 22 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 3 0.0 %
Branches: 0 4 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : #include <stdlib.h>
       3                 :            : #include <string.h>
       4                 :            : 
       5                 :            : 
       6                 :            : static gint
       7                 :          0 : handle_local_options (GApplication      *application,
       8                 :            :                       GVariantDict      *options,
       9                 :            :                       gpointer           user_data)
      10                 :            : {
      11                 :            :   guint32 count;
      12                 :            : 
      13                 :            :   /* Deal (locally) with version option */
      14         [ #  # ]:          0 :   if (g_variant_dict_lookup (options, "version", "b", &count))
      15                 :            :     {
      16                 :          0 :       g_print ("This is example-cmdline4, version 1.2.3\n");
      17                 :          0 :       return EXIT_SUCCESS;
      18                 :            :     }
      19                 :            : 
      20                 :          0 :   return -1;
      21                 :            : 
      22                 :            : }
      23                 :            : 
      24                 :            : static gint
      25                 :          0 : command_line (GApplication                *application,
      26                 :            :               GApplicationCommandLine     *cmdline,
      27                 :            :               gpointer                     user_data)
      28                 :            : {
      29                 :            :   guint32 count;
      30                 :            : 
      31                 :          0 :   GVariantDict *options = g_application_command_line_get_options_dict (cmdline);
      32                 :            : 
      33                 :            :   /* Deal with arg option */
      34         [ #  # ]:          0 :   if (g_variant_dict_lookup (options, "flag", "b", &count))
      35                 :            :     {
      36                 :          0 :       g_application_command_line_print (cmdline, "flag is set\n");
      37                 :            :     }
      38                 :            : 
      39                 :          0 :   return EXIT_SUCCESS;
      40                 :            : }
      41                 :            : 
      42                 :            : 
      43                 :            : int
      44                 :          0 : main (int argc, char **argv)
      45                 :            : {
      46                 :            :   GApplication *app;
      47                 :            :   int status;
      48                 :            : 
      49                 :          0 :   GOptionEntry entries[] = {
      50                 :            :     /* A version flag option, to be handled locally */
      51                 :            :     { "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Show the application version", NULL },
      52                 :            : 
      53                 :            :     /* A dummy flag option, to be handled in primary */
      54                 :            :     { "flag", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "A flag argument", NULL },
      55                 :            : 
      56                 :            :     G_OPTION_ENTRY_NULL
      57                 :            :   };
      58                 :            : 
      59                 :          0 :   app = g_application_new ("org.gtk.TestApplication",
      60                 :            :                            G_APPLICATION_HANDLES_COMMAND_LINE);
      61                 :            : 
      62                 :          0 :   g_application_add_main_option_entries (app, entries);
      63                 :            : 
      64                 :          0 :   g_application_set_option_context_parameter_string (app, "- a simple command line example");
      65                 :          0 :   g_application_set_option_context_summary (app,
      66                 :            :                                             "Summary:\n"
      67                 :            :                                             "This is a simple command line --help example.");
      68                 :          0 :   g_application_set_option_context_description (app,
      69                 :            :                                                 "Description:\n"
      70                 :            :                                                 "This example illustrates the use of "
      71                 :            :                                                 "g_application command line --help functionalities "
      72                 :            :                                                 "(parameter string, summary, description). "
      73                 :            :                                                 "It does nothing at all except displaying information "
      74                 :            :                                                 "when invoked with --help argument...\n");
      75                 :            : 
      76                 :          0 :   g_signal_connect (app, "handle-local-options", G_CALLBACK (handle_local_options), NULL);
      77                 :          0 :   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
      78                 :            : 
      79                 :            :   /* This application does absolutely nothing, except if a command line is given */
      80                 :          0 :   status = g_application_run (app, argc, argv);
      81                 :            : 
      82                 :          0 :   g_object_unref (app);
      83                 :            : 
      84                 :          0 :   return status;
      85                 :            : }

Generated by: LCOV version 1.14