diff options
author | George Kadianakis <desnacked@riseup.net> | 2012-12-17 14:14:09 +0200 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2013-02-09 16:30:16 +0000 |
commit | b8532bcb1ec51fcfae4ceff869be116fec4ccbb9 (patch) | |
tree | a7b042c5ecadcbe9de92ef9cda232c32a0129b83 /src/test/test_util.c | |
parent | d86a45f991693cf2367a6ccb94fc29c22f5f7b45 (diff) | |
download | tor-b8532bcb1ec51fcfae4ceff869be116fec4ccbb9.tar.gz tor-b8532bcb1ec51fcfae4ceff869be116fec4ccbb9.zip |
Add utility functions needed for SOCKS argument parsing.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index bed33fac25..b41f23571b 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -795,6 +795,54 @@ test_util_expand_filename(void) } #endif +/** Test tor_escape_str_for_socks_arg(). */ +static void +test_util_escape_string_socks(void) +{ + char *escaped_string = NULL; + + /** Simple backslash escape. */ + escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\"); + test_assert(escaped_string); + test_streq(escaped_string, "This is a backslash: \\\\"); + tor_free(escaped_string); + + /** Simple semicolon escape. */ + escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;"); + test_assert(escaped_string); + test_streq(escaped_string, "First rule: Do not use \\;"); + tor_free(escaped_string); + + /** Ilegal: Empty string. */ + escaped_string = tor_escape_str_for_socks_arg(""); + test_assert(!escaped_string); + + /** Escape all characters. */ + escaped_string = tor_escape_str_for_socks_arg(";\\;\\"); + test_assert(escaped_string); + test_streq(escaped_string, "\\;\\\\\\;\\\\"); + tor_free(escaped_string); + + done: + tor_free(escaped_string); +} + +static void +test_util_string_is_key_value(void *ptr) +{ + (void)ptr; + test_assert(string_is_key_value("key=value")); + test_assert(string_is_key_value("k=v")); + test_assert(string_is_key_value("key=")); + test_assert(!string_is_key_value("=value")); + test_assert(!string_is_key_value("=")); + + /* ??? */ + /* test_assert(!string_is_key_value("===")); */ + done: + ; +} + /** Test basic string functionality. */ static void test_util_strmisc(void) @@ -3271,6 +3319,8 @@ struct testcase_t util_tests[] = { #ifndef _WIN32 UTIL_LEGACY(expand_filename), #endif + UTIL_LEGACY(escape_string_socks), + UTIL_LEGACY(string_is_key_value), UTIL_LEGACY(strmisc), UTIL_LEGACY(pow2), UTIL_LEGACY(gzip), |