test-bus-marshal.c revision 49df985cef85b94e621f95b13ccd94b109de30cb
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <math.h>
#include <stdlib.h>
#ifdef HAVE_GLIB
#endif
#ifdef HAVE_DBUS
#endif
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-dump.h"
#include "bus-label.h"
#include "bus-message.h"
#include "bus-util.h"
#include "fd-util.h"
#include "hexdecoct.h"
#include "log.h"
#include "util.h"
static void test_bus_path_encode_unique(void) {
assert_se(bus_path_encode_unique(NULL, "/foo/bar", "some.sender", "a.suffix", &a) >= 0 && streq_ptr(a, "/foo/bar/some_2esender/a_2esuffix"));
assert_se(bus_path_decode_unique(a, "/foo/bar", &b, &c) > 0 && streq_ptr(b, "some.sender") && streq_ptr(c, "a.suffix"));
assert_se(bus_path_decode_unique("/foo/bar/_/_", "/foo/bar", &d, &e) > 0 && streq_ptr(d, "") && streq_ptr(e, ""));
}
static void test_bus_path_encode(void) {
}
static void test_bus_path_encode_many(void) {
assert_se(sd_bus_path_decode_many("/prefix/foobar/suffix", "/prefix/%/suffix", &a) == 1 && streq_ptr(a, "foobar"));
assert_se(sd_bus_path_decode_many("/prefix/one_foo_two/mid/three_bar_four/suffix", "/prefix/one_%_two/mid/three_%_four/suffix", &b, &c) == 1 && streq_ptr(b, "foo") && streq_ptr(c, "bar"));
assert_se(sd_bus_path_decode_many("/prefix/one_foo_two/mid/three_bar_four/suffix", "/prefix/one_%_two/mid/three_%_four/suffix", NULL, &d) == 1 && streq_ptr(d, "bar"));
assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%%/suffix", NULL, NULL) == 0); /* multiple '%' are treated verbatim */
assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%/suffix", &e) == 1 && streq_ptr(e, "bar"));
assert_se(sd_bus_path_encode_many(&f, "/prefix/one_%_two/mid/three_%_four/suffix", "foo", "bar") >= 0 && streq_ptr(f, "/prefix/one_foo_two/mid/three_bar_four/suffix"));
}
static void test_bus_label_escape_one(const char *a, const char *b) {
assert_se(t = bus_label_escape(a));
assert_se(x = bus_label_unescape(t));
assert_se(y = bus_label_unescape(b));
}
static void test_bus_label_escape(void) {
}
int r, boolean;
const char *x, *x2, *y, *z, *a, *b, *c, *d, *a_signature;
uint8_t u, v;
char *h;
char *s;
double dbl;
r = sd_bus_default_system(&bus);
if (r < 0)
return EXIT_TEST_SKIP;
assert_se(r >= 0);
r = sd_bus_message_append(m, "");
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
r = sd_bus_message_append(m, "()");
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
r = sd_bus_message_close_container(m);
assert_se(r >= 0);
r = sd_bus_message_append_string_space(m, 5, &s);
assert_se(r >= 0);
strcpy(s, "hallo");
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
r = bus_message_seal(m, 4711, 0);
assert_se(r >= 0);
bus_message_dump(m, ms, 0);
assert_se(r >= 0);
assert_se(h);
free(h);
#ifdef HAVE_GLIB
{
GDBusMessage *g;
char *p;
#if !defined(GLIB_VERSION_2_36)
g_type_init();
#endif
p = g_dbus_message_print(g, 0);
log_info("%s", p);
g_free(p);
g_object_unref(g);
}
#endif
#ifdef HAVE_DBUS
{
DBusMessage *w;
if (!w)
else
}
#endif
m = sd_bus_message_unref(m);
assert_se(r >= 0);
bus_message_dump(m, ms, 0);
assert_se(sd_bus_message_rewind(m, true) >= 0);
assert_se(r > 0);
assert_se(r > 0);
assert_se(r > 0);
assert_se(u == 3);
assert_se(v == 5);
assert_se(r > 0);
assert_se(v == 8);
assert_se(u == 7);
assert_se(r > 0);
assert_se(v == 9);
assert_se(u == 77);
r = sd_bus_message_read(m, "y", &v);
assert_se(r > 0);
assert_se(v == 10);
r = sd_bus_message_read(m, "()");
assert_se(r > 0);
assert_se(r > 0);
assert_se(r > 0);
r = sd_bus_message_read_basic(m, 's', &s);
assert_se(r > 0);
assert_se(r > 0);
assert_se(r > 0);
assert_se(r > 0);
assert_se(r == 0);
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);
assert_se(r >= 0);
r = sd_bus_message_rewind(m, true);
assert_se(r >= 0);
r = sd_bus_message_skip(m, "ssasg");
assert_se(r > 0);
r = sd_bus_message_skip(m, "sass");
assert_se(r >= 0);
r = sd_bus_message_skip(m, "a{yv}y(ty)y(yt)y()");
assert_se(r >= 0);
assert_se(r > 0);
r = sd_bus_message_enter_container(m, 0, NULL);
assert_se(r > 0);
r = sd_bus_message_read(m, "(ss)", &x, &y);
assert_se(r > 0);
r = sd_bus_message_read(m, "(ss)", &a, &b);
assert_se(r > 0);
r = sd_bus_message_read(m, "(ss)", &c, &d);
assert_se(r > 0);
r = sd_bus_message_read(m, "(ss)", &x, &y);
assert_se(r == 0);
r = sd_bus_message_exit_container(m);
assert_se(r >= 0);
return 0;
}