tests/libpakfire/main \
tests/libpakfire/arch \
tests/libpakfire/archive \
+ tests/libpakfire/compress \
tests/libpakfire/db \
tests/libpakfire/downloader \
tests/libpakfire/execute \
$(TESTSUITE_LDADD) \
$(PAKFIRE_LIBS)
+dist_tests_libpakfire_compress_SOURCES = \
+ tests/libpakfire/compress.c \
+ src/libpakfire/compress.c
+
+tests_libpakfire_compress_CPPFLAGS = \
+ $(TESTSUITE_CPPFLAGS) \
+ -DPAKFIRE_PRIVATE
+
+tests_libpakfire_compress_LDADD = \
+ $(TESTSUITE_LDADD) \
+ $(PAKFIRE_LIBS) \
+ $(LZMA_LIBS)
+
tests_libpakfire_db_SOURCES = \
tests/libpakfire/db.c
tests/data/beep.nm \
tests/data/kernel.nm \
\
+ tests/data/compress/data.xz \
+ \
tests/data/parser/test-comments.txt \
tests/data/parser/test-conditionals.txt \
tests/data/parser/test-declarations.txt \
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <stdio.h>
+
+#include <pakfire/compress.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+const char TEST_DATA[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
+
+static int test_xzfopen_read(const struct test* t) {
+ char buffer[1024];
+
+ char* path = pakfire_path_join(TEST_SRC_PATH, "data/compress/data.xz");
+ ASSERT(path);
+
+ FILE* f = fopen(path, "r");
+ ASSERT(f);
+
+ // Engage decompressor
+ f = pakfire_xzfopen(f, "r");
+ ASSERT(f);
+
+ // Read into buffer
+ size_t bytes_read = fread(buffer, 1, sizeof(buffer), f);
+ ASSERT(bytes_read);
+
+ // Buffer should equal the test data
+ ASSERT(bytes_read >= sizeof(TEST_DATA) - 1);
+ ASSERT(memcmp(buffer, TEST_DATA, sizeof(TEST_DATA) - 1) == 0);
+
+ fclose(f);
+ free(path);
+
+ return EXIT_SUCCESS;
+}
+
+static int test_xzfopen_write(const struct test* t) {
+ // Create a backend storage file
+ FILE* f = test_mktemp();
+ ASSERT(f);
+
+ // Open compressed file for writing
+ f = pakfire_xzfopen(f, "w");
+ ASSERT(f);
+
+ // Write some data and close fwrite
+ for (unsigned int i = 0; i < 1000; i++) {
+ size_t bytes_written = fwrite(TEST_DATA, 1, sizeof(TEST_DATA) - 1, f);
+ ASSERT(bytes_written == sizeof(TEST_DATA) - 1);
+ }
+
+ fclose(f);
+
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char** argv) {
+ testsuite_add_test(test_xzfopen_read);
+ testsuite_add_test(test_xzfopen_write);
+
+ return testsuite_run();
+}