chiark / gitweb /
test-bus-policy: silence coverity
[elogind.git] / src / bus-proxyd / test-bus-policy.c
index 37e66274f01d9cc61b12d382c4875d7bc3bb7573..7bcebef905cc73ca5f3c22cd00512de6f3e7b1be 100644 (file)
 
 #include <bus-proxyd/bus-policy.h>
 
+static int test_policy_load(Policy *p, const char *name)
+{
+        _cleanup_free_ char *path = NULL;
+        int r = 0;
+
+        path = strjoin(TEST_DIR, "/bus-policy/", name, NULL);
+        assert_se(path);
+
+        if (access(path, R_OK) == 0)
+                policy_load(p, STRV_MAKE(path));
+        else
+                r = -ENOENT;
+
+        return r;
+}
+
 int main(int argc, char *argv[]) {
 
         Policy p = {};
@@ -52,7 +68,7 @@ int main(int argc, char *argv[]) {
         Hashmap *names_hash;
 
         /* Ownership tests */
-        assert_se(policy_load(&p, STRV_MAKE("test/bus-policy/ownerships.conf")) == 0);
+        assert_se(test_policy_load(&p, "ownerships.conf") == 0);
 
         ucred.uid = 0;
         assert_se(policy_check_own(&p, &ucred, "org.test.test1") == true);
@@ -77,7 +93,7 @@ int main(int argc, char *argv[]) {
         policy_free(&p);
 
         /* Signaltest */
-        assert_se(policy_load(&p, STRV_MAKE("test/bus-policy/signals.conf")) == 0);
+        assert_se(test_policy_load(&p, "signals.conf") == 0);
         names_strv = STRV_MAKE("bli.bla.blubb");
 
         ucred.uid = 0;
@@ -89,7 +105,7 @@ int main(int argc, char *argv[]) {
         policy_free(&p);
 
         /* Method calls */
-        assert_se(policy_load(&p, STRV_MAKE("test/bus-policy/methods.conf")) == 0);
+        assert_se(test_policy_load(&p, "methods.conf") == 0);
         names_strv = STRV_MAKE("org.test.test1");
         policy_dump(&p);
 
@@ -108,7 +124,7 @@ int main(int argc, char *argv[]) {
         policy_free(&p);
 
         /* User and groups */
-        assert_se(policy_load(&p, STRV_MAKE("test/bus-policy/hello.conf")) == 0);
+        assert_se(test_policy_load(&p, "hello.conf") == 0);
         policy_dump(&p);
 
         ucred.uid = 0;