Commit 94c246e8 authored by Matthias Clasen's avatar Matthias Clasen

Add tests for new g_environ_ functions

parent 7a9987d3
#include <glib.h>
static void
test_environment (void)
test_listenv (void)
{
GHashTable *table;
gchar **list;
......@@ -40,12 +40,70 @@ test_environment (void)
g_strfreev (list);
}
static void
test_setenv (void)
{
const gchar *var, *value;
var = "NOSUCHENVVAR";
value = "value1";
g_assert (g_getenv (var) == NULL);
g_setenv (var, value, FALSE);
g_assert_cmpstr (g_getenv (var), ==, value);
g_assert (g_setenv (var, "value2", FALSE));
g_assert_cmpstr (g_getenv (var), ==, value);
g_assert (g_setenv (var, "value2", TRUE));
g_assert_cmpstr (g_getenv (var), ==, "value2");
g_unsetenv (var);
g_assert (g_getenv (var) == NULL);
}
static void
test_environ_array (void)
{
gchar **env;
const gchar *value;
env = g_new (gchar *, 1);
env[0] = NULL;
value = g_environ_getenv (env, "foo");
g_assert (value == NULL);
env = g_environ_setenv (env, "foo", "bar", TRUE);
value = g_environ_getenv (env, "foo");
g_assert_cmpstr (value, ==, "bar");
env = g_environ_setenv (env, "foo2", "bar2", FALSE);
value = g_environ_getenv (env, "foo");
g_assert_cmpstr (value, ==, "bar");
value = g_environ_getenv (env, "foo2");
g_assert_cmpstr (value, ==, "bar2");
env = g_environ_setenv (env, "foo", "x", FALSE);
value = g_environ_getenv (env, "foo");
g_assert_cmpstr (value, ==, "bar");
env = g_environ_setenv (env, "foo", "x", TRUE);
value = g_environ_getenv (env, "foo");
g_assert_cmpstr (value, ==, "x");
env = g_environ_unsetenv (env, "foo2");
value = g_environ_getenv (env, "foo2");
g_assert (value == NULL);
g_strfreev (env);
}
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/glib/environment", test_environment);
g_test_add_func ("/environ/listenv", test_listenv);
g_test_add_func ("/environ/setenv", test_setenv);
g_test_add_func ("/environ/array", test_environ_array);
return g_test_run ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment