return 0;
}
+int pakfire_package_matches_dep(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char* dep) {
+ int r;
+
+ Id id = ID_NULL;
+ int marker = 0;
+
+ // Translate the dependency type
+ r = pakfire_package_dep2id(key, &id, &marker);
+ if (r)
+ return r;
+
+ // Get the dependency
+ Id depid = pakfire_str2dep(pkg->pakfire, dep);
+ if (!depid)
+ return 0;
+
+ // Fetch the solvable
+ Solvable* s = get_solvable(pkg);
+
+ // Check whether this solvable matches the requested dependency
+ return solvable_matchesdep(s, id, depid, marker) == 0;
+}
+
PAKFIRE_EXPORT struct pakfire_repo* pakfire_package_get_repo(struct pakfire_package* pkg) {
if (!pkg->repo) {
Solvable* s = get_solvable(pkg);
return EXIT_FAILURE;
}
+static int test_dep_match(const struct test* t) {
+ struct pakfire_package* pkg = NULL;
+ int r = EXIT_FAILURE;
+
+ ASSERT_SUCCESS(pakfire_package_create(&pkg, t->pakfire, NULL,
+ "test", "1.0-1", "x86_64"));
+
+ // Check if the package matches itself
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "test") == 1);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "test = 1.0-1") == 1);
+
+ // Add a couple of things this package provides
+ ASSERT_SUCCESS(pakfire_package_add_dep(pkg, PAKFIRE_PKG_PROVIDES, "a = 1"));
+ ASSERT_SUCCESS(pakfire_package_add_dep(pkg, PAKFIRE_PKG_PROVIDES, "b"));
+
+ // Check if the package matches those dependencies
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "a") == 1);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "a = 1") == 1);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "a >= 1") == 1);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "a <= 1") == 1);
+
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "b") == 1);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "b = 1") == 1);
+
+ // Check for something that doesn't exist
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "c") == 0);
+ ASSERT_SUCCESS(pakfire_package_matches_dep(pkg, PAKFIRE_PKG_PROVIDES, "c = 2") == 0);
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (pkg)
+ pakfire_package_unref(pkg);
+
+ return r;
+}
+
int main(int argc, const char* argv[]) {
testsuite_add_test(test_dependencies);
+ testsuite_add_test(test_dep_match);
return testsuite_run(argc, argv);
}