diff options
author | Esteban Manchado Velázquez <emanchado@demiurgo.org> | 2012-02-03 00:12:23 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-03-08 20:49:16 -0500 |
commit | 57a4e0766557e62d90d1e3ed44643a4890b96902 (patch) | |
tree | 48f8ce9707e2504ba6c6cf4dd057646390b0e8f8 /src | |
parent | 2a720847ad691c3cbfd92eedef1b4fd90e6d214c (diff) | |
download | tor-57a4e0766557e62d90d1e3ed44643a4890b96902.tar.gz tor-57a4e0766557e62d90d1e3ed44643a4890b96902.zip |
Add quoted content tests for the config parser
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test_util.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index c7540e81a6..9866ab31c3 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -243,6 +243,60 @@ test_util_config_line(void) tor_free(v); } +static void +test_util_config_line_quotes(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, "kTrailingSpace \"quoted value\" \n" + "kTrailingGarbage \"quoted value\"trailing garbage\n" + , sizeof(buf1)); + strlcpy(buf2, "kTrailingSpaceAndGarbage \"quoted value\" trailing space+g\n" + , sizeof(buf2)); + strlcpy(buf3, "kMultilineTrailingSpace \"mline\\ \nvalue w/ trailing sp\"\n" + , sizeof(buf3)); + strlcpy(buf4, "kMultilineNoTrailingBackslash \"naked multiline\nvalue\"\n" + , sizeof(buf4)); + str = buf1; + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "kTrailingSpace"); + test_streq(v, "quoted value"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_eq_ptr(str, NULL); + 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) @@ -2105,6 +2159,7 @@ test_util_set_env_var_in_sl(void *ptr) struct testcase_t util_tests[] = { UTIL_LEGACY(time), UTIL_LEGACY(config_line), + UTIL_LEGACY(config_line_quotes), UTIL_LEGACY(strmisc), UTIL_LEGACY(pow2), UTIL_LEGACY(gzip), |