diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-03-11 19:03:50 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-11 19:03:50 +0100 |
commit | a6278b88305b237b02eabff0d870b57fe851822d (patch) | |
tree | d826e248d401a18f07c45cfc0832907e861a2877 /src/libsystemd/sd-bus/test-bus-marshal.c | |
parent | 2be56ff1e49c8954a0899da701233acf053e95a4 (diff) |
bus: replace sd_bus_label_{escape,unescape}() by new sd_bus_path_{encode,decode}()
The new calls work similarly, but enforce a that a common, fixed bus
path prefix is used.
This follows discussions with Simon McVittie on IRC that it should be a
good idea to make sure that people don't use the escaping applied here
too wildly as anything other than the last label of a bus path.
Diffstat (limited to 'src/libsystemd/sd-bus/test-bus-marshal.c')
-rw-r--r-- | src/libsystemd/sd-bus/test-bus-marshal.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index d438a231a6..2321873da5 100644 --- a/src/libsystemd/sd-bus/test-bus-marshal.c +++ b/src/libsystemd/sd-bus/test-bus-marshal.c @@ -38,17 +38,35 @@ #include "bus-message.h" #include "bus-util.h" #include "bus-dump.h" +#include "bus-label.h" + +static void test_bus_path_encode(void) { + _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL; + + assert_se(sd_bus_path_encode("/foo/bar", "waldo", &a) >= 0 && streq(a, "/foo/bar/waldo")); + assert_se(sd_bus_path_decode(a, "/waldo", &b) == 0 && b == NULL); + assert_se(sd_bus_path_decode(a, "/foo/bar", &b) > 0 && streq(b, "waldo")); + + assert_se(sd_bus_path_encode("xxxx", "waldo", &c) < 0); + assert_se(sd_bus_path_encode("/foo/", "waldo", &c) < 0); + + assert_se(sd_bus_path_encode("/foo/bar", "", &c) >= 0 && streq(c, "/foo/bar/_")); + assert_se(sd_bus_path_decode(c, "/foo/bar", &d) > 0 && streq(d, "")); + + assert_se(sd_bus_path_encode("/foo/bar", "foo.bar", &e) >= 0 && streq(e, "/foo/bar/foo_2ebar")); + assert_se(sd_bus_path_decode(e, "/foo/bar", &f) > 0 && streq(f, "foo.bar")); +} static void test_bus_label_escape_one(const char *a, const char *b) { _cleanup_free_ char *t = NULL, *x = NULL, *y = NULL; - assert_se(t = sd_bus_label_escape(a)); + assert_se(t = bus_label_escape(a)); assert_se(streq(t, b)); - assert_se(x = sd_bus_label_unescape(t)); + assert_se(x = bus_label_unescape(t)); assert_se(streq(a, x)); - assert_se(y = sd_bus_label_unescape(b)); + assert_se(y = bus_label_unescape(b)); assert_se(streq(a, y)); } @@ -322,6 +340,7 @@ int main(int argc, char *argv[]) { assert_se(streq(d, "3")); test_bus_label_escape(); + test_bus_path_encode(); return 0; } |