1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 #include "bus-message.h"
31 #include "bus-error.h"
32 #include "bus-kernel.h"
34 #define FIRST_ARRAY 17
35 #define SECOND_ARRAY 33
37 int main(int argc, char *argv[]) {
38 _cleanup_free_ char *bus_name = NULL, *address = NULL;
48 log_set_max_level(LOG_DEBUG);
50 bus_ref = bus_kernel_create("deine-mutter", &bus_name);
51 if (bus_ref == -ENOENT)
52 return EXIT_TEST_SKIP;
54 assert_se(bus_ref >= 0);
56 address = strappend("kernel:path=", bus_name);
65 r = sd_bus_set_address(a, address);
68 r = sd_bus_set_address(b, address);
77 r = sd_bus_message_new_method_call(b, ":1.1", "/a/path", "an.inter.face", "AMethod", &m);
80 r = sd_bus_message_open_container(m, 'r', "ayay");
83 r = sd_bus_message_append_array_space(m, 'y', FIRST_ARRAY, (void**) &p);
86 memset(p, 'L', FIRST_ARRAY);
88 r = sd_memfd_new_and_map(&f, SECOND_ARRAY, (void**) &p);
91 memset(p, 'P', SECOND_ARRAY);
92 munmap(p, SECOND_ARRAY);
94 r = sd_memfd_get_size(f, &sz);
96 assert_se(sz == SECOND_ARRAY);
98 r = sd_bus_message_append_array_memfd(m, 'y', f);
103 r = sd_bus_message_close_container(m);
106 r = sd_bus_message_append(m, "u", 4711);
109 r = bus_message_seal(m, 55);
114 r = sd_bus_send(b, m, NULL);
117 sd_bus_message_unref(m);
119 r = sd_bus_process(a, &m);
123 sd_bus_message_rewind(m, true);
125 r = sd_bus_message_enter_container(m, 'r', "ayay");
128 r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
130 assert_se(l == FIRST_ARRAY);
132 for (i = 0; i < l; i++)
133 assert_se(p[i] == 'L');
135 r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);
137 assert_se(l == SECOND_ARRAY);
139 for (i = 0; i < l; i++)
140 assert_se(p[i] == 'P');
142 r = sd_bus_message_exit_container(m);
145 r = sd_bus_message_read(m, "u", &u32);
147 assert_se(u32 == 4711);
149 sd_bus_message_unref(m);