10 table = g_hash_table_new_full (g_str_hash, g_str_equal,
13 list = g_get_environ ();
14 for (i = 0; list[i]; i++)
18 parts = g_strsplit (list[i], "=", 2);
19 g_assert (g_hash_table_lookup (table, parts[0]) == NULL);
20 g_hash_table_insert (table, parts[0], parts[1]);
25 g_assert_cmpint (g_hash_table_size (table), >, 0);
28 for (i = 0; list[i]; i++)
30 const gchar *expected;
33 expected = g_hash_table_lookup (table, list[i]);
34 value = g_getenv (list[i]);
35 g_assert_cmpstr (value, ==, expected);
36 g_hash_table_remove (table, list[i]);
38 g_assert_cmpint (g_hash_table_size (table), ==, 0);
39 g_hash_table_unref (table);
46 const gchar *var, *value;
51 g_assert (g_getenv (var) == NULL);
52 g_setenv (var, value, FALSE);
53 g_assert_cmpstr (g_getenv (var), ==, value);
54 g_assert (g_setenv (var, "value2", FALSE));
55 g_assert_cmpstr (g_getenv (var), ==, value);
56 g_assert (g_setenv (var, "value2", TRUE));
57 g_assert_cmpstr (g_getenv (var), ==, "value2");
59 g_assert (g_getenv (var) == NULL);
63 test_environ_array (void)
68 env = g_new (gchar *, 1);
71 value = g_environ_getenv (env, "foo");
72 g_assert (value == NULL);
74 env = g_environ_setenv (env, "foo", "bar", TRUE);
75 value = g_environ_getenv (env, "foo");
76 g_assert_cmpstr (value, ==, "bar");
78 env = g_environ_setenv (env, "foo2", "bar2", FALSE);
79 value = g_environ_getenv (env, "foo");
80 g_assert_cmpstr (value, ==, "bar");
81 value = g_environ_getenv (env, "foo2");
82 g_assert_cmpstr (value, ==, "bar2");
84 env = g_environ_setenv (env, "foo", "x", FALSE);
85 value = g_environ_getenv (env, "foo");
86 g_assert_cmpstr (value, ==, "bar");
88 env = g_environ_setenv (env, "foo", "x", TRUE);
89 value = g_environ_getenv (env, "foo");
90 g_assert_cmpstr (value, ==, "x");
92 env = g_environ_unsetenv (env, "foo2");
93 value = g_environ_getenv (env, "foo2");
94 g_assert (value == NULL);
100 test_environ_null (void)
107 value = g_environ_getenv (env, "foo");
108 g_assert (value == NULL);
110 env = g_environ_setenv (NULL, "foo", "bar", TRUE);
111 g_assert (env != NULL);
114 env = g_environ_unsetenv (NULL, "foo");
115 g_assert (env == NULL);
119 main (int argc, char **argv)
121 g_test_init (&argc, &argv, NULL);
123 g_test_add_func ("/environ/listenv", test_listenv);
124 g_test_add_func ("/environ/setenv", test_setenv);
125 g_test_add_func ("/environ/array", test_environ_array);
126 g_test_add_func ("/environ/null", test_environ_null);
128 return g_test_run ();