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 if (g_strcmp0 (parts
[0], ""))
21 g_hash_table_insert (table
, parts
[0], parts
[1]);
26 g_assert_cmpint (g_hash_table_size (table
), >, 0);
29 for (i
= 0; list
[i
]; i
++)
31 const gchar
*expected
;
34 expected
= g_hash_table_lookup (table
, list
[i
]);
35 value
= g_getenv (list
[i
]);
36 g_assert_cmpstr (value
, ==, expected
);
37 g_hash_table_remove (table
, list
[i
]);
39 g_assert_cmpint (g_hash_table_size (table
), ==, 0);
40 g_hash_table_unref (table
);
47 const gchar
*var
, *value
;
52 g_assert (g_getenv (var
) == NULL
);
53 g_setenv (var
, value
, FALSE
);
54 g_assert_cmpstr (g_getenv (var
), ==, value
);
55 g_assert (g_setenv (var
, "value2", FALSE
));
56 g_assert_cmpstr (g_getenv (var
), ==, value
);
57 g_assert (g_setenv (var
, "value2", TRUE
));
58 g_assert_cmpstr (g_getenv (var
), ==, "value2");
60 g_assert (g_getenv (var
) == NULL
);
64 test_environ_array (void)
69 env
= g_new (gchar
*, 1);
72 value
= g_environ_getenv (env
, "foo");
73 g_assert (value
== NULL
);
75 env
= g_environ_setenv (env
, "foo", "bar", TRUE
);
76 value
= g_environ_getenv (env
, "foo");
77 g_assert_cmpstr (value
, ==, "bar");
79 env
= g_environ_setenv (env
, "foo2", "bar2", FALSE
);
80 value
= g_environ_getenv (env
, "foo");
81 g_assert_cmpstr (value
, ==, "bar");
82 value
= g_environ_getenv (env
, "foo2");
83 g_assert_cmpstr (value
, ==, "bar2");
85 env
= g_environ_setenv (env
, "foo", "x", FALSE
);
86 value
= g_environ_getenv (env
, "foo");
87 g_assert_cmpstr (value
, ==, "bar");
89 env
= g_environ_setenv (env
, "foo", "x", TRUE
);
90 value
= g_environ_getenv (env
, "foo");
91 g_assert_cmpstr (value
, ==, "x");
93 env
= g_environ_unsetenv (env
, "foo2");
94 value
= g_environ_getenv (env
, "foo2");
95 g_assert (value
== NULL
);
101 test_environ_null (void)
108 value
= g_environ_getenv (env
, "foo");
109 g_assert (value
== NULL
);
111 env
= g_environ_setenv (NULL
, "foo", "bar", TRUE
);
112 g_assert (env
!= NULL
);
115 env
= g_environ_unsetenv (NULL
, "foo");
116 g_assert (env
== NULL
);
120 main (int argc
, char **argv
)
122 g_test_init (&argc
, &argv
, NULL
);
124 g_test_add_func ("/environ/listenv", test_listenv
);
125 g_test_add_func ("/environ/setenv", test_setenv
);
126 g_test_add_func ("/environ/array", test_environ_array
);
127 g_test_add_func ("/environ/null", test_environ_null
);
129 return g_test_run ();