]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add some tests for packages with invalid inputs
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 20:02:34 +0000 (20:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 20:02:34 +0000 (20:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/package.c

index bdffabfbe290f7004e6a062985a434b7a897b4a5..3e59401cbbbb5dca9c987f472b7dd077ba174760 100644 (file)
@@ -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);