diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-09-21 14:36:12 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-09-25 14:41:02 +0200 |
commit | 8526644b08722ce6cb0c7b050ada8127e1702746 (patch) | |
tree | 8eb160f8d87d427f6a35d2c4c6cb2826d028a568 /src/test/test-conf-parser.c | |
parent | bb37bf113ec83d58e6b6225e0b0f74deb638f85b (diff) |
test-conf-parser: add tests for the new long lines, including overflow handling
Diffstat (limited to 'src/test/test-conf-parser.c')
-rw-r--r-- | src/test/test-conf-parser.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index ef8a85a47..caac43822 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -235,6 +235,10 @@ static void test_config_parse_iec_uint64(void) { } #endif // 0 +#define x10(x) x x x x x x x x x x +#define x100(x) x10(x10(x)) +#define x1000(x) x10(x100(x)) + static const char* const config_file[] = { "[Section]\n" "setting1=1\n", @@ -261,6 +265,24 @@ static const char* const config_file[] = { "\\\\2\n", /* note that C requires one level of escaping, so the * parser gets "…1 BS BS BS NL BS BS 2 NL", which * it translates into "…1 BS BS SP BS BS 2" */ + + "\n[Section]\n\n" + "setting1=" /* a line above LINE_MAX length */ + x1000("ABCD") + "\n", + + "[Section]\n" + "setting1=" /* a line above LINE_MAX length, with continuation */ + x1000("ABCD") "\\\n" + "foobar", + + "[Section]\n" + "setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */ + x1000(x1000("x") x10("abcde")) "\n", + + "[Section]\n" + "setting1=" /* many continuation lines, together above the limit */ + x1000(x1000("x") x10("abcde") "\\\n") "xxx", }; static void test_config_parse(unsigned i, const char *s) { @@ -300,20 +322,37 @@ static void test_config_parse(unsigned i, const char *s) { "Section\0", config_item_table_lookup, items, false, false, true, NULL); - assert_se(r == 0); switch (i) { case 0 ... 3: + assert_se(r == 0); assert_se(streq(setting1, "1")); break; case 4: + assert_se(r == 0); assert_se(streq(setting1, "1 2 3")); break; case 5: + assert_se(r == 0); assert_se(streq(setting1, "1\\\\ \\\\2")); break; + + case 6: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD"))); + break; + + case 7: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD") " foobar")); + break; + + case 8 ... 9: + assert_se(r == -ENOBUFS); + assert_se(setting1 == NULL); + break; } } |