summaryrefslogtreecommitdiff
path: root/test/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'test/stdio')
-rw-r--r--test/stdio/Makefile8
-rw-r--r--test/stdio/Makefile.in10
-rw-r--r--test/stdio/lseek_no_lfs.c22
-rw-r--r--test/stdio/scanf_m.c24
-rw-r--r--test/stdio/tst-fmemopen.c53
5 files changed, 114 insertions, 3 deletions
diff --git a/test/stdio/Makefile b/test/stdio/Makefile
index d3ae2f368..95b930b9d 100644
--- a/test/stdio/Makefile
+++ b/test/stdio/Makefile
@@ -1,6 +1,8 @@
-# uClibc assert tests
+# uClibc stdio tests
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+top_builddir=../../
+top_srcdir=../../
+include ../Rules.mak
+-include Makefile.in
include ../Test.mak
-
-DODIFF_64bit := 1
diff --git a/test/stdio/Makefile.in b/test/stdio/Makefile.in
new file mode 100644
index 000000000..3e60b4090
--- /dev/null
+++ b/test/stdio/Makefile.in
@@ -0,0 +1,10 @@
+# uClibc stdio tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+DODIFF_64bit := 1
+
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),)
+TESTS_DISABLED += tst-fmemopen
+endif
+
+CFLAGS_tst-fmemopen = -fPIC
diff --git a/test/stdio/lseek_no_lfs.c b/test/stdio/lseek_no_lfs.c
new file mode 100644
index 000000000..54daf6b48
--- /dev/null
+++ b/test/stdio/lseek_no_lfs.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, char *argv[])
+{
+ FILE * f = fopen(argv[0], "rb");
+ if (!f)
+ {
+ printf("Error: Can't open %s, reason: %s\n", argv[0], strerror(errno));
+ return 1;
+ }
+
+ if (fseek(f, (unsigned)4096, (int)SEEK_SET) == -1)
+ {
+ printf("Test failed, fseek return fail code. errno=%u (%s)\n", errno, strerror(errno));
+ return 1;
+ }
+
+ fclose(f);
+ return 0;
+}
diff --git a/test/stdio/scanf_m.c b/test/stdio/scanf_m.c
new file mode 100644
index 000000000..0ce78b6e4
--- /dev/null
+++ b/test/stdio/scanf_m.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void)
+{
+ const char *buf = "hello world";
+ char *ps = NULL, *pc = NULL;
+ char s[6], c;
+
+ /* Check that %[...]/%c work. */
+ sscanf(buf, "%[a-z] %c", s, &c);
+ /* Check that %m[...]/%mc work. */
+ sscanf(buf, "%m[a-z] %mc", &ps, &pc);
+
+ if (strcmp(ps, "hello") != 0 || *pc != 'w' ||
+ strcmp(s, "hello") != 0 || c != 'w')
+ return 1;
+
+ free(ps);
+ free(pc);
+
+ return 0;
+}
diff --git a/test/stdio/tst-fmemopen.c b/test/stdio/tst-fmemopen.c
new file mode 100644
index 000000000..384faa1c9
--- /dev/null
+++ b/test/stdio/tst-fmemopen.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *text_input = "1 23 43";
+
+static const char *good_answer = "1 529 1849 ";
+
+
+static int
+do_test (void)
+{
+ FILE *out, *in;
+ int v, s;
+ size_t size;
+ char *ptr;
+
+ in = fmemopen(text_input, strlen(text_input), "r");
+ if (in == NULL) {
+ perror("fmemopen");
+ return 1;
+ }
+
+ out = open_memstream(&ptr, &size);
+ if (out == NULL) {
+ perror("open_memstream");
+ return 1;
+ }
+
+ for (;;) {
+ s = fscanf(in, "%d", &v);
+ if (s <= 0)
+ break;
+
+ s = fprintf(out, "%d ", v * v);
+ if (s == -1) {
+ puts("fprintf failed");
+ exit(1);
+ }
+ }
+ fclose(in);
+ fclose(out);
+
+ if (size != strlen(good_answer) || strcmp(good_answer, ptr) != 0) {
+ printf("failed: size=%zu; ptr=%s\n", size, ptr);
+ exit(1);
+ }
+ free(ptr);
+ exit(0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"