summaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-01-02 06:59:12 +0000
committerNick Mathewson <nickm@torproject.org>2008-01-02 06:59:12 +0000
commit86f5180853e4054c6a14dda69253bccf6ea50a4c (patch)
tree7e271734bc756086974a0b4047d94034087e22bb /src/or/test.c
parentc0ec2815652842bdb2b533c2a8ddd125f26730fb (diff)
downloadtor-86f5180853e4054c6a14dda69253bccf6ea50a4c.tar.gz
tor-86f5180853e4054c6a14dda69253bccf6ea50a4c.zip
r15786@tombo: nickm | 2008-01-02 01:11:51 -0500
Push the strdups used for parsing configuration lines into parse_line_from_string(). This will make it easier to parse more complex value formats, which in turn will help fix bug 557 svn:r13020
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 23bae48209..20bbc49102 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -682,6 +682,7 @@ test_util(void)
uint32_t u32;
uint16_t u16;
char *cp, *k, *v;
+ const char *str;
start.tv_sec = 5;
start.tv_usec = 5000;
@@ -821,52 +822,60 @@ test_util(void)
U64_PRINTF_ARG(U64_LITERAL(12345678901)));
test_streq(buf, "x!12345678901!x");
- /* Test parse_line_from_str */
+ /* Test parse_config_line_from_str */
strlcpy(buf, "k v\n" " key value with spaces \n" "keykey val\n"
"k2\n"
"k3 \n" "\n" " \n" "#comment\n"
"k4#a\n" "k5#abc\n" "k6 val #with comment\n", sizeof(buf));
- cp = buf;
+ str = buf;
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k");
test_streq(v, "v");
- test_assert(!strcmpstart(cp, " key value with"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, " key value with"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "key");
test_streq(v, "value with spaces");
- test_assert(!strcmpstart(cp, "keykey"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "keykey"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "keykey");
test_streq(v, "val");
- test_assert(!strcmpstart(cp, "k2\n"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "k2\n"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k2");
test_streq(v, "");
- test_assert(!strcmpstart(cp, "k3 \n"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "k3 \n"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k3");
test_streq(v, "");
- test_assert(!strcmpstart(cp, "\n \n"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "\n \n"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k4");
test_streq(v, "");
- test_assert(!strcmpstart(cp, "k5#abc"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "k5#abc"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k5");
test_streq(v, "");
- test_assert(!strcmpstart(cp, "k6"));
+ tor_free(k); tor_free(v);
+ test_assert(!strcmpstart(str, "k6"));
- cp = parse_line_from_str(cp, &k, &v);
+ str = parse_config_line_from_str(str, &k, &v);
test_streq(k, "k6");
test_streq(v, "val");
- test_streq(cp, "");
+ tor_free(k); tor_free(v);
+ test_streq(str, "");
/* Test for strcmpstart and strcmpend. */
test_assert(strcmpstart("abcdef", "abcdef")==0);