103 lines
1.6 KiB
C
103 lines
1.6 KiB
C
#include <criterion/criterion.h>
|
|
#include <stdio.h>
|
|
|
|
#include "io.h"
|
|
|
|
/*
|
|
** TESTS: io/streams.c
|
|
*/
|
|
|
|
Test(io, open_with_files)
|
|
{
|
|
t_io io;
|
|
int8_t ret;
|
|
|
|
FILE *f = fopen("/tmp/test_io_in.md", "w");
|
|
fprintf(f, "test\n");
|
|
fclose(f);
|
|
|
|
ret = io_open(&io, "/tmp/test_io_in.md", "/tmp/test_io_out.c");
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_not_null(io.in);
|
|
cr_assert_not_null(io.out);
|
|
cr_assert_neq(io.in, stdin);
|
|
cr_assert_neq(io.out, stdout);
|
|
|
|
io_close(&io);
|
|
remove("/tmp/test_io_in.md");
|
|
remove("/tmp/test_io_out.c");
|
|
}
|
|
|
|
Test(io, open_with_stdin_stdout)
|
|
{
|
|
t_io io;
|
|
int8_t ret;
|
|
|
|
ret = io_open(&io, NULL, NULL);
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_eq(io.in, stdin);
|
|
cr_assert_eq(io.out, stdout);
|
|
|
|
io_close(&io);
|
|
}
|
|
|
|
Test(io, open_with_invalid_input)
|
|
{
|
|
t_io io;
|
|
int8_t ret;
|
|
|
|
ret = io_open(&io, "/tmp/nonexistent_file_123456.md", "/tmp/test_io_out.c");
|
|
|
|
cr_assert_eq(ret, 1);
|
|
}
|
|
|
|
Test(io, open_input_only)
|
|
{
|
|
t_io io;
|
|
int8_t ret;
|
|
|
|
FILE *f = fopen("/tmp/test_io_input.md", "w");
|
|
fprintf(f, "test\n");
|
|
fclose(f);
|
|
|
|
ret = io_open(&io, "/tmp/test_io_input.md", NULL);
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_not_null(io.in);
|
|
cr_assert_neq(io.in, stdin);
|
|
cr_assert_eq(io.out, stdout);
|
|
|
|
io_close(&io);
|
|
remove("/tmp/test_io_input.md");
|
|
}
|
|
|
|
Test(io, open_output_only)
|
|
{
|
|
t_io io;
|
|
int8_t ret;
|
|
|
|
ret = io_open(&io, NULL, "/tmp/test_io_output.c");
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_eq(io.in, stdin);
|
|
cr_assert_not_null(io.out);
|
|
cr_assert_neq(io.out, stdout);
|
|
|
|
io_close(&io);
|
|
remove("/tmp/test_io_output.c");
|
|
}
|
|
|
|
Test(io, close_does_not_close_stdin_stdout)
|
|
{
|
|
t_io io;
|
|
|
|
io.in = stdin;
|
|
io.out = stdout;
|
|
|
|
io_close(&io);
|
|
|
|
cr_assert_eq(io.in, stdin);
|
|
cr_assert_eq(io.out, stdout);
|
|
}
|