[tor-commits] [tor/master] Add testcase for too few elements in tokenize_string() input

nickm at torproject.org nickm at torproject.org
Wed Oct 24 13:08:21 UTC 2018


commit 7c8bf2f7c7adbae3b0f56631c2a2c036076b322d
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Tue Oct 16 15:22:48 2018 +0300

    Add testcase for too few elements in tokenize_string() input
---
 src/test/test_parsecommon.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/test/test_parsecommon.c b/src/test/test_parsecommon.c
index 0c754a8fe..e68d0fb88 100644
--- a/src/test/test_parsecommon.c
+++ b/src/test/test_parsecommon.c
@@ -80,6 +80,36 @@ test_parsecommon_tokenize_string_multiple_lines(void *arg)
 }
 
 static void
+test_parsecommon_tokenize_string_min_cnt(void *arg)
+{
+  memarea_t *area = memarea_new();
+  smartlist_t *tokens = smartlist_new();
+
+  (void)arg;
+
+  token_rule_t table[] = {
+          T01("uptime", K_UPTIME, EQ(2), NO_OBJ),
+          T01("hibernating", K_HIBERNATING, GE(1), NO_OBJ),
+          END_OF_TABLE,
+  };
+
+  // Missing "uptime"
+  char *str = tor_strdup("uptime 1024\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();
@@ -425,6 +455,7 @@ test_parsecommon_get_next_token_err_bad_base64(void *arg)
 struct testcase_t parsecommon_tests[] = {
   PARSECOMMON_TEST(tokenize_string_null),
   PARSECOMMON_TEST(tokenize_string_multiple_lines),
+  PARSECOMMON_TEST(tokenize_string_min_cnt),
   PARSECOMMON_TEST(get_next_token_success),
   PARSECOMMON_TEST(get_next_token_concat_args),
   PARSECOMMON_TEST(get_next_token_parse_keys),





More information about the tor-commits mailing list