diff options
author | Esteban Manchado Velázquez <emanchado@demiurgo.org> | 2012-02-03 20:52:34 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-03-08 20:49:17 -0500 |
commit | 4d9dda9bb9129fa7996c077a2f98c65e6b123178 (patch) | |
tree | 3c8b8f185ff0fa247aefa98a8987a7d88eae6b56 /src/test/test_util.c | |
parent | 57a4e0766557e62d90d1e3ed44643a4890b96902 (diff) | |
download | tor-4d9dda9bb9129fa7996c077a2f98c65e6b123178.tar.gz tor-4d9dda9bb9129fa7996c077a2f98c65e6b123178.zip |
Add tests for escaped content in config
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 9866ab31c3..86c650eeae 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -297,6 +297,107 @@ test_util_config_line_quotes(void) tor_free(v); } +static void +test_util_config_line_escaped_content(void) +{ + char buf1[1024]; + char buf2[128]; + char buf3[128]; + char buf4[128]; + char *k=NULL, *v=NULL; + const char *str; + + /* Test parse_config_line_from_str */ + strlcpy(buf1, "HexadecimalLower \"\\x2a\"\n" + "HexadecimalUpper \"\\x2A\"\n" + "HexadecimalUpperX \"\\X2A\"\n" + "Octal \"\\52\"\n" + "Newline \"\\n\"\n" + "Tab \"\\t\"\n" + "CarriageReturn \"\\r\"\n" + "Quote \"\\\"\"\n" + "Backslash \"\\\\\"\n" + , sizeof(buf1)); + + strlcpy(buf2, "BrokenEscapedContent \"\\a\"\n" + , sizeof(buf2)); + + strlcpy(buf3, "BrokenEscapedContent \"\\x\"\n" + , sizeof(buf3)); + + strlcpy(buf4, "BrokenOctal \"\\8\"\n" + , sizeof(buf4)); + + str = buf1; + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "HexadecimalLower"); + test_streq(v, "*"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "HexadecimalUpper"); + test_streq(v, "*"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "HexadecimalUpperX"); + test_streq(v, "*"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "Octal"); + test_streq(v, "*"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "Newline"); + test_streq(v, "\n"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "Tab"); + test_streq(v, "\t"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "CarriageReturn"); + test_streq(v, "\r"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "Quote"); + test_streq(v, "\""); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "Backslash"); + test_streq(v, "\\"); + tor_free(k); tor_free(v); + + str = buf2; + + str = parse_config_line_from_str(str, &k, &v); + test_eq_ptr(str, NULL); + tor_free(k); tor_free(v); + + str = buf3; + + str = parse_config_line_from_str(str, &k, &v); + test_eq_ptr(str, NULL); + tor_free(k); tor_free(v); + + str = buf4; + + str = parse_config_line_from_str(str, &k, &v); + test_eq_ptr(str, NULL); + tor_free(k); tor_free(v); + + done: + tor_free(k); + tor_free(v); +} + /** Test basic string functionality. */ static void test_util_strmisc(void) @@ -2160,6 +2261,7 @@ struct testcase_t util_tests[] = { UTIL_LEGACY(time), UTIL_LEGACY(config_line), UTIL_LEGACY(config_line_quotes), + UTIL_LEGACY(config_line_escaped_content), UTIL_LEGACY(strmisc), UTIL_LEGACY(pow2), UTIL_LEGACY(gzip), |