From e49efa011ddd7cd695147bd42b12c8aa846f5815 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 18 Mar 2021 19:10:08 +0000 Subject: [PATCH] compress: Add test for pakfire_xfopen Signed-off-by: Michael Tremer --- tests/libpakfire/compress.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/libpakfire/compress.c b/tests/libpakfire/compress.c index de207084d..fa6ddf6a8 100644 --- a/tests/libpakfire/compress.c +++ b/tests/libpakfire/compress.c @@ -27,17 +27,18 @@ const char TEST_DATA[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; -static int test_xzfopen_read(const struct test* t) { +static int read_test(const struct test* t, + FILE* (function)(FILE* f, const char* mode), const char* file) { char buffer[1024]; - char* path = pakfire_path_join(TEST_SRC_PATH, "data/compress/data.xz"); + char* path = pakfire_path_join(TEST_SRC_PATH, file); ASSERT(path); FILE* f = fopen(path, "r"); ASSERT(f); // Engage decompressor - f = pakfire_xzfopen(f, "r"); + f = function(f, "r"); ASSERT(f); // Read into buffer @@ -54,6 +55,10 @@ static int test_xzfopen_read(const struct test* t) { return EXIT_SUCCESS; } +static int test_xzfopen_read(const struct test* t) { + return read_test(t, pakfire_xzfopen, "data/compress/data.xz"); +} + static int test_xzfopen_write(const struct test* t) { // Create a backend storage file FILE* f = test_mktemp(); @@ -74,9 +79,15 @@ static int test_xzfopen_write(const struct test* t) { return EXIT_SUCCESS; } +static int test_xfopen(const struct test* t) { + return read_test(t, pakfire_xfopen, "data/compress/data.xz"); +} + int main(int argc, char** argv) { testsuite_add_test(test_xzfopen_read); testsuite_add_test(test_xzfopen_write); + testsuite_add_test(test_xfopen); + return testsuite_run(); } -- 2.47.2