chiark / gitweb /
test-conf-parser: add tests for the new long lines, including overflow handling
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Sep 2017 12:36:12 +0000 (14:36 +0200)
committerSven Eden <yamakuzure@gmx.net>
Mon, 25 Sep 2017 12:41:02 +0000 (14:41 +0200)
src/test/test-conf-parser.c

index ef8a85a478142574a43a3967828cbf0e8e5405a4..caac438224d43b6aadc0472f7777e216c835a776 100644 (file)
@@ -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;
         }
 }