]> git.ipfire.org Git - pakfire.git/commitdiff
compress: Add test for pakfire_xfopen
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Mar 2021 19:10:08 +0000 (19:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Mar 2021 19:10:08 +0000 (19:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/compress.c

index de207084d68adfad48cb51c0042a2bd5ea068065..fa6ddf6a87b3cd7a5f85ee278373bcb03f972315 100644 (file)
 
 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();
 }