LCOV - code coverage report
Current view: top level - gio/tests - sandbox.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 100.0 % 34 34
Test Date: 2024-11-26 05:23:01 Functions: 100.0 % 5 5
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2022 Canonical Ltd
       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                 :             : 
      20                 :             : #include "portal-support-utils.h"
      21                 :             : 
      22                 :             : #include "../gsandbox.h"
      23                 :             : #include <gio/gio.h>
      24                 :             : #include <glib/gstdio.h>
      25                 :             : 
      26                 :             : static void
      27                 :           1 : test_sandbox_none (void)
      28                 :             : {
      29                 :           1 :   g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_UNKNOWN);
      30                 :           1 : }
      31                 :             : 
      32                 :             : static void
      33                 :           1 : test_sandbox_snap (void)
      34                 :             : {
      35                 :             :   const char *temp_dir;
      36                 :             :   gchar *snap_path;
      37                 :             : 
      38                 :           1 :   temp_dir = g_getenv ("G_TEST_TMPDIR");
      39                 :           1 :   g_assert_nonnull (temp_dir);
      40                 :             : 
      41                 :           1 :   snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
      42                 :           1 :   create_fake_snap_yaml (snap_path, FALSE);
      43                 :           1 :   g_setenv ("SNAP", snap_path, TRUE);
      44                 :             : 
      45                 :           1 :   g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_SNAP);
      46                 :             : 
      47                 :           1 :   g_unsetenv ("SNAP");
      48                 :           1 :   g_free (snap_path);
      49                 :           1 : }
      50                 :             : 
      51                 :             : static void
      52                 :           1 : test_sandbox_snap_classic (void)
      53                 :             : {
      54                 :             :   const char *temp_dir;
      55                 :             :   char *snap_path;
      56                 :             : 
      57                 :           1 :   temp_dir = g_getenv ("G_TEST_TMPDIR");
      58                 :           1 :   g_assert_nonnull (temp_dir);
      59                 :             : 
      60                 :           1 :   snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
      61                 :           1 :   create_fake_snap_yaml (snap_path, TRUE);
      62                 :           1 :   g_setenv ("SNAP", snap_path, TRUE);
      63                 :             : 
      64                 :           1 :   g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_UNKNOWN);
      65                 :             : 
      66                 :           1 :   g_unsetenv ("SNAP");
      67                 :           1 :   g_free (snap_path);
      68                 :           1 : }
      69                 :             : 
      70                 :             : static void
      71                 :           1 : test_sandbox_flatpak (void)
      72                 :             : {
      73                 :           1 :   create_fake_flatpak_info (g_get_user_runtime_dir (), NULL, NULL);
      74                 :           1 :   g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_FLATPAK);
      75                 :           1 : }
      76                 :             : 
      77                 :             : int
      78                 :           1 : main (int argc, char **argv)
      79                 :             : {
      80                 :           1 :   g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
      81                 :             : 
      82                 :           1 :   g_test_add_func ("/sandbox/none", test_sandbox_none);
      83                 :           1 :   g_test_add_func ("/sandbox/snap", test_sandbox_snap);
      84                 :           1 :   g_test_add_func ("/sandbox/classic-snap", test_sandbox_snap_classic);
      85                 :           1 :   g_test_add_func ("/sandbox/flatpak", test_sandbox_flatpak);
      86                 :             : 
      87                 :           1 :   return g_test_run ();
      88                 :             : }
        

Generated by: LCOV version 2.0-1