]> git.ipfire.org Git - pakfire.git/commitdiff
testsuite: Add test which extracts an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 15:55:03 +0000 (16:55 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 15:55:03 +0000 (16:55 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/libpakfire.sym
tests/libpakfire/archive.c

index 6e0bfc675af0150a38546c5acf4842e864a61b3d..af4c8b7155e3d56f0b060b83d16a8280aa8a905d 100644 (file)
@@ -320,6 +320,7 @@ global:
        pakfire_transaction_run;
 
        # util
+       pakfire_access;
        pakfire_free;
        pakfire_get_errno;
        pakfire_path_join;
index d4d51e5c070a4a1d28cc7d933cd348f0b00cc0b6..08918dca72e9124fb25d3a76c4e184511a1d27f9 100644 (file)
 #include "../testsuite.h"
 
 static const char* TEST_PKG1_PATH = "data/beep-1.3-2.ip3.x86_64.pfm";
+static const char* TEST_PKG1_FILE = "usr/bin/beep";
 
 int test_open(const test_t* t) {
-    char* path = pakfire_path_join(TEST_SRC_PATH, TEST_PKG1_PATH);
-    LOG("Trying to open %s\n", path);
+       char* path = pakfire_path_join(TEST_SRC_PATH, TEST_PKG1_PATH);
+       LOG("Trying to open %s\n", path);
 
-    // Open the archive
-    PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
-    assert_return(archive, EXIT_FAILURE);
+       // Open the archive
+       PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
+       assert_return(archive, EXIT_FAILURE);
 
-    pakfire_archive_unref(archive);
+       // Verify the archive
+       pakfire_archive_verify_status_t verify = pakfire_archive_verify(archive);
+       assert_return(verify == PAKFIRE_ARCHIVE_VERIFY_OK, EXIT_FAILURE);
 
-    pakfire_free(path);
+       pakfire_archive_unref(archive);
+       pakfire_free(path);
 
-    return EXIT_SUCCESS;
+       return EXIT_SUCCESS;
+}
+
+int test_extract(const test_t* t) {
+       char* path = pakfire_path_join(TEST_SRC_PATH, TEST_PKG1_PATH);
+
+       PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
+       pakfire_free(path);
+
+       // Extract the archive payload
+       int r = pakfire_archive_extract(archive, NULL, PAKFIRE_ARCHIVE_USE_PAYLOAD);
+       assert_return(r == 0, EXIT_FAILURE);
+
+       // Check if test file from the archive exists
+       assert_return(pakfire_access(pakfire_get_path(t->pakfire),
+               TEST_PKG1_FILE, F_OK) == 0, EXIT_FAILURE);
+
+       pakfire_archive_unref(archive);
+
+       return EXIT_SUCCESS;
 }
 
 int main(int argc, char** argv) {
        testsuite_init();
 
-       testsuite_t* ts = testsuite_create(1);
+       testsuite_t* ts = testsuite_create(2);
 
        testsuite_add_test(ts, "test_open", test_open);
+       testsuite_add_test(ts, "test_extract", test_extract);
 
        return testsuite_run(ts);
 }