[glib] Add testcase for environment functions
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add testcase for environment functions
- Date: Fri, 29 Oct 2010 02:21:18 +0000 (UTC)
commit 99d2c2eef580c6ee4cbcf18b656e574331d6ad08
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Oct 28 22:20:25 2010 -0400
Add testcase for environment functions
glib/tests/.gitignore | 1 +
glib/tests/Makefile.am | 3 ++
glib/tests/environment.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/.gitignore b/glib/tests/.gitignore
index a2c75e7..9b1b214 100644
--- a/glib/tests/.gitignore
+++ b/glib/tests/.gitignore
@@ -6,6 +6,7 @@ collate
convert
date
dir
+environment
error
fileutils
gdatetime
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 0d54cae..d3d6f66 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -148,6 +148,9 @@ TEST_PROGS += gdatetime
gdatetime_SOURCES = gdatetime.c
gdatetime_LDADD = $(progs_ldadd)
+TEST_PROGS += environment
+environment_LDADD = $(progs_ldadd)
+
if OS_UNIX
# some testing of gtester funcitonality
diff --git a/glib/tests/environment.c b/glib/tests/environment.c
new file mode 100644
index 0000000..7b313d1
--- /dev/null
+++ b/glib/tests/environment.c
@@ -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 ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]