summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/test-bus-gvariant.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-bus/test-bus-gvariant.c')
-rw-r--r--src/libsystemd/sd-bus/test-bus-gvariant.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/libsystemd/sd-bus/test-bus-gvariant.c b/src/libsystemd/sd-bus/test-bus-gvariant.c
index 75804f3458..1a9a35d56b 100644
--- a/src/libsystemd/sd-bus/test-bus-gvariant.c
+++ b/src/libsystemd/sd-bus/test-bus-gvariant.c
@@ -1,6 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-***/
#if HAVE_GLIB
#include <glib.h>
@@ -15,11 +13,14 @@
#include "bus-message.h"
#include "bus-util.h"
#include "macro.h"
+#include "tests.h"
#include "util.h"
static void test_bus_gvariant_is_fixed_size(void) {
+ log_info("/* %s */", __func__);
+
assert_se(bus_gvariant_is_fixed_size("") > 0);
- assert_se(bus_gvariant_is_fixed_size("()") > 0);
+ assert_se(bus_gvariant_is_fixed_size("()") == -EINVAL);
assert_se(bus_gvariant_is_fixed_size("y") > 0);
assert_se(bus_gvariant_is_fixed_size("u") > 0);
assert_se(bus_gvariant_is_fixed_size("b") > 0);
@@ -43,8 +44,10 @@ static void test_bus_gvariant_is_fixed_size(void) {
}
static void test_bus_gvariant_get_size(void) {
+ log_info("/* %s */", __func__);
+
assert_se(bus_gvariant_get_size("") == 0);
- assert_se(bus_gvariant_get_size("()") == 1);
+ assert_se(bus_gvariant_get_size("()") == -EINVAL);
assert_se(bus_gvariant_get_size("y") == 1);
assert_se(bus_gvariant_get_size("u") == 4);
assert_se(bus_gvariant_get_size("b") == 1);
@@ -75,8 +78,10 @@ static void test_bus_gvariant_get_size(void) {
}
static void test_bus_gvariant_get_alignment(void) {
+ log_info("/* %s */", __func__);
+
assert_se(bus_gvariant_get_alignment("") == 1);
- assert_se(bus_gvariant_get_alignment("()") == 1);
+ assert_se(bus_gvariant_get_alignment("()") == -EINVAL);
assert_se(bus_gvariant_get_alignment("y") == 1);
assert_se(bus_gvariant_get_alignment("b") == 1);
assert_se(bus_gvariant_get_alignment("u") == 4);
@@ -115,20 +120,25 @@ static void test_bus_gvariant_get_alignment(void) {
assert_se(bus_gvariant_get_alignment("((t)(t))") == 8);
}
-static void test_marshal(void) {
+static int test_marshal(void) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *n = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
- _cleanup_free_ void *blob;
+ _cleanup_free_ void *blob = NULL;
size_t sz;
int r;
r = sd_bus_open_user(&bus);
if (r < 0)
- exit(EXIT_TEST_SKIP);
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ return log_tests_skipped_errno(r, "Failed to connect to bus");
bus->message_version = 2; /* dirty hack to enable gvariant */
- assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path/which/is/really/really/long/so/that/we/hit/the/eight/bit/boundary/by/quite/some/margin/to/test/this/stuff/that/it/really/works", "an.interface.name", "AMethodName") >= 0);
+ r = sd_bus_message_new_method_call(bus, &m, "a.service.name",
+ "/an/object/path/which/is/really/really/long/so/that/we/hit/the/eight/bit/boundary/by/quite/some/margin/to/test/this/stuff/that/it/really/works",
+ "an.interface.name", "AMethodName");
+ assert_se(r >= 0);
assert_cc(sizeof(struct bus_header) == 16);
@@ -196,14 +206,16 @@ static void test_marshal(void) {
assert_se(sd_bus_message_seal(m, 4712, 0) >= 0);
assert_se(bus_message_dump(m, NULL, BUS_MESSAGE_DUMP_WITH_HEADER) >= 0);
+
+ return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
+ test_setup_logging(LOG_DEBUG);
test_bus_gvariant_is_fixed_size();
test_bus_gvariant_get_size();
test_bus_gvariant_get_alignment();
- test_marshal();
- return 0;
+ return test_marshal();
}