diff --git a/tests/.gitignore b/tests/.gitignore index 6cfb8396be..10ba484ea8 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -15,6 +15,7 @@ /fsync /ftruncate /getid +/getc_unget /link /math /mem @@ -27,6 +28,8 @@ /sprintf /stdlib/strtol /stdlib/a64l +/stdio/fwrite +/stdio/all /string/strncmp /string/strcspn /string/strchr diff --git a/tests/Makefile b/tests/Makefile index a252889605..43b5512399 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,6 +12,8 @@ EXPECT_BINS=\ fcntl \ fsync \ ftruncate \ + getid \ + getc_unget \ link \ math \ mem \ @@ -20,6 +22,8 @@ EXPECT_BINS=\ rmdir \ sleep \ sprintf \ + stdio/fwrite \ + stdio/all \ stdlib/strtol \ stdlib/a64l \ string/strncmp \ diff --git a/tests/getc_unget.c b/tests/getc_unget.c new file mode 100644 index 0000000000..f8008534fb --- /dev/null +++ b/tests/getc_unget.c @@ -0,0 +1,12 @@ +#include + +int main(int argc, char ** argv) { + ungetc('h', stdin); + char c; + if ((c = getchar()) == 'h') { + printf("Worked!\n"); + return 0; + } + printf("failed :( %c\n", c); + return 0; +} diff --git a/tests/stdio/all.c b/tests/stdio/all.c new file mode 100644 index 0000000000..450829364e --- /dev/null +++ b/tests/stdio/all.c @@ -0,0 +1,11 @@ +#include +#include + +int main(int argc, char ** argv) { + FILE *f = fopen("stdio/stdio.in", "r"); + printf("%c\n", fgetc(f)); + ungetc('H', f); + char *in = malloc(30); + printf("%s\n", fgets(in, 30, f)); + return 0; +} diff --git a/tests/stdio/fwrite.c b/tests/stdio/fwrite.c new file mode 100644 index 0000000000..da172d5b58 --- /dev/null +++ b/tests/stdio/fwrite.c @@ -0,0 +1,11 @@ +#include +#include +#include + +int main(int argc, char ** argv) { + FILE *f = fopen("stdio/fwrite.out", "w"); + char *in = "Hello World!"; + fputs(in, f); // calls fwrite, helpers::fwritex, internal::to_write and internal::stdio_write + fclose(f); + return 0; +} diff --git a/tests/stdio/fwrite.out b/tests/stdio/fwrite.out new file mode 100644 index 0000000000..c57eff55eb --- /dev/null +++ b/tests/stdio/fwrite.out @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/tests/stdio/stdio.in b/tests/stdio/stdio.in new file mode 100644 index 0000000000..c50d87bb17 --- /dev/null +++ b/tests/stdio/stdio.in @@ -0,0 +1,3 @@ +Hello World! + +Line 2