mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 02:36:19 +01:00
Add testcase for environment functions
This commit is contained in:
parent
29ce7385bb
commit
99d2c2eef5
1
glib/tests/.gitignore
vendored
1
glib/tests/.gitignore
vendored
@ -6,6 +6,7 @@ collate
|
|||||||
convert
|
convert
|
||||||
date
|
date
|
||||||
dir
|
dir
|
||||||
|
environment
|
||||||
error
|
error
|
||||||
fileutils
|
fileutils
|
||||||
gdatetime
|
gdatetime
|
||||||
|
@ -148,6 +148,9 @@ TEST_PROGS += gdatetime
|
|||||||
gdatetime_SOURCES = gdatetime.c
|
gdatetime_SOURCES = gdatetime.c
|
||||||
gdatetime_LDADD = $(progs_ldadd)
|
gdatetime_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
TEST_PROGS += environment
|
||||||
|
environment_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
if OS_UNIX
|
if OS_UNIX
|
||||||
|
|
||||||
# some testing of gtester funcitonality
|
# some testing of gtester funcitonality
|
||||||
|
51
glib/tests/environment.c
Normal file
51
glib/tests/environment.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_environment (void)
|
||||||
|
{
|
||||||
|
GHashTable *table;
|
||||||
|
gchar **list;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
table = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
g_free, g_free);
|
||||||
|
|
||||||
|
list = g_get_environ ();
|
||||||
|
for (i = 0; list[i]; i++)
|
||||||
|
{
|
||||||
|
gchar **parts;
|
||||||
|
|
||||||
|
parts = g_strsplit (list[i], "=", 2);
|
||||||
|
g_assert (g_hash_table_lookup (table, parts[0]) == NULL);
|
||||||
|
g_hash_table_insert (table, parts[0], parts[1]);
|
||||||
|
g_free (parts);
|
||||||
|
}
|
||||||
|
g_strfreev (list);
|
||||||
|
|
||||||
|
g_assert_cmpint (g_hash_table_size (table), >, 0);
|
||||||
|
|
||||||
|
list = g_listenv ();
|
||||||
|
for (i = 0; list[i]; i++)
|
||||||
|
{
|
||||||
|
const gchar *expected;
|
||||||
|
const gchar *value;
|
||||||
|
|
||||||
|
expected = g_hash_table_lookup (table, list[i]);
|
||||||
|
value = g_getenv (list[i]);
|
||||||
|
g_assert_cmpstr (value, ==, expected);
|
||||||
|
g_hash_table_remove (table, list[i]);
|
||||||
|
}
|
||||||
|
g_assert_cmpint (g_hash_table_size (table), ==, 0);
|
||||||
|
g_hash_table_unref (table);
|
||||||
|
g_strfreev (list);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/glib/environment", test_environment);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user