diff options
author | Alexander Færøy <ahf@torproject.org> | 2018-11-26 04:59:12 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-17 16:39:28 -0500 |
commit | 289ed0849d9b473cd0fbafada30c03638d73e541 (patch) | |
tree | 2d101bb9108619d9c47250049957d5ea1d7eaff7 /src/test/test_process.c | |
parent | 9b6a10a26f25e0da07e62bd5617b519b0952b40a (diff) | |
download | tor-289ed0849d9b473cd0fbafada30c03638d73e541.tar.gz tor-289ed0849d9b473cd0fbafada30c03638d73e541.zip |
Add tests for process environment functionality of process_t.
This patch adds tests for the process_environment_t interaction in
process_t.
See: https://bugs.torproject.org/28179
Diffstat (limited to 'src/test/test_process.c')
-rw-r--r-- | src/test/test_process.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/test_process.c b/src/test/test_process.c index 4f86e786cb..2fcb3f6686 100644 --- a/src/test/test_process.c +++ b/src/test/test_process.c @@ -9,6 +9,7 @@ #include "orconfig.h" #include "core/or/or.h" #include "test/test.h" +#include "lib/process/env.h" #define PROCESS_PRIVATE #include "lib/process/process.h" @@ -173,6 +174,56 @@ test_default_values(void *arg) } static void +test_environment(void *arg) +{ + (void)arg; + process_init(); + + process_t *process = process_new(""); + process_environment_t *env = NULL; + + process_set_environment(process, "E", "F"); + process_set_environment(process, "C", "D"); + process_set_environment(process, "A", "B"); + + env = process_get_environment(process); + tt_mem_op(env->windows_environment_block, OP_EQ, + "A=B\0C=D\0E=F\0", 12); + tt_str_op(env->unixoid_environment_block[0], OP_EQ, + "A=B"); + tt_str_op(env->unixoid_environment_block[1], OP_EQ, + "C=D"); + tt_str_op(env->unixoid_environment_block[2], OP_EQ, + "E=F"); + tt_ptr_op(env->unixoid_environment_block[3], OP_EQ, + NULL); + process_environment_free(env); + + /* Reset our environment. */ + smartlist_t *new_env = smartlist_new(); + smartlist_add(new_env, (char *)"FOO=bar"); + smartlist_add(new_env, (char *)"HELLO=world"); + + process_reset_environment(process, new_env); + smartlist_free(new_env); + + env = process_get_environment(process); + tt_mem_op(env->windows_environment_block, OP_EQ, + "FOO=bar\0HELLO=world\0", 20); + tt_str_op(env->unixoid_environment_block[0], OP_EQ, + "FOO=bar"); + tt_str_op(env->unixoid_environment_block[1], OP_EQ, + "HELLO=world"); + tt_ptr_op(env->unixoid_environment_block[2], OP_EQ, + NULL); + + done: + process_environment_free(env); + process_free(process); + process_free_all(); +} + +static void test_stringified_types(void *arg) { (void)arg; @@ -589,6 +640,7 @@ test_win32(void *arg) struct testcase_t process_tests[] = { { "default_values", test_default_values, TT_FORK, NULL, NULL }, + { "environment", test_environment, TT_FORK, NULL, NULL }, { "stringified_types", test_stringified_types, TT_FORK, NULL, NULL }, { "line_protocol_simple", test_line_protocol_simple, TT_FORK, NULL, NULL }, { "line_protocol_multi", test_line_protocol_multi, TT_FORK, NULL, NULL }, |