chiark / gitweb /
bus: we now support path_namespace=/
[elogind.git] / src / libelogind / sd-bus / test-bus-kernel-bloom.c
index b11c43bd7b0fa0c010d4ea82d5833b278ab7a8c7..90eb1f2a3350d98ea714034077e6c8c8bdc1bc11 100644 (file)
 #include "bus-kernel.h"
 #include "bus-util.h"
 
+static int test_match(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+        int *found = userdata;
+
+        *found = 1;
+
+        return 0;
+}
+
 static void test_one(
                 const char *path,
                 const char *interface,
@@ -39,7 +47,7 @@ static void test_one(
         _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         sd_bus *a, *b;
-        int r;
+        int r, found = 0;
 
         assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);
 
@@ -71,7 +79,7 @@ static void test_one(
         assert_se(r >= 0);
 
         log_debug("match");
-        r = sd_bus_add_match(b, NULL, match, NULL, NULL);
+        r = sd_bus_add_match(b, NULL, match, test_match, &found);
         assert_se(r >= 0);
 
         log_debug("signal");
@@ -83,7 +91,7 @@ static void test_one(
         assert_se(r >= 0);
 
         r = sd_bus_process(b, &m);
-        assert_se(r >= 0 && (good == !!m));
+        assert_se(r >= 0 && good == !!found);
 
         sd_bus_unref(a);
         sd_bus_unref(b);
@@ -115,6 +123,17 @@ int main(int argc, char *argv[]) {
         test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo'", true);
         test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
         test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/quux'", false);
+        test_one("/", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
+
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/'", false);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/'", false);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo/'", false);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/'", true);
+
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/bar/waldo", "arg0path='/foo/'", true);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo'", true);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo/bar/waldo'", false);
+        test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/", "arg0path='/foo/bar/waldo'", true);
 
         return 0;
 }