diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-10-29 19:30:55 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-10-29 19:34:59 +0100 |
commit | c430fee6ffda0e3736e4e2b617bef0a4c0882849 (patch) | |
tree | 32d4491da8676e79d6010641f7b9fb13a611e20e /src/libsystemd-bus/test-bus-marshal.c | |
parent | 276fc0668fdfd22ec3b38533e311e14969d42293 (diff) |
bus: add new sd_bus_message_verify_type() and sd_bus_message_copy() API calls
Diffstat (limited to 'src/libsystemd-bus/test-bus-marshal.c')
-rw-r--r-- | src/libsystemd-bus/test-bus-marshal.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c index 1e2caa0620..baa269c9aa 100644 --- a/src/libsystemd-bus/test-bus-marshal.c +++ b/src/libsystemd-bus/test-bus-marshal.c @@ -37,7 +37,7 @@ #include "bus-util.h" int main(int argc, char *argv[]) { - _cleanup_bus_message_unref_ sd_bus_message *m = NULL; + _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *copy = NULL; int r, boolean; const char *x, *y, *z, *a, *b, *c, *d; uint8_t u, v; @@ -46,6 +46,9 @@ int main(int argc, char *argv[]) { char *h; const int32_t integer_array[] = { -1, -2, 0, 1, 2 }, *return_array; char *s; + _cleanup_free_ char *first = NULL, *second = NULL, *third = NULL; + _cleanup_fclose_ FILE *ms = NULL; + size_t first_size = 0, second_size = 0, third_size = 0; r = sd_bus_message_new_method_call(NULL, "foobar.waldo", "/", "foobar.waldo", "Piep", &m); assert_se(r >= 0); @@ -90,7 +93,12 @@ int main(int argc, char *argv[]) { r = bus_message_seal(m, 4711); assert_se(r >= 0); - bus_message_dump(m); + bus_message_dump(m, stdout, true); + + ms = open_memstream(&first, &first_size); + bus_message_dump(m, ms, false); + fflush(ms); + assert_se(!ferror(ms)); r = bus_message_get_blob(m, &buffer, &sz); assert_se(r >= 0); @@ -136,7 +144,15 @@ int main(int argc, char *argv[]) { r = bus_message_from_malloc(buffer, sz, NULL, 0, NULL, NULL, &m); assert_se(r >= 0); - bus_message_dump(m); + bus_message_dump(m, stdout, true); + + fclose(ms); + ms = open_memstream(&second, &second_size); + bus_message_dump(m, ms, false); + fflush(ms); + assert_se(!ferror(ms)); + assert_se(first_size == second_size); + assert_se(memcmp(first, second, first_size) == 0); assert_se(sd_bus_message_rewind(m, true) >= 0); @@ -173,6 +189,8 @@ int main(int argc, char *argv[]) { assert_se(streq(c, "ccc")); assert_se(streq(d, "3")); + assert_se(sd_bus_message_verify_type(m, 'a', "s") > 0); + r = sd_bus_message_read(m, "as", 2, &x, &y); assert_se(r > 0); assert_se(streq(x, "foobar")); @@ -190,5 +208,29 @@ int main(int argc, char *argv[]) { r = sd_bus_message_peek_type(m, NULL, NULL); assert_se(r == 0); + r = sd_bus_message_new_method_call(NULL, "foobar.waldo", "/", "foobar.waldo", "Piep", ©); + assert_se(r >= 0); + + r = sd_bus_message_rewind(m, true); + assert_se(r >= 0); + + r = sd_bus_message_copy(copy, m, true); + assert_se(r >= 0); + + r = bus_message_seal(copy, 4712); + assert_se(r >= 0); + + fclose(ms); + ms = open_memstream(&third, &third_size); + bus_message_dump(copy, ms, false); + fflush(ms); + assert_se(!ferror(ms)); + + printf("<%.*s>", (int) first_size, first); + printf("<%.*s>", (int) third_size, third); + + assert_se(first_size == third_size); + assert_se(memcmp(first, third, third_size) == 0); + return 0; } |