diff options
author | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
commit | 7aa261f8d57cb53cc334f6bf1920a6f8517ff054 (patch) | |
tree | f23a96feda17de737c71b45dc94e7e044410ad35 /tests/test_fcopy.c | |
parent | 27bb394bc0bf2ca66d06931bf1e73a3e20d5741a (diff) | |
download | extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.gz extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.bz2 |
Rework test suite to be more modular
Diffstat (limited to 'tests/test_fcopy.c')
-rw-r--r-- | tests/test_fcopy.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_fcopy.c b/tests/test_fcopy.c new file mode 100644 index 0000000..3847ed3 --- /dev/null +++ b/tests/test_fcopy.c @@ -0,0 +1,41 @@ +#include <string.h> +#define USE_SECURE_MEM +#include "../src/extlib.h" +#undef free + +int +test_fcopy () +{ + int errno = 0; + char *buf_a; + char *buf_b; + size_t len_a; + size_t len_b; + FILE *file_test_a = open_memstream (&buf_a, &len_a); + FILE *file_test_b = open_memstream (&buf_b, &len_b); + + fprintf (file_test_a, "meow"); + fflush (file_test_a); + fclose (file_test_a); + file_test_a = fmemopen (buf_a, len_a, "r"); + + fcopy (file_test_a, file_test_b); + fclose (file_test_b); + + if (memcmp (buf_a, buf_b, len_a) != 0) + errno = 1; + + free_secure ((void **) &buf_a, len_a); + free_secure ((void **) &buf_b, len_b); + return errno; +} + +struct test_t* +test_fcopy_t () +{ + struct test_t* test = malloc (sizeof (struct test_t)); + test->test_func=test_fcopy; + test->test_name="test_fcopy"; + test->test_desc="fcopy"; + return test; +} |