0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek/*
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek Authors:
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek Copyright (C) 2014 Red Hat
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek SSSD tests: SBUS internals
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek This program is free software; you can redistribute it and/or modify
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek it under the terms of the GNU General Public License as published by
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek (at your option) any later version.
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek This program is distributed in the hope that it will be useful,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek GNU General Public License for more details.
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek You should have received a copy of the GNU General Public License
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek*/
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include <popt.h>
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include <dbus/dbus.h>
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include "util/util.h"
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include "responder/common/responder.h"
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include "tests/cmocka/common_mock.h"
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek#include "sbus/sssd_dbus_private.h"
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekstruct sbus_get_id_ctx {
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sss_test_ctx *stc;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_connection *conn;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusPendingCallNotifyFunction reply_handler;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek void *reply_pvt;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int last_hash_lookup;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int64_t expected;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek};
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekstruct sbus_get_id_ctx *global_test_ctx;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub HrozekDBusConnection *
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek__wrap_dbus_bus_get(DBusBusType type,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusError *error)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek /* just don't return NULL */
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return (DBusConnection *) 0x42;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek__wrap_dbus_connection_set_exit_on_disconnect(DBusConnection *connection,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek dbus_bool_t exit_on_disconnect)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_pending_call_unref(DBusPendingCall *pending)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_message_unref(DBusMessage *message)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_connection_unref(DBusConnection *connection)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub HrozekDBusMessage*
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek__wrap_dbus_pending_call_steal_reply(DBusPendingCall *pending)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return sss_mock_ptr_type(DBusMessage *);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint __real_hash_lookup(hash_table_t *table, hash_key_t *key, hash_value_t *value);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint __wrap_hash_lookup(hash_table_t *table, hash_key_t *key, hash_value_t *value)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx->last_hash_lookup = __real_hash_lookup(table, key, value);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return global_test_ctx->last_hash_lookup;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekstatic void fake_sbus_msg_done(struct tevent_context *ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct tevent_immediate *imm,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek void *pvt)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(pvt,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek talloc_free(imm);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->reply_handler(NULL, test_ctx->reply_pvt);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint sss_dbus_conn_send(DBusConnection *dbus_conn,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusMessage *msg,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int timeout_ms,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusPendingCallNotifyFunction reply_handler,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek void *pvt,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusPendingCall **pending)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct tevent_immediate *imm;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx->reply_pvt = pvt;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx->reply_handler = reply_handler;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek imm = tevent_create_immediate(global_test_ctx->stc->ev);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_non_null(imm);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_schedule_immediate(imm, global_test_ctx->stc->ev, fake_sbus_msg_done, global_test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return EOK;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekint sbus_get_id_test_setup(void **state)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int ret;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx = talloc(global_talloc_context, struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_non_null(test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn = talloc(test_ctx, struct sbus_connection);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_non_null(test_ctx->conn);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn->connection_type = SBUS_CONN_TYPE_SYSBUS;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = sss_hash_create(test_ctx->conn, 32, &test_ctx->conn->clients);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, EOK);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->stc = create_ev_test_ctx(test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_non_null(test_ctx->stc);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek *state = test_ctx;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx = test_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid_done(struct tevent_req *req)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek errno_t ret;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int64_t uid;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = tevent_req_callback_data(req,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = sbus_get_sender_id_recv(req, &uid);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek talloc_free(req);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, EOK);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->stc->done = true;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(uid, test_ctx->expected);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid(void **state)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek errno_t ret;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct tevent_req *req;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBusMessage *reply;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek uint32_t uid;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->expected = 42;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek uid = test_ctx->expected;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_non_null(reply);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek dbus_message_append_args(reply,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBUS_TYPE_UINT32, &uid,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek DBUS_TYPE_INVALID);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek will_return(__wrap_dbus_pending_call_steal_reply, reply);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek req = sbus_get_sender_id_send(test_ctx, test_ctx->stc->ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn, __FILE__);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_req_set_callback(req, sbus_int_test_get_uid_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = test_ev_loop(test_ctx->stc);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, EOK);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(test_ctx->last_hash_lookup, HASH_ERROR_KEY_NOT_FOUND);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek /* Now do the same lookup again, just make sure the result was cached */
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek req = sbus_get_sender_id_send(test_ctx, test_ctx->stc->ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn, __FILE__);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_req_set_callback(req, sbus_int_test_get_uid_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = test_ev_loop(test_ctx->stc);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, EOK);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(test_ctx->last_hash_lookup, HASH_SUCCESS);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid_no_sender_done(struct tevent_req *req)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek errno_t ret;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int64_t uid;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = tevent_req_callback_data(req,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = sbus_get_sender_id_recv(req, &uid);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek talloc_free(req);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, ERR_SBUS_NO_SENDER);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->stc->done = true;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid_no_sender(void **state)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek errno_t ret;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct tevent_req *req;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->expected = -1;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek req = sbus_get_sender_id_send(test_ctx, test_ctx->stc->ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn, NULL);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_req_set_callback(req, sbus_int_test_get_uid_no_sender_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ret = test_ev_loop(test_ctx->stc);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(ret, EOK);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekint sbus_get_id_test_teardown(void **state)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek talloc_free(test_ctx);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint main(int argc, const char *argv[])
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek{
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek poptContext pc;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek int opt;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct poptOption long_options[] = {
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek POPT_AUTOHELP
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek SSSD_DEBUG_OPTS
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek POPT_TABLEEND
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek };
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(sbus_int_test_get_uid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek sbus_get_id_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek sbus_get_id_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(sbus_int_test_get_uid_no_sender,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek sbus_get_id_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek sbus_get_id_test_teardown),
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek };
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek debug_level = SSSDBG_INVALID;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek switch(opt) {
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek default:
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek poptPrintUsage(pc, stderr, 0);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek return 1;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek }
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek }
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek poptFreeContext(pc);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tests_set_cwd();
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return cmocka_run_group_tests(tests, NULL, NULL);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek}