]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: add basic test for getline_wrapped
authorLucas De Marchi <lucas.demarchi@intel.com>
Mon, 18 Nov 2013 07:13:59 +0000 (05:13 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 18 Nov 2013 13:01:16 +0000 (11:01 -0200)
testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt [new file with mode: 0644]
testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt [new file with mode: 0644]
testsuite/test-util.c

diff --git a/testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt b/testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt
new file mode 100644 (file)
index 0000000..87344ab
--- /dev/null
@@ -0,0 +1,6 @@
+this is the first line wrapped by one \
+2
+this is a single line
+1
+three line lines in a row
+3
diff --git a/testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt b/testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt
new file mode 100644 (file)
index 0000000..f84a852
--- /dev/null
@@ -0,0 +1,6 @@
+this is the first line \
+wrapped by one \\
+this is a single line
+three line \
+lines \
+in a row
index db9f1343d3f634f0500c82dc9b5d63f60a576ab2..4fedb246630936d89497ec1a0e5cb60162271843 100644 (file)
@@ -67,8 +67,39 @@ static DEFINE_TEST(alias_1,
                .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt",
        });
 
+static int test_getline_wrapped(const struct test *t)
+{
+       FILE *fp = fopen("/getline_wrapped-input.txt", "re");
+
+       if (!fp)
+               return EXIT_FAILURE;
+
+       while (!feof(fp) && !ferror(fp)) {
+               unsigned int num = 0;
+               char *s = getline_wrapped(fp, &num);
+               if (!s)
+                       break;
+               puts(s);
+               free(s);
+               printf("%u\n", num);
+       }
+
+       fclose(fp);
+       return EXIT_SUCCESS;
+}
+static DEFINE_TEST(test_getline_wrapped,
+       .description = "check if getline_wrapped() does the right thing",
+       .config = {
+               [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
+       },
+       .need_spawn = true,
+       .output = {
+               .out = TESTSUITE_ROOTFS "test-util/getline_wrapped-correct.txt",
+       });
+
 static const struct test *tests[] = {
        &salias_1,
+       &stest_getline_wrapped,
        NULL,
 };