summaryrefslogtreecommitdiff
path: root/source4/lib/replace/test
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-03-12 09:59:48 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:27 -0500
commitd358087227727a9a8e8661c8eae2990115f8fb80 (patch)
tree1dcc444d1fee9c460d0fc8d7f43d644c1d583035 /source4/lib/replace/test
parent544a2d30e01b5f4f9849c9aa631e0525062c2707 (diff)
downloadsamba-d358087227727a9a8e8661c8eae2990115f8fb80.tar.gz
samba-d358087227727a9a8e8661c8eae2990115f8fb80.tar.bz2
samba-d358087227727a9a8e8661c8eae2990115f8fb80.zip
r21794: add setenv()/unsetenv() testsuite
metze (This used to be commit 3df206ddfadea5bf39a22e8c4c262764c79d302c)
Diffstat (limited to 'source4/lib/replace/test')
-rw-r--r--source4/lib/replace/test/testsuite.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c
index effbdb13ef..c2f5ff9a6b 100644
--- a/source4/lib/replace/test/testsuite.c
+++ b/source4/lib/replace/test/testsuite.c
@@ -171,7 +171,67 @@ static int test_timegm(void)
static int test_setenv(void)
{
- /* FIXME */
+#define TEST_SETENV(key, value, overwrite, result) do { \
+ int _ret; \
+ char *_v; \
+ _ret = setenv(key, value, overwrite); \
+ if (_ret != 0) { \
+ printf("failure: setenv [\n" \
+ "setenv(%s, %s, %d) failed\n" \
+ "]\n", \
+ key, value, overwrite); \
+ return false; \
+ } \
+ _v=getenv(key); \
+ if (!_v) { \
+ printf("failure: setenv [\n" \
+ "getenv(%s) returned NULL\n" \
+ "]\n", \
+ key); \
+ return false; \
+ } \
+ if (strcmp(result, _v) != 0) { \
+ printf("failure: setenv [\n" \
+ "getenv(%s): '%s' != '%s'\n" \
+ "]\n", \
+ key, result, _v); \
+ return false; \
+ } \
+} while(0)
+
+#define TEST_UNSETENV(key) do { \
+ int _ret; \
+ char *_v; \
+ _ret = unsetenv(key); \
+ if (_ret != 0) { \
+ printf("failure: setenv [\n" \
+ "unsetenv(%s) failed\n" \
+ "]\n", \
+ key); \
+ return false; \
+ } \
+ _v=getenv(key); \
+ if (_v) { \
+ printf("failure: setenv [\n" \
+ "getenv(%s): NULL != '%s'\n" \
+ "]\n", \
+ SETENVTEST_KEY, _v); \
+ return false; \
+ } \
+} while (0)
+
+#define SETENVTEST_KEY "SETENVTESTKEY"
+#define SETENVTEST_VAL "SETENVTESTVAL"
+
+ printf("test: setenv\n");
+ TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1");
+ TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1");
+ TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3");
+ TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4");
+ TEST_UNSETENV(SETENVTEST_KEY);
+ TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5");
+ TEST_UNSETENV(SETENVTEST_KEY);
+ printf("success: setenv\n");
return true;
}