diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-18 05:13:59 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-18 11:01:16 -0200 |
commit | 1dda626f6b2ba5975467a5507277d632f615a5ce (patch) | |
tree | 9504ccae3b65a8a188dfe055ac82ceac33686042 | |
parent | b93d800640ca4ebe433400abcf743d9521b3f58a (diff) | |
download | kmod-1dda626f6b2ba5975467a5507277d632f615a5ce.tar.gz |
testsuite: add basic test for getline_wrapped
-rw-r--r-- | testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt | 6 | ||||
-rw-r--r-- | testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt | 6 | ||||
-rw-r--r-- | testsuite/test-util.c | 31 |
3 files changed, 43 insertions, 0 deletions
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 0000000..87344ab --- /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 0000000..f84a852 --- /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 db9f134..4fedb24 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, }; |