]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Test package UUID functions
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 19:51:36 +0000 (19:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 19:51:36 +0000 (19:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/package.c

index 72da1edb8bda267c6167de9ab7b485a92fb80af6..bdffabfbe290f7004e6a062985a434b7a897b4a5 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <stdio.h>
 
+#include <uuid/uuid.h>
+
 #include <pakfire/package.h>
 #include <pakfire/util.h>
 
@@ -141,6 +143,47 @@ FAIL:
        return r;
 }
 
+static int test_uuid(const struct test* t) {
+       struct pakfire_package* pkg = NULL;
+       int r = EXIT_FAILURE;
+
+       uuid_t uuid;
+       char uuid_string[UUID_STR_LEN];
+
+       // Generate a new random UUID
+       uuid_generate_random(uuid);
+
+       // Convert the UUID to string
+       uuid_unparse(uuid, uuid_string);
+
+       // Create a new package
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->pakfire, NULL, "test", "1.0-1", "src"));
+
+       // Set the UUID
+       ASSERT_SUCCESS(pakfire_package_set_uuid(pkg, PAKFIRE_PKG_UUID, uuid));
+
+       // Fetch the UUID as string
+       ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID), uuid_string);
+
+       // Set the Build ID
+       ASSERT_SUCCESS(pakfire_package_set_uuid(pkg, PAKFIRE_PKG_BUILD_ID, uuid));
+
+       // Fetch the Build ID as string
+       ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_BUILD_ID), uuid_string);
+
+       // Try setting the UUID as something else
+       ASSERT_ERRNO(pakfire_package_set_uuid(pkg, PAKFIRE_PKG_SUMMARY, uuid), EINVAL);
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (pkg)
+               pakfire_package_unref(pkg);
+
+       return r;
+}
+
 static int test_deps(const struct test* t) {
        struct pakfire_package* pkg = NULL;
        char** deps = NULL;
@@ -171,6 +214,7 @@ FAIL:
 
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_create);
+       testsuite_add_test(test_uuid);
        testsuite_add_test(test_deps);
 
        return testsuite_run(argc, argv);