0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek Copyright (C) 2014 Red Hat
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek SSSD tests: SBUS internals
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 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 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 /* just don't return NULL */
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek__wrap_dbus_connection_set_exit_on_disconnect(DBusConnection *connection,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_pending_call_unref(DBusPendingCall *pending)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_message_unref(DBusMessage *message)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid __wrap_dbus_connection_unref(DBusConnection *connection)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek__wrap_dbus_pending_call_steal_reply(DBusPendingCall *pending)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint __real_hash_lookup(hash_table_t *table, hash_key_t *key, hash_value_t *value);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint __wrap_hash_lookup(hash_table_t *table, hash_key_t *key, hash_value_t *value)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx->last_hash_lookup = __real_hash_lookup(table, key, value);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekstatic void fake_sbus_msg_done(struct tevent_context *ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(pvt,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->reply_handler(NULL, test_ctx->reply_pvt);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekint sss_dbus_conn_send(DBusConnection *dbus_conn,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek global_test_ctx->reply_handler = reply_handler;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek imm = tevent_create_immediate(global_test_ctx->stc->ev);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_schedule_immediate(imm, global_test_ctx->stc->ev, fake_sbus_msg_done, global_test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx = talloc(global_talloc_context, struct sbus_get_id_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek test_ctx->conn = talloc(test_ctx, struct sbus_connection);
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 Hrozekvoid sbus_int_test_get_uid_done(struct tevent_req *req)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = tevent_req_callback_data(req,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek will_return(__wrap_dbus_pending_call_steal_reply, reply);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek req = sbus_get_sender_id_send(test_ctx, test_ctx->stc->ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_req_set_callback(req, sbus_int_test_get_uid_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(test_ctx->last_hash_lookup, HASH_ERROR_KEY_NOT_FOUND);
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 tevent_req_set_callback(req, sbus_int_test_get_uid_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek assert_int_equal(test_ctx->last_hash_lookup, HASH_SUCCESS);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid_no_sender_done(struct tevent_req *req)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = tevent_req_callback_data(req,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekvoid sbus_int_test_get_uid_no_sender(void **state)
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek req = sbus_get_sender_id_send(test_ctx, test_ctx->stc->ev,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek tevent_req_set_callback(req, sbus_int_test_get_uid_no_sender_done, test_ctx);
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek struct sbus_get_id_ctx *test_ctx = talloc_get_type(*state,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(sbus_int_test_get_uid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(sbus_int_test_get_uid_no_sender,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);