test-bus-match.c revision cc65fe5e14770d0116e0f475c5dc2ef57113bc98
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster This file is part of systemd.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Copyright 2013 Lennart Poettering
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster systemd is free software; you can redistribute it and/or modify it
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster under the terms of the GNU Lesser General Public License as published by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster the Free Software Foundation; either version 2.1 of the License, or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (at your option) any later version.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster systemd is distributed in the hope that it will be useful, but
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WITHOUT ANY WARRANTY; without even the implied warranty of
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Lesser General Public License for more details.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster You should have received a copy of the GNU Lesser General Public License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster along with systemd; If not, see <http://www.gnu.org/licenses/>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic int filter(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster assert_se(PTR_TO_UINT(userdata) < ELEMENTSOF(mask));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic bool mask_contains(unsigned a[], unsigned n) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster unsigned i, j;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bool found = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (j = 0; j < n; j++)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (a[j] == i) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char *match, int value) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster r = bus_match_parse(match, &components, &n_components);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster r = bus_match_add(root, components, n_components, &s->match_callback);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bus_match_parse_free(components, n_components);
unsigned n_components = 0;
enum bus_match_node_type i;
return EXIT_TEST_SKIP;
assert_se(match_add(slots, &root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar.x',", 1) >= 0);
assert_se(match_add(slots, &root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar.x',", 2) >= 0);
assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='signal',interface='bar.x',", 3) >= 0);
assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='method_call',interface='bar.x',", 4) >= 0);
assert_se(sd_bus_message_append(m, "ssssas", "one", "two", "/prefix/three", "prefix.four", 3, "pi", "pa", "po") >= 0);
for (i = 0; i < _BUS_MATCH_NODE_TYPE_MAX; i++) {
if (i >= BUS_MATCH_MESSAGE_TYPE)