From abc7ed19f1f426b8a36e80bdf07809cc7dea5c3d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 26 Oct 2022 19:51:36 +0000 Subject: [PATCH] tests: Test package UUID functions Signed-off-by: Michael Tremer --- tests/libpakfire/package.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/libpakfire/package.c b/tests/libpakfire/package.c index 72da1edb8..bdffabfbe 100644 --- a/tests/libpakfire/package.c +++ b/tests/libpakfire/package.c @@ -20,6 +20,8 @@ #include +#include + #include #include @@ -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); -- 2.39.5