summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-06-26 10:50:37 -0400
committerNick Mathewson <nickm@torproject.org>2012-06-26 10:50:37 -0400
commit9c8ec0aa20cda1787ee27a96e666af84f1081f5b (patch)
tree895ab19d1bde2689ca7665676824bc7c5f7aeb3d
parent201b852c277bdf4bf70a656871d502318bd5b25b (diff)
downloadtor-9c8ec0aa20cda1787ee27a96e666af84f1081f5b.tar.gz
tor-9c8ec0aa20cda1787ee27a96e666af84f1081f5b.zip
Add a unit test for environment_variable_names_equal
I need this because I'm about to frob that function to stop using strcspn() in order to get rid of a clang warning.
-rw-r--r--changes/envvar_test2
-rw-r--r--src/test/test_util.c34
2 files changed, 36 insertions, 0 deletions
diff --git a/changes/envvar_test b/changes/envvar_test
new file mode 100644
index 0000000000..d76a817078
--- /dev/null
+++ b/changes/envvar_test
@@ -0,0 +1,2 @@
+ o New unit tests:
+ - Add a unit test for the environment_variable_names_equal function. \ No newline at end of file
diff --git a/src/test/test_util.c b/src/test/test_util.c
index fab95953bd..d2d0a55520 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2869,6 +2869,39 @@ test_util_sl_new_from_text_lines(void *ptr)
}
}
+static void
+test_util_envnames(void *ptr)
+{
+ (void) ptr;
+
+ tt_assert(environment_variable_names_equal("abc", "abc"));
+ tt_assert(environment_variable_names_equal("abc", "abc="));
+ tt_assert(environment_variable_names_equal("abc", "abc=def"));
+ tt_assert(environment_variable_names_equal("abc=def", "abc"));
+ tt_assert(environment_variable_names_equal("abc=def", "abc=ghi"));
+
+ tt_assert(environment_variable_names_equal("abc", "abc"));
+ tt_assert(environment_variable_names_equal("abc", "abc="));
+ tt_assert(environment_variable_names_equal("abc", "abc=def"));
+ tt_assert(environment_variable_names_equal("abc=def", "abc"));
+ tt_assert(environment_variable_names_equal("abc=def", "abc=ghi"));
+
+ tt_assert(!environment_variable_names_equal("abc", "abcd"));
+ tt_assert(!environment_variable_names_equal("abc=", "abcd"));
+ tt_assert(!environment_variable_names_equal("abc=", "abcd"));
+ tt_assert(!environment_variable_names_equal("abc=", "def"));
+ tt_assert(!environment_variable_names_equal("abc=", "def="));
+ tt_assert(!environment_variable_names_equal("abc=x", "def=x"));
+
+ tt_assert(!environment_variable_names_equal("", "a=def"));
+ /* A bit surprising. */
+ tt_assert(environment_variable_names_equal("", "=def"));
+ tt_assert(environment_variable_names_equal("=y", "=x"));
+
+ done:
+ ;
+}
+
/** Test process_environment_make */
static void
test_util_make_environment(void *ptr)
@@ -3081,6 +3114,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(n_bits_set, 0),
UTIL_TEST(eat_whitespace, 0),
UTIL_TEST(sl_new_from_text_lines, 0),
+ UTIL_TEST(envnames, 0),
UTIL_TEST(make_environment, 0),
UTIL_TEST(set_env_var_in_sl, 0),
END_OF_TESTCASES