mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-04 18:18:56 +01:00
tests: Use G_TEST_OPTION_ISOLATE_DIRS for utils tests
Another test isolated. This does mean moving one of the test cases from the suite out into a separate suite, as it explicitly relies on running without `G_TEST_OPTION_ISOLATE_DIRS`, and I think that makes sense. The other test cases run fine when isolated. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
@@ -185,6 +185,7 @@ glib_tests = {
|
|||||||
'c_standards': c_standards.keys(),
|
'c_standards': c_standards.keys(),
|
||||||
},
|
},
|
||||||
'utils-isolated' : {},
|
'utils-isolated' : {},
|
||||||
|
'utils-unisolated' : {},
|
||||||
'unicode' : {},
|
'unicode' : {},
|
||||||
'unicode-encoding' : {},
|
'unicode-encoding' : {},
|
||||||
'unicode-normalize': {},
|
'unicode-normalize': {},
|
||||||
|
|||||||
110
glib/tests/utils-unisolated.c
Normal file
110
glib/tests/utils-unisolated.c
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
/* Unit tests for utilities
|
||||||
|
* Copyright (C) 2010 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LicenseRef-old-glib-tests
|
||||||
|
*
|
||||||
|
* This work is provided "as is"; redistribution and modification
|
||||||
|
* in whole or in part, in any medium, physical or electronic is
|
||||||
|
* permitted without restriction.
|
||||||
|
*
|
||||||
|
* This work is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* In no event shall the authors or contributors be liable for any
|
||||||
|
* direct, indirect, incidental, special, exemplary, or consequential
|
||||||
|
* damages (including, but not limited to, procurement of substitute
|
||||||
|
* goods or services; loss of use, data, or profits; or business
|
||||||
|
* interruption) however caused and on any theory of liability, whether
|
||||||
|
* in contract, strict liability, or tort (including negligence or
|
||||||
|
* otherwise) arising in any way out of the use of this software, even
|
||||||
|
* if advised of the possibility of such damage.
|
||||||
|
*
|
||||||
|
* Author: Matthias Clasen
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_xdg_dirs (void)
|
||||||
|
{
|
||||||
|
#ifdef G_OS_UNIX
|
||||||
|
char *xdg = NULL;
|
||||||
|
const char *dir;
|
||||||
|
const char * const *dirs;
|
||||||
|
char *s = NULL;
|
||||||
|
|
||||||
|
xdg = g_strdup (g_getenv ("XDG_CONFIG_HOME"));
|
||||||
|
if (!xdg)
|
||||||
|
xdg = g_build_filename (g_get_home_dir (), ".config", NULL);
|
||||||
|
|
||||||
|
dir = g_get_user_config_dir ();
|
||||||
|
|
||||||
|
g_assert_cmpstr (dir, ==, xdg);
|
||||||
|
g_free (xdg);
|
||||||
|
|
||||||
|
xdg = g_strdup (g_getenv ("XDG_DATA_HOME"));
|
||||||
|
if (!xdg)
|
||||||
|
xdg = g_build_filename (g_get_home_dir (), ".local", "share", NULL);
|
||||||
|
|
||||||
|
dir = g_get_user_data_dir ();
|
||||||
|
|
||||||
|
g_assert_cmpstr (dir, ==, xdg);
|
||||||
|
g_free (xdg);
|
||||||
|
|
||||||
|
xdg = g_strdup (g_getenv ("XDG_CACHE_HOME"));
|
||||||
|
if (!xdg)
|
||||||
|
xdg = g_build_filename (g_get_home_dir (), ".cache", NULL);
|
||||||
|
|
||||||
|
dir = g_get_user_cache_dir ();
|
||||||
|
|
||||||
|
g_assert_cmpstr (dir, ==, xdg);
|
||||||
|
g_free (xdg);
|
||||||
|
|
||||||
|
xdg = g_strdup (g_getenv ("XDG_STATE_HOME"));
|
||||||
|
if (!xdg)
|
||||||
|
xdg = g_build_filename (g_get_home_dir (), ".local/state", NULL);
|
||||||
|
|
||||||
|
dir = g_get_user_state_dir ();
|
||||||
|
|
||||||
|
g_assert_cmpstr (dir, ==, xdg);
|
||||||
|
g_free (xdg);
|
||||||
|
|
||||||
|
xdg = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
|
||||||
|
if (!xdg)
|
||||||
|
xdg = g_strdup (g_get_user_cache_dir ());
|
||||||
|
|
||||||
|
dir = g_get_user_runtime_dir ();
|
||||||
|
|
||||||
|
g_assert_cmpstr (dir, ==, xdg);
|
||||||
|
g_free (xdg);
|
||||||
|
|
||||||
|
xdg = (gchar *)g_getenv ("XDG_CONFIG_DIRS");
|
||||||
|
if (!xdg)
|
||||||
|
xdg = "/etc/xdg";
|
||||||
|
|
||||||
|
dirs = g_get_system_config_dirs ();
|
||||||
|
|
||||||
|
s = g_strjoinv (":", (gchar **)dirs);
|
||||||
|
|
||||||
|
g_assert_cmpstr (s, ==, xdg);
|
||||||
|
|
||||||
|
g_free (s);
|
||||||
|
#else
|
||||||
|
g_test_skip ("User special dirs are not defined using environment variables on non-Unix systems");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc,
|
||||||
|
char *argv[])
|
||||||
|
{
|
||||||
|
/* Note: We do *not* use G_TEST_OPTION_ISOLATE_DIRS here, as we want to test
|
||||||
|
* the calculation of the XDG dirs from a real environment. */
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
/* You almost certainly want to add a test to glib/tests/utils.c instead of here. */
|
||||||
|
g_test_add_func ("/utils/xdgdirs", test_xdg_dirs);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
||||||
@@ -817,74 +817,6 @@ test_hostname (void)
|
|||||||
g_assert_true (g_utf8_validate (name, -1, NULL));
|
g_assert_true (g_utf8_validate (name, -1, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
|
||||||
static void
|
|
||||||
test_xdg_dirs (void)
|
|
||||||
{
|
|
||||||
gchar *xdg;
|
|
||||||
const gchar *dir;
|
|
||||||
const gchar * const *dirs;
|
|
||||||
gchar *s;
|
|
||||||
|
|
||||||
xdg = g_strdup (g_getenv ("XDG_CONFIG_HOME"));
|
|
||||||
if (!xdg)
|
|
||||||
xdg = g_build_filename (g_get_home_dir (), ".config", NULL);
|
|
||||||
|
|
||||||
dir = g_get_user_config_dir ();
|
|
||||||
|
|
||||||
g_assert_cmpstr (dir, ==, xdg);
|
|
||||||
g_free (xdg);
|
|
||||||
|
|
||||||
xdg = g_strdup (g_getenv ("XDG_DATA_HOME"));
|
|
||||||
if (!xdg)
|
|
||||||
xdg = g_build_filename (g_get_home_dir (), ".local", "share", NULL);
|
|
||||||
|
|
||||||
dir = g_get_user_data_dir ();
|
|
||||||
|
|
||||||
g_assert_cmpstr (dir, ==, xdg);
|
|
||||||
g_free (xdg);
|
|
||||||
|
|
||||||
xdg = g_strdup (g_getenv ("XDG_CACHE_HOME"));
|
|
||||||
if (!xdg)
|
|
||||||
xdg = g_build_filename (g_get_home_dir (), ".cache", NULL);
|
|
||||||
|
|
||||||
dir = g_get_user_cache_dir ();
|
|
||||||
|
|
||||||
g_assert_cmpstr (dir, ==, xdg);
|
|
||||||
g_free (xdg);
|
|
||||||
|
|
||||||
xdg = g_strdup (g_getenv ("XDG_STATE_HOME"));
|
|
||||||
if (!xdg)
|
|
||||||
xdg = g_build_filename (g_get_home_dir (), ".local/state", NULL);
|
|
||||||
|
|
||||||
dir = g_get_user_state_dir ();
|
|
||||||
|
|
||||||
g_assert_cmpstr (dir, ==, xdg);
|
|
||||||
g_free (xdg);
|
|
||||||
|
|
||||||
xdg = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
|
|
||||||
if (!xdg)
|
|
||||||
xdg = g_strdup (g_get_user_cache_dir ());
|
|
||||||
|
|
||||||
dir = g_get_user_runtime_dir ();
|
|
||||||
|
|
||||||
g_assert_cmpstr (dir, ==, xdg);
|
|
||||||
g_free (xdg);
|
|
||||||
|
|
||||||
xdg = (gchar *)g_getenv ("XDG_CONFIG_DIRS");
|
|
||||||
if (!xdg)
|
|
||||||
xdg = "/etc/xdg";
|
|
||||||
|
|
||||||
dirs = g_get_system_config_dirs ();
|
|
||||||
|
|
||||||
s = g_strjoinv (":", (gchar **)dirs);
|
|
||||||
|
|
||||||
g_assert_cmpstr (s, ==, xdg);
|
|
||||||
|
|
||||||
g_free (s);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_special_dir (void)
|
test_special_dir (void)
|
||||||
{
|
{
|
||||||
@@ -1353,7 +1285,7 @@ main (int argc,
|
|||||||
*/
|
*/
|
||||||
g_set_prgname (argv[0]);
|
g_set_prgname (argv[0]);
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/utils/language-names", test_language_names);
|
g_test_add_func ("/utils/language-names", test_language_names);
|
||||||
g_test_add_func ("/utils/locale-variants", test_locale_variants);
|
g_test_add_func ("/utils/locale-variants", test_locale_variants);
|
||||||
@@ -1374,9 +1306,6 @@ main (int argc,
|
|||||||
g_test_add_func ("/utils/username", test_username);
|
g_test_add_func ("/utils/username", test_username);
|
||||||
g_test_add_func ("/utils/realname", test_realname);
|
g_test_add_func ("/utils/realname", test_realname);
|
||||||
g_test_add_func ("/utils/hostname", test_hostname);
|
g_test_add_func ("/utils/hostname", test_hostname);
|
||||||
#ifdef G_OS_UNIX
|
|
||||||
g_test_add_func ("/utils/xdgdirs", test_xdg_dirs);
|
|
||||||
#endif
|
|
||||||
g_test_add_func ("/utils/specialdir", test_special_dir);
|
g_test_add_func ("/utils/specialdir", test_special_dir);
|
||||||
g_test_add_func ("/utils/specialdir/desktop", test_desktop_special_dir);
|
g_test_add_func ("/utils/specialdir/desktop", test_desktop_special_dir);
|
||||||
g_test_add_func ("/utils/os-info", test_os_info);
|
g_test_add_func ("/utils/os-info", test_os_info);
|
||||||
|
|||||||
Reference in New Issue
Block a user