chiark / gitweb /
Stop talking about the "XDG" version of basename()
[elogind.git] / src / libelogind / sd-bus / test-bus-match.c
index 051969f9c759c3c5ba956f855873572414b54e59..a1687b1c7bb81f835b3fbfec61649f003837abac 100644 (file)
@@ -29,7 +29,7 @@
 
 static bool mask[32];
 
-static int filter(sd_bus *b, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+static int filter(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
         log_info("Ran %u", PTR_TO_UINT(userdata));
         assert_se(PTR_TO_UINT(userdata) < ELEMENTSOF(mask));
         mask[PTR_TO_UINT(userdata)] = true;
@@ -77,6 +77,15 @@ static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char
         return r;
 }
 
+static void test_match_scope(const char *match, enum bus_match_scope scope) {
+        struct bus_match_component *components = NULL;
+        unsigned n_components = 0;
+
+        assert_se(bus_match_parse(match, &components, &n_components) >= 0);
+        assert_se(bus_match_get_scope(components, n_components) == scope);
+        bus_match_parse_free(components, n_components);
+}
+
 int main(int argc, char *argv[]) {
         struct bus_match_node root = {
                 .type = BUS_MATCH_ROOT,
@@ -142,5 +151,12 @@ int main(int argc, char *argv[]) {
 
         bus_match_free(&root);
 
+        test_match_scope("interface='foobar'", BUS_MATCH_GENERIC);
+        test_match_scope("", BUS_MATCH_GENERIC);
+        test_match_scope("interface='org.freedesktop.DBus.Local'", BUS_MATCH_LOCAL);
+        test_match_scope("sender='org.freedesktop.DBus.Local'", BUS_MATCH_LOCAL);
+        test_match_scope("member='gurke',path='/org/freedesktop/DBus/Local'", BUS_MATCH_LOCAL);
+        test_match_scope("arg2='piep',sender='org.freedesktop.DBus',member='waldo'", BUS_MATCH_DRIVER);
+
         return 0;
 }