diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-10-16 15:31:47 +0300 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2018-10-16 18:04:54 +0300 |
commit | 1a4edceee9049d19a97b08dc28e87fa346d02536 (patch) | |
tree | b77ee20df64773a88fda0a3be7e6f2c8124c4fa8 | |
parent | 7c8bf2f7c7adbae3b0f56631c2a2c036076b322d (diff) | |
download | tor-1a4edceee9049d19a97b08dc28e87fa346d02536.tar.gz tor-1a4edceee9049d19a97b08dc28e87fa346d02536.zip |
Add testcase for too many elements in tokenize_string() input
-rw-r--r-- | src/test/test_parsecommon.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/test_parsecommon.c b/src/test/test_parsecommon.c index e68d0fb884..182f6fba5d 100644 --- a/src/test/test_parsecommon.c +++ b/src/test/test_parsecommon.c @@ -110,6 +110,37 @@ test_parsecommon_tokenize_string_min_cnt(void *arg) } static void +test_parsecommon_tokenize_string_max_cnt(void *arg) +{ + memarea_t *area = memarea_new(); + smartlist_t *tokens = smartlist_new(); + + (void)arg; + + token_rule_t table[] = { + T01("uptime", K_UPTIME, EQ(1), NO_OBJ), + T01("hibernating", K_HIBERNATING, GE(1), NO_OBJ), + END_OF_TABLE, + }; + + // "uptime" expected once, but occurs twice in input. + char *str = tor_strdup( + "uptime 1024\nuptime 2048\nhibernating 0\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(); @@ -456,6 +487,7 @@ struct testcase_t parsecommon_tests[] = { PARSECOMMON_TEST(tokenize_string_null), PARSECOMMON_TEST(tokenize_string_multiple_lines), PARSECOMMON_TEST(tokenize_string_min_cnt), + PARSECOMMON_TEST(tokenize_string_max_cnt), PARSECOMMON_TEST(get_next_token_success), PARSECOMMON_TEST(get_next_token_concat_args), PARSECOMMON_TEST(get_next_token_parse_keys), |