From: Lucas De Marchi Date: Mon, 18 Nov 2013 07:13:59 +0000 (-0200) Subject: testsuite: add basic test for getline_wrapped X-Git-Tag: v16~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1dda626f6b2ba5975467a5507277d632f615a5ce;p=thirdparty%2Fkmod.git testsuite: add basic test for getline_wrapped --- 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 index 00000000..87344ab0 --- /dev/null +++ b/testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt @@ -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 index 00000000..f84a8520 --- /dev/null +++ b/testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt @@ -0,0 +1,6 @@ +this is the first line \ +wrapped by one \\ +this is a single line +three line \ +lines \ +in a row diff --git a/testsuite/test-util.c b/testsuite/test-util.c index db9f1343..4fedb246 100644 --- a/testsuite/test-util.c +++ b/testsuite/test-util.c @@ -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, };