|
|
71e593 |
From 57af8c95f5639e3ff61d4b1e9864fee8150cd2ba Mon Sep 17 00:00:00 2001
|
|
|
71e593 |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
71e593 |
Date: Thu, 16 Aug 2018 13:20:55 +0200
|
|
|
71e593 |
Subject: [PATCH 35/47] sbus: add unit tests for public sbus_message module
|
|
|
71e593 |
|
|
|
71e593 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
71e593 |
(cherry picked from commit c895fa2449900f4abd1dce6bb62a45c52bbb12cf)
|
|
|
71e593 |
---
|
|
|
71e593 |
Makefile.am | 14 +
|
|
|
71e593 |
src/tests/cmocka/sbus/test_sbus_message.c | 610 ++++++++++++++++++++++++++++++
|
|
|
71e593 |
2 files changed, 624 insertions(+)
|
|
|
71e593 |
create mode 100644 src/tests/cmocka/sbus/test_sbus_message.c
|
|
|
71e593 |
|
|
|
71e593 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
71e593 |
index 1602ec6236799015fa7fd9f1707cb2bcdb20e07b..c05c9312d74d2adab9dfe6d40987a791785da256 100644
|
|
|
71e593 |
--- a/Makefile.am
|
|
|
71e593 |
+++ b/Makefile.am
|
|
|
71e593 |
@@ -270,6 +270,7 @@ if HAVE_CMOCKA
|
|
|
71e593 |
test_copy_keytab \
|
|
|
71e593 |
test_child_common \
|
|
|
71e593 |
responder_cache_req-tests \
|
|
|
71e593 |
+ test_sbus_message \
|
|
|
71e593 |
test_sbus_opath \
|
|
|
71e593 |
test_fo_srv \
|
|
|
71e593 |
pam-srv-tests \
|
|
|
71e593 |
@@ -2593,6 +2594,19 @@ test_ssh_client_LDADD = \
|
|
|
71e593 |
$(SSSD_LIBS) \
|
|
|
71e593 |
$(NULL)
|
|
|
71e593 |
|
|
|
71e593 |
+test_sbus_message_SOURCES = \
|
|
|
71e593 |
+ src/tests/cmocka/sbus/test_sbus_message.c \
|
|
|
71e593 |
+ $(NULL)
|
|
|
71e593 |
+test_sbus_message_CFLAGS = \
|
|
|
71e593 |
+ $(AM_CFLAGS)
|
|
|
71e593 |
+test_sbus_message_LDADD = \
|
|
|
71e593 |
+ $(CMOCKA_LIBS) \
|
|
|
71e593 |
+ $(POPT_LIBS) \
|
|
|
71e593 |
+ libsss_debug.la \
|
|
|
71e593 |
+ libsss_test_common.la \
|
|
|
71e593 |
+ libsss_sbus.la \
|
|
|
71e593 |
+ $(NULL)
|
|
|
71e593 |
+
|
|
|
71e593 |
test_sbus_opath_SOURCES = \
|
|
|
71e593 |
src/tests/cmocka/sbus/test_sbus_opath.c \
|
|
|
71e593 |
$(NULL)
|
|
|
71e593 |
diff --git a/src/tests/cmocka/sbus/test_sbus_message.c b/src/tests/cmocka/sbus/test_sbus_message.c
|
|
|
71e593 |
new file mode 100644
|
|
|
71e593 |
index 0000000000000000000000000000000000000000..c01e16823237775f95b772534adb5639e264c057
|
|
|
71e593 |
--- /dev/null
|
|
|
71e593 |
+++ b/src/tests/cmocka/sbus/test_sbus_message.c
|
|
|
71e593 |
@@ -0,0 +1,610 @@
|
|
|
71e593 |
+/*
|
|
|
71e593 |
+ Authors:
|
|
|
71e593 |
+ Jakub Hrozek <jhrozek@redhat.com>
|
|
|
71e593 |
+ Pavel Březina <pbrezina@redhat.com>
|
|
|
71e593 |
+
|
|
|
71e593 |
+ Copyright (C) 2014 Red Hat
|
|
|
71e593 |
+
|
|
|
71e593 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
71e593 |
+ it under the terms of the GNU General Public License as published by
|
|
|
71e593 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
71e593 |
+ (at your option) any later version.
|
|
|
71e593 |
+
|
|
|
71e593 |
+ This program is distributed in the hope that it will be useful,
|
|
|
71e593 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
71e593 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
71e593 |
+ GNU General Public License for more details.
|
|
|
71e593 |
+
|
|
|
71e593 |
+ You should have received a copy of the GNU General Public License
|
|
|
71e593 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
71e593 |
+*/
|
|
|
71e593 |
+
|
|
|
71e593 |
+#include "config.h"
|
|
|
71e593 |
+
|
|
|
71e593 |
+#include <talloc.h>
|
|
|
71e593 |
+#include <errno.h>
|
|
|
71e593 |
+#include <popt.h>
|
|
|
71e593 |
+
|
|
|
71e593 |
+#include "util/util.h"
|
|
|
71e593 |
+#include "sbus/sbus_message.h"
|
|
|
71e593 |
+#include "tests/cmocka/common_mock.h"
|
|
|
71e593 |
+#include "tests/common.h"
|
|
|
71e593 |
+
|
|
|
71e593 |
+#define BASE_PATH "/some/path"
|
|
|
71e593 |
+
|
|
|
71e593 |
+struct test_ctx {
|
|
|
71e593 |
+ bool msg_removed;
|
|
|
71e593 |
+};
|
|
|
71e593 |
+
|
|
|
71e593 |
+static void helper_msg_removed(void *state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(state, struct test_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ test_ctx->msg_removed = true;
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+static void helper_msg_watch(struct test_ctx *test_ctx, DBusMessage *msg)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusFreeFunction free_fn;
|
|
|
71e593 |
+ dbus_int32_t data_slot = -1;
|
|
|
71e593 |
+ dbus_bool_t bret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ bret = dbus_message_allocate_data_slot(&data_slot);
|
|
|
71e593 |
+ assert_true(bret);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ free_fn = helper_msg_removed;
|
|
|
71e593 |
+ bret = dbus_message_set_data(msg, data_slot, test_ctx, free_fn);
|
|
|
71e593 |
+ assert_true(bret);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+static int test_setup(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_true(leak_check_setup());
|
|
|
71e593 |
+
|
|
|
71e593 |
+ test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
|
|
|
71e593 |
+ assert_non_null(test_ctx);
|
|
|
71e593 |
+ *state = test_ctx;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ check_leaks_push(test_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ return 0;
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+int test_teardown(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_true(check_leaks_pop(test_ctx));
|
|
|
71e593 |
+ talloc_zfree(test_ctx);
|
|
|
71e593 |
+ assert_true(leak_check_teardown());
|
|
|
71e593 |
+
|
|
|
71e593 |
+ return 0;
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound__null(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound(NULL, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EINVAL);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound(test_ctx, NULL);
|
|
|
71e593 |
+ assert_int_equal(ret, EINVAL);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound__unref(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound(test_ctx, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ /* no memory leak should be detected in teardown */
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound(tmp_ctx, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound_steal__null(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound_steal(NULL, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EINVAL);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound_steal(test_ctx, NULL);
|
|
|
71e593 |
+ assert_int_equal(ret, EINVAL);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound_steal__invalid(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound_steal(test_ctx, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, ERR_INTERNAL);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_message_bound_steal__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx_steal;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx_steal = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx_steal);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_message_bound(tmp_ctx, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ /* this will increase ref counter of message and add new talloc bound */
|
|
|
71e593 |
+ ret = sbus_message_bound_steal(tmp_ctx_steal, msg);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_false(test_ctx->msg_removed);
|
|
|
71e593 |
+ talloc_free(tmp_ctx_steal);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_method_create_empty__unref(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_method_create_empty(NULL, "bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_destination(msg), "bus.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_method_create_empty__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_method_create_empty(tmp_ctx, "bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_destination(msg), "bus.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_method_create__unref(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ dbus_bool_t dbret;
|
|
|
71e593 |
+ uint32_t in_value = 32;
|
|
|
71e593 |
+ uint32_t out_value;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_method_create(NULL, "bus.test", "/", "iface.test", "method",
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &in_value);
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_destination(msg), "bus.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbret = dbus_message_get_args(msg, NULL,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &out_value,
|
|
|
71e593 |
+ DBUS_TYPE_INVALID);
|
|
|
71e593 |
+ assert_true(dbret);
|
|
|
71e593 |
+ assert_int_equal(out_value, 32);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_method_create__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_method_create_empty(tmp_ctx, "bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_destination(msg), "bus.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_signal_create_empty__unref(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_signal_create_empty(NULL, "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_SIGNAL);
|
|
|
71e593 |
+ assert_null(dbus_message_get_destination(msg));
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_signal_create_empty__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_signal_create_empty(tmp_ctx, "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_SIGNAL);
|
|
|
71e593 |
+ assert_null(dbus_message_get_destination(msg));
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_signal_create__unref(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ dbus_bool_t dbret;
|
|
|
71e593 |
+ uint32_t in_value = 32;
|
|
|
71e593 |
+ uint32_t out_value;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_signal_create(NULL, "/", "iface.test", "method",
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &in_value);
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_SIGNAL);
|
|
|
71e593 |
+ assert_null(dbus_message_get_destination(msg));
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbret = dbus_message_get_args(msg, NULL,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &out_value,
|
|
|
71e593 |
+ DBUS_TYPE_INVALID);
|
|
|
71e593 |
+ assert_true(dbret);
|
|
|
71e593 |
+ assert_int_equal(out_value, 32);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_signal_create__free(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ struct test_ctx *test_ctx = talloc_get_type_abort(*state, struct test_ctx);
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ dbus_bool_t dbret;
|
|
|
71e593 |
+ uint32_t in_value = 32;
|
|
|
71e593 |
+ uint32_t out_value;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(test_ctx);
|
|
|
71e593 |
+ assert_non_null(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = sbus_signal_create(tmp_ctx, "/", "iface.test", "method",
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &in_value);
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ helper_msg_watch(test_ctx, msg);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ assert_int_equal(dbus_message_get_type(msg), DBUS_MESSAGE_TYPE_SIGNAL);
|
|
|
71e593 |
+ assert_null(dbus_message_get_destination(msg));
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_path(msg), "/");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_interface(msg), "iface.test");
|
|
|
71e593 |
+ assert_string_equal(dbus_message_get_member(msg), "method");
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbret = dbus_message_get_args(msg, NULL,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &out_value,
|
|
|
71e593 |
+ DBUS_TYPE_INVALID);
|
|
|
71e593 |
+ assert_true(dbret);
|
|
|
71e593 |
+ assert_int_equal(out_value, 32);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ assert_true(test_ctx->msg_removed);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_parse__ok(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ DBusMessage *reply;
|
|
|
71e593 |
+ dbus_bool_t dbret;
|
|
|
71e593 |
+ uint32_t in_value1 = 32;
|
|
|
71e593 |
+ uint32_t in_value2 = 64;
|
|
|
71e593 |
+ uint32_t out_value1;
|
|
|
71e593 |
+ uint32_t out_value2;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ reply = dbus_message_new_method_return(msg);
|
|
|
71e593 |
+ assert_non_null(reply);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbret = dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_value1,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &in_value2,
|
|
|
71e593 |
+ DBUS_TYPE_INVALID);
|
|
|
71e593 |
+ assert_true(dbret);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_parse(reply, DBUS_TYPE_UINT32, &out_value1,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &out_value2);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+ assert_int_equal(out_value1, in_value1);
|
|
|
71e593 |
+ assert_int_equal(out_value2, in_value2);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ dbus_message_unref(reply);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_parse__error(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ DBusMessage *reply;
|
|
|
71e593 |
+ uint32_t out_value1;
|
|
|
71e593 |
+ uint32_t out_value2;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ reply = dbus_message_new_error(msg, SBUS_ERROR_KILLED, "Test error!");
|
|
|
71e593 |
+ assert_non_null(reply);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_parse(reply, DBUS_TYPE_UINT32, &out_value1,
|
|
|
71e593 |
+ DBUS_TYPE_UINT32, &out_value2);
|
|
|
71e593 |
+ assert_int_equal(ret, ERR_SBUS_KILL_CONNECTION);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ dbus_message_unref(reply);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_parse__wrong_type(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_parse(msg);
|
|
|
71e593 |
+ assert_int_not_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_check__ok(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ DBusMessage *reply;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ reply = dbus_message_new_method_return(msg);
|
|
|
71e593 |
+ assert_non_null(reply);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_check(reply);
|
|
|
71e593 |
+ assert_int_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ dbus_message_unref(reply);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_check__error(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ DBusMessage *reply;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ reply = dbus_message_new_error(msg, SBUS_ERROR_KILLED, "Test error!");
|
|
|
71e593 |
+ assert_non_null(reply);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_check(reply);
|
|
|
71e593 |
+ assert_int_equal(ret, ERR_SBUS_KILL_CONNECTION);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+ dbus_message_unref(reply);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+void test_sbus_reply_check__wrong_type(void **state)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ DBusMessage *msg;
|
|
|
71e593 |
+ errno_t ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ msg = dbus_message_new_method_call("bus.test", "/", "iface.test", "method");
|
|
|
71e593 |
+ assert_non_null(msg);
|
|
|
71e593 |
+ dbus_message_set_serial(msg, 1);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sbus_reply_check(msg);
|
|
|
71e593 |
+ assert_int_not_equal(ret, EOK);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dbus_message_unref(msg);
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+int main(int argc, const char *argv[])
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ poptContext pc;
|
|
|
71e593 |
+ int opt;
|
|
|
71e593 |
+ struct poptOption long_options[] = {
|
|
|
71e593 |
+ POPT_AUTOHELP
|
|
|
71e593 |
+ SSSD_DEBUG_OPTS
|
|
|
71e593 |
+ POPT_TABLEEND
|
|
|
71e593 |
+ };
|
|
|
71e593 |
+
|
|
|
71e593 |
+ const struct CMUnitTest tests[] = {
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound__null,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound__unref,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound_steal__null,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound_steal__invalid,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_message_bound_steal__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_method_create_empty__unref,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_method_create_empty__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_method_create__unref,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_method_create__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_signal_create_empty__unref,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_signal_create_empty__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_signal_create__unref,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_signal_create__free,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_parse__ok,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_parse__error,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_parse__wrong_type,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_check__ok,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_check__error,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ cmocka_unit_test_setup_teardown(test_sbus_reply_check__wrong_type,
|
|
|
71e593 |
+ test_setup, test_teardown),
|
|
|
71e593 |
+ };
|
|
|
71e593 |
+
|
|
|
71e593 |
+ /* Set debug level to invalid value so we can decide if -d 0 was used. */
|
|
|
71e593 |
+ debug_level = SSSDBG_INVALID;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
|
|
|
71e593 |
+ while((opt = poptGetNextOpt(pc)) != -1) {
|
|
|
71e593 |
+ switch(opt) {
|
|
|
71e593 |
+ default:
|
|
|
71e593 |
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
|
|
|
71e593 |
+ poptBadOption(pc, 0), poptStrerror(opt));
|
|
|
71e593 |
+ poptPrintUsage(pc, stderr, 0);
|
|
|
71e593 |
+ return 1;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ poptFreeContext(pc);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ DEBUG_CLI_INIT(debug_level);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
71e593 |
+}
|
|
|
71e593 |
--
|
|
|
71e593 |
2.14.4
|
|
|
71e593 |
|