From: Michael Tremer Date: Wed, 26 Oct 2022 20:02:34 +0000 (+0000) Subject: tests: Add some tests for packages with invalid inputs X-Git-Tag: 0.9.28~198 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6692c216f2b1f27b2d59272114c00af4e8b990b;p=pakfire.git tests: Add some tests for packages with invalid inputs Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/package.c b/tests/libpakfire/package.c index bdffabfbe..3e59401cb 100644 --- a/tests/libpakfire/package.c +++ b/tests/libpakfire/package.c @@ -143,6 +143,34 @@ FAIL: return r; } +static int test_invalid_inputs(const struct test* t) { + struct pakfire_package* pkg = NULL; + int r = EXIT_FAILURE; + + // Try to create a package with some values missing + ASSERT_ERRNO(pakfire_package_create(&pkg, t->pakfire, NULL, NULL, "1.0-1", "src"), EINVAL); + ASSERT_ERRNO(pakfire_package_create(&pkg, t->pakfire, NULL, "test", NULL, "src"), EINVAL); + ASSERT_ERRNO(pakfire_package_create(&pkg, t->pakfire, NULL, "test", "1.0-1", NULL), EINVAL); + + // Finally create a package + ASSERT_SUCCESS(pakfire_package_create(&pkg, t->pakfire, NULL, "test", "1.0-1", "x86_64")); + + // Try to set non-sense for strings + ASSERT_ERRNO(pakfire_package_set_string(pkg, PAKFIRE_PKG_INSTALLTIME, "today"), EINVAL); + + // Try to set a non-sense numeric value + ASSERT_ERRNO(pakfire_package_set_num(pkg, PAKFIRE_PKG_NAME, 0), EINVAL); + + // Everything passed + r = EXIT_SUCCESS; + +FAIL: + if (pkg) + pakfire_package_unref(pkg); + + return r; +} + static int test_uuid(const struct test* t) { struct pakfire_package* pkg = NULL; int r = EXIT_FAILURE; @@ -214,6 +242,7 @@ FAIL: int main(int argc, const char* argv[]) { testsuite_add_test(test_create); + testsuite_add_test(test_invalid_inputs); testsuite_add_test(test_uuid); testsuite_add_test(test_deps);