X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Ftest-bus-marshal.c;h=2321873da53d65536ab4c2ae0ec710acf0047816;hb=e09826dcf13a17cd63d900502282c511a06ecbe8;hp=85aaf95d6c31ea23902bdea2fc27c7690ca666fe;hpb=151b9b9662a90455262ce575a8a8ae74bf4ff336;p=elogind.git diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index 85aaf95d6..2321873da 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)); } @@ -79,6 +97,9 @@ int main(int argc, char *argv[]) { r = sd_bus_message_new_method_call(NULL, &m, "foobar.waldo", "/", "foobar.waldo", "Piep"); assert_se(r >= 0); + r = sd_bus_message_append(m, ""); + assert_se(r >= 0); + r = sd_bus_message_append(m, "s", "a string"); assert_se(r >= 0); @@ -319,6 +340,7 @@ int main(int argc, char *argv[]) { assert_se(streq(d, "3")); test_bus_label_escape(); + test_bus_path_encode(); return 0; }