LCOV - code coverage report
Current view: top level - glib/gio/tests - application-command-line.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 45 45 100.0 %
Date: 2024-04-23 05:16:05 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright © 2022 Endless OS Foundation, LLC
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General
      17                 :            :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Author: Philip Withnall <pwithnall@endlessos.org>
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <gio/gio.h>
      23                 :            : #include <locale.h>
      24                 :            : 
      25                 :            : 
      26                 :            : static void
      27                 :          1 : test_basic_properties (void)
      28                 :            : {
      29                 :          1 :   GApplicationCommandLine *cl = NULL;
      30                 :          1 :   const gchar * const arguments[] = { "arg1", "arg2", "arg3", NULL };
      31                 :          1 :   GVariantBuilder options_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
      32                 :          1 :   GVariantBuilder platform_data_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
      33                 :          1 :   gchar **argv = NULL;
      34                 :          1 :   int argc = 0;
      35                 :            :   GVariantDict *options_dict;
      36                 :            :   GVariant *platform_data;
      37                 :          1 :   GVariantDict *platform_data_dict = NULL;
      38                 :            :   gboolean is_remote;
      39                 :            : 
      40                 :            :   /* Basic construction. */
      41                 :          1 :   g_variant_builder_add (&options_builder, "{sv}", "option1", g_variant_new_string ("value1"));
      42                 :          1 :   g_variant_builder_add (&options_builder, "{sv}", "option2", g_variant_new_string ("value2"));
      43                 :            : 
      44                 :          1 :   g_variant_builder_add (&platform_data_builder, "{sv}", "data1", g_variant_new_string ("data-value1"));
      45                 :          1 :   g_variant_builder_add (&platform_data_builder, "{sv}", "data2", g_variant_new_string ("data-value2"));
      46                 :            : 
      47                 :          1 :   cl = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
      48                 :            :                      "arguments", g_variant_new_bytestring_array (arguments, -1),
      49                 :            :                      "options", g_variant_builder_end (&options_builder),
      50                 :            :                      "platform-data", g_variant_builder_end (&platform_data_builder),
      51                 :            :                      NULL);
      52                 :          1 :   g_assert_nonnull (cl);
      53                 :            : 
      54                 :            :   /* Check the getters. */
      55                 :          1 :   argv = g_application_command_line_get_arguments (cl, &argc);
      56                 :          1 :   g_assert_cmpint (argc, ==, 3);
      57                 :          4 :   g_assert_cmpstrv (argv, arguments);
      58                 :          1 :   g_clear_pointer (&argv, g_strfreev);
      59                 :            : 
      60                 :          1 :   options_dict = g_application_command_line_get_options_dict (cl);
      61                 :          1 :   g_assert_nonnull (options_dict);
      62                 :          1 :   g_assert_true (g_variant_dict_contains (options_dict, "option1"));
      63                 :          1 :   g_assert_true (g_variant_dict_contains (options_dict, "option2"));
      64                 :            : 
      65                 :          1 :   g_assert_false (g_application_command_line_get_is_remote (cl));
      66                 :            : 
      67                 :          1 :   platform_data = g_application_command_line_get_platform_data (cl);
      68                 :          1 :   g_assert_nonnull (platform_data);
      69                 :          1 :   platform_data_dict = g_variant_dict_new (platform_data);
      70                 :          1 :   g_assert_true (g_variant_dict_contains (platform_data_dict, "data1"));
      71                 :          1 :   g_assert_true (g_variant_dict_contains (platform_data_dict, "data2"));
      72                 :          1 :   g_variant_dict_unref (platform_data_dict);
      73                 :          1 :   g_variant_unref (platform_data);
      74                 :            : 
      75                 :            :   /* And g_object_get(). */
      76                 :          1 :   g_object_get (cl, "is-remote", &is_remote, NULL);
      77                 :          1 :   g_assert_false (is_remote);
      78                 :            : 
      79                 :            :   /* exit status */
      80                 :          1 :   g_assert_cmpint (g_application_command_line_get_exit_status (cl), ==, 0);
      81                 :          1 :   g_application_command_line_set_exit_status (cl, 1);
      82                 :          1 :   g_assert_cmpint (g_application_command_line_get_exit_status (cl), ==, 1);
      83                 :            : 
      84                 :          1 :   g_application_command_line_done (cl);
      85                 :          1 :   g_application_command_line_set_exit_status (cl, 2);
      86                 :          1 :   g_assert_cmpint (g_application_command_line_get_exit_status (cl), ==, 1);
      87                 :            : 
      88                 :          1 :   g_clear_object (&cl);
      89                 :          1 : }
      90                 :            : 
      91                 :            : int
      92                 :          1 : main (int   argc,
      93                 :            :       char *argv[])
      94                 :            : {
      95                 :          1 :   setlocale (LC_ALL, "");
      96                 :          1 :   g_test_init (&argc, &argv, NULL);
      97                 :            : 
      98                 :          1 :   g_test_add_func ("/application-command-line/basic-properties", test_basic_properties);
      99                 :            : 
     100                 :          1 :   return g_test_run ();
     101                 :            : }

Generated by: LCOV version 1.14