summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/test-bus-zero-copy.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-05-16 16:53:03 +0200
committerLennart Poettering <lennart@poettering.net>2013-05-16 16:53:03 +0200
commit5cbe749238f62546f70d81173a2778f3982adb03 (patch)
tree1b71925f7478b7a9c05d497b2896db87de9d59b4 /src/libsystemd-bus/test-bus-zero-copy.c
parent66b26c5c9b02e787bc46db24daff04ad41e05ec5 (diff)
bus: implement sd_bus_message_append_string_memfd()
Diffstat (limited to 'src/libsystemd-bus/test-bus-zero-copy.c')
-rw-r--r--src/libsystemd-bus/test-bus-zero-copy.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c
index 63bb921456..db3906e274 100644
--- a/src/libsystemd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd-bus/test-bus-zero-copy.c
@@ -34,6 +34,8 @@
#define FIRST_ARRAY 17
#define SECOND_ARRAY 33
+#define STRING_SIZE 123
+
int main(int argc, char *argv[]) {
_cleanup_free_ char *bus_name = NULL, *address = NULL;
uint8_t *p;
@@ -44,6 +46,7 @@ int main(int argc, char *argv[]) {
uint64_t sz;
uint32_t u32;
size_t i, l;
+ char *s;
log_set_max_level(LOG_DEBUG);
@@ -77,7 +80,7 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_new_method_call(b, ":1.1", "/a/path", "an.inter.face", "AMethod", &m);
assert_se(r >= 0);
- r = sd_bus_message_open_container(m, 'r', "ayay");
+ r = sd_bus_message_open_container(m, 'r', "aysay");
assert_se(r >= 0);
r = sd_bus_message_append_array_space(m, 'y', FIRST_ARRAY, (void**) &p);
@@ -85,6 +88,24 @@ int main(int argc, char *argv[]) {
memset(p, 'L', FIRST_ARRAY);
+ r = sd_memfd_new_and_map(&f, STRING_SIZE, (void**) &s);
+ assert_se(r >= 0);
+
+ for (i = 0; i < STRING_SIZE-1; i++)
+ s[i] = '0' + (i % 10);
+
+ s[STRING_SIZE-1] = 0;
+ munmap(s, STRING_SIZE);
+
+ r = sd_memfd_get_size(f, &sz);
+ assert_se(r >= 0);
+ assert_se(sz == STRING_SIZE);
+
+ r = sd_bus_message_append_string_memfd(m, f);
+ assert_se(r >= 0);
+
+ sd_memfd_free(f);
+
r = sd_memfd_new_and_map(&f, SECOND_ARRAY, (void**) &p);
assert_se(r >= 0);
@@ -122,7 +143,7 @@ int main(int argc, char *argv[]) {
bus_message_dump(m);
sd_bus_message_rewind(m, true);
- r = sd_bus_message_enter_container(m, 'r', "ayay");
+ r = sd_bus_message_enter_container(m, 'r', "aysay");
assert_se(r > 0);
r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
@@ -132,6 +153,13 @@ int main(int argc, char *argv[]) {
for (i = 0; i < l; i++)
assert_se(p[i] == 'L');
+ r = sd_bus_message_read(m, "s", &s);
+ assert_se(r > 0);
+
+ for (i = 0; i < STRING_SIZE-1; i++)
+ assert_se(s[i] == (char) ('0' + (i % 10)));
+ assert_se(s[STRING_SIZE-1] == 0);
+
r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
assert_se(r > 0);
assert_se(l == SECOND_ARRAY);