[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Add quoted content tests for the config parser
commit 57a4e0766557e62d90d1e3ed44643a4890b96902
Author: Esteban Manchado Velázquez <emanchado@xxxxxxxxxxxx>
Date: Fri Feb 3 00:12:23 2012 +0100
Add quoted content tests for the config parser
---
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 c7540e8..9866ab3 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),
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits