aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_parsecommon.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-10-16 15:54:11 +0300
committerrl1987 <rl1987@sdf.lonestar.org>2018-10-16 18:04:54 +0300
commitf10d664fd14b318fba23c7290c800590d0a474b4 (patch)
tree92004997ec3bef15b9de728564aedef1f940b96c /src/test/test_parsecommon.c
parent1a4edceee9049d19a97b08dc28e87fa346d02536 (diff)
downloadtor-f10d664fd14b318fba23c7290c800590d0a474b4.tar.gz
tor-f10d664fd14b318fba23c7290c800590d0a474b4.zip
Test AT_END checking in tokenize_string()
Diffstat (limited to 'src/test/test_parsecommon.c')
-rw-r--r--src/test/test_parsecommon.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/test_parsecommon.c b/src/test/test_parsecommon.c
index 182f6fba5d..13e4ac8c7f 100644
--- a/src/test/test_parsecommon.c
+++ b/src/test/test_parsecommon.c
@@ -141,6 +141,66 @@ test_parsecommon_tokenize_string_max_cnt(void *arg)
}
static void
+test_parsecommon_tokenize_string_at_start(void *arg)
+{
+ memarea_t *area = memarea_new();
+ smartlist_t *tokens = smartlist_new();
+
+ (void)arg;
+
+ token_rule_t table[] = {
+ T1_START("client-name", C_CLIENT_NAME, CONCAT_ARGS, NO_OBJ),
+ T01("uptime", K_UPTIME, EQ(1), NO_OBJ),
+ END_OF_TABLE,
+ };
+
+ // "client-name" is not the first line.
+ char *str = tor_strdup(
+ "uptime 1024\nclient-name Alice\n");
+
+ int retval =
+ tokenize_string(area, str, NULL, tokens, table, 0);
+
+ tt_int_op(retval, OP_EQ, -1);
+
+ done:
+ tor_free(str);
+ memarea_drop_all(area);
+ smartlist_free(tokens);
+ return;
+}
+
+static void
+test_parsecommon_tokenize_string_at_end(void *arg)
+{
+ memarea_t *area = memarea_new();
+ smartlist_t *tokens = smartlist_new();
+
+ (void)arg;
+
+ token_rule_t table[] = {
+ T1_END("client-name", C_CLIENT_NAME, CONCAT_ARGS, NO_OBJ),
+ T01("uptime", K_UPTIME, EQ(1), NO_OBJ),
+ END_OF_TABLE,
+ };
+
+ // "client-name" is not the last line.
+ char *str = tor_strdup(
+ "client-name Alice\nuptime 1024\n");
+
+ int retval =
+ tokenize_string(area, str, NULL, tokens, table, 0);
+
+ tt_int_op(retval, OP_EQ, -1);
+
+ done:
+ tor_free(str);
+ memarea_drop_all(area);
+ smartlist_free(tokens);
+ return;
+}
+
+static void
test_parsecommon_get_next_token_success(void *arg)
{
memarea_t *area = memarea_new();
@@ -488,6 +548,8 @@ struct testcase_t parsecommon_tests[] = {
PARSECOMMON_TEST(tokenize_string_multiple_lines),
PARSECOMMON_TEST(tokenize_string_min_cnt),
PARSECOMMON_TEST(tokenize_string_max_cnt),
+ PARSECOMMON_TEST(tokenize_string_at_start),
+ PARSECOMMON_TEST(tokenize_string_at_end),
PARSECOMMON_TEST(get_next_token_success),
PARSECOMMON_TEST(get_next_token_concat_args),
PARSECOMMON_TEST(get_next_token_parse_keys),