[PATCH 5/9] testsuite: add basic test for getline_wrapped

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 .../test-util/getline_wrapped-correct.txt          |  6 +++++
 .../test-util/getline_wrapped-input.txt            |  6 +++++
 testsuite/test-util.c                              | 31 ++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 testsuite/rootfs-pristine/test-util/getline_wrapped-correct.txt
 create mode 100644 testsuite/rootfs-pristine/test-util/getline_wrapped-input.txt

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,
 };
 
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux