Branch data Line data Source code
1 : : /* Copyright (C) 2022 Marco Trevisan 2 : : * 3 : : * SPDX-License-Identifier: LGPL-2.1-or-later 4 : : * 5 : : * This library is free software; you can redistribute it and/or 6 : : * modify it under the terms of the GNU Lesser General Public 7 : : * License as published by the Free Software Foundation; either 8 : : * version 2.1 of the License, or (at your option) any later version. 9 : : * 10 : : * This library is distributed in the hope that it will be useful, 11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 : : * Lesser General Public License for more details. 14 : : * 15 : : * You should have received a copy of the GNU Lesser General 16 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. 17 : : * 18 : : * Author: Marco Trevisan <marco.trevisan@canonical.com> 19 : : */ 20 : : 21 : : #include "config.h" 22 : : 23 : : #include <glib/glib.h> 24 : : 25 : : /* Test that all of the well-known directories returned by GLib 26 : : * are returned as children of test_tmpdir when running with 27 : : * %G_TEST_OPTION_ISOLATE_DIRS. This ensures that tests should 28 : : * not interfere with each other in `/tmp` while running. 29 : : */ 30 : : 31 : : const char *test_tmpdir; 32 : : 33 : : static void 34 : 1 : test_tmp_dir (void) 35 : : { 36 : 1 : g_assert_cmpstr (g_get_tmp_dir (), ==, test_tmpdir); 37 : 1 : } 38 : : 39 : : static void 40 : 1 : test_home_dir (void) 41 : : { 42 : 1 : g_assert_true (g_str_has_prefix (g_get_home_dir (), test_tmpdir)); 43 : 1 : } 44 : : 45 : : static void 46 : 1 : test_user_cache_dir (void) 47 : : { 48 : 1 : g_assert_true (g_str_has_prefix (g_get_user_cache_dir (), test_tmpdir)); 49 : 1 : } 50 : : 51 : : static void 52 : 1 : test_system_config_dirs (void) 53 : : { 54 : : const char *const *dir; 55 : : 56 [ + + ]: 3 : for (dir = g_get_system_config_dirs (); *dir != NULL; dir++) 57 : 2 : g_assert_true (g_str_has_prefix (*dir, test_tmpdir)); 58 : 1 : } 59 : : 60 : : static void 61 : 1 : test_user_config_dir (void) 62 : : { 63 : 1 : g_assert_true (g_str_has_prefix (g_get_user_config_dir (), test_tmpdir)); 64 : 1 : } 65 : : 66 : : static void 67 : 1 : test_system_data_dirs (void) 68 : : { 69 : : const char *const *dir; 70 : : 71 [ + + ]: 3 : for (dir = g_get_system_data_dirs (); *dir != NULL; dir++) 72 : 2 : g_assert_true (g_str_has_prefix (*dir, test_tmpdir)); 73 : 1 : } 74 : : 75 : : static void 76 : 1 : test_user_data_dir (void) 77 : : { 78 : 1 : g_assert_true (g_str_has_prefix (g_get_user_data_dir (), test_tmpdir)); 79 : 1 : } 80 : : 81 : : static void 82 : 1 : test_user_state_dir (void) 83 : : { 84 : 1 : g_assert_true (g_str_has_prefix (g_get_user_state_dir (), test_tmpdir)); 85 : 1 : } 86 : : 87 : : static void 88 : 1 : test_user_runtime_dir (void) 89 : : { 90 : 1 : g_assert_true (g_str_has_prefix (g_get_user_runtime_dir (), test_tmpdir)); 91 : 1 : } 92 : : 93 : : 94 : : int 95 : 1 : main (int argc, 96 : : char *argv[]) 97 : : { 98 : 1 : g_setenv ("LC_ALL", "C", TRUE); 99 : 1 : g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); 100 : : 101 : 1 : test_tmpdir = g_getenv ("G_TEST_TMPDIR"); 102 : 1 : g_assert_nonnull (test_tmpdir); 103 : : 104 : 1 : g_test_add_func ("/utils-isolated/tmp-dir", test_tmp_dir); 105 : 1 : g_test_add_func ("/utils-isolated/home-dir", test_home_dir); 106 : 1 : g_test_add_func ("/utils-isolated/user-cache-dir", test_user_cache_dir); 107 : 1 : g_test_add_func ("/utils-isolated/system-config-dirs", test_system_config_dirs); 108 : 1 : g_test_add_func ("/utils-isolated/user-config-dir", test_user_config_dir); 109 : 1 : g_test_add_func ("/utils-isolated/system-data-dirs", test_system_data_dirs); 110 : 1 : g_test_add_func ("/utils-isolated/user-data-dir", test_user_data_dir); 111 : 1 : g_test_add_func ("/utils-isolated/user-state-dir", test_user_state_dir); 112 : 1 : g_test_add_func ("/utils-isolated/user-runtime-dir", test_user_runtime_dir); 113 : 1 : return g_test_run (); 114 : : }