[glib] Add tests for new g_environ_ functions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add tests for new g_environ_ functions
- Date: Sat, 15 Oct 2011 20:28:57 +0000 (UTC)
commit 94c246e8e3816d05971e9a825cf15769b04e8098
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Oct 15 16:28:07 2011 -0400
Add tests for new g_environ_ functions
glib/tests/environment.c | 62 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/glib/tests/environment.c b/glib/tests/environment.c
index 7b313d1..1e4698c 100644
--- a/glib/tests/environment.c
+++ b/glib/tests/environment.c
@@ -1,7 +1,7 @@
#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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]