f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina/*
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina Authors:
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina Pavel Březina <pbrezina@redhat.com>
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina Copyright (C) 2014 Red Hat
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina This program is free software; you can redistribute it and/or modify
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina it under the terms of the GNU General Public License as published by
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina the Free Software Foundation; either version 3 of the License, or
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (at your option) any later version.
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina This program is distributed in the hope that it will be useful,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina GNU General Public License for more details.
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina You should have received a copy of the GNU General Public License
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina*/
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include <dbus/dbus.h>
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include <popt.h>
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include "tests/cmocka/common_mock.h"
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include "lib/sifp/sss_sifp.h"
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include "lib/sifp/sss_sifp_dbus.h"
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina#include "lib/sifp/sss_sifp_private.h"
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina#include "responder/ifp/ifp_iface.h"
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinastruct {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina} test_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel BřezinaDBusConnection *
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina__wrap_dbus_bus_get(DBusBusType type, DBusError *error)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* we won't use the connection anywhere, so we can just return NULL */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina return NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel BřezinaDBusMessage *
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina__wrap_dbus_connection_send_with_reply_and_block(DBusConnection *connection,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *message,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int timeout_milliseconds,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusError *error)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina if (message == NULL || error == NULL) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina return NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina return sss_mock_ptr_type(DBusMessage *);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinastatic void reply_variant_basic(DBusMessage *reply,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *type,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const void *val)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter variant_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina type, &variant_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* Now add the value */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&variant_iter, type[0], val);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &variant_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinastatic void reply_variant_array(DBusMessage *reply,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *type,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int num_vals,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint8_t *vals,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int item_size)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter variant_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter array_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char array_type[3];
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina void *addr;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina array_type[0] = DBUS_TYPE_ARRAY;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina array_type[1] = type[0];
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina array_type[2] = '\0';
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina array_type, &variant_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina type, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_vals; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina addr = vals + i*item_size;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&array_iter, type[0], addr);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &variant_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_setup(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_init(&test_ctx.dbus_ctx);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina test_ctx.reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(test_ctx.reply);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_teardown_parser(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free(&test_ctx.dbus_ctx);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(test_ctx.dbus_ctx);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_unref(test_ctx.reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina test_ctx.reply = NULL;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_teardown_api(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free(&test_ctx.dbus_ctx);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(test_ctx.dbus_ctx);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* sss_sifp is responsible for freeing the reply */
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strdup_valid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *str = "test_string";
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik char *dup_str = sss_sifp_strdup(test_ctx.dbus_ctx, str);
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik assert_non_null(dup_str);
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik assert_string_equal(str, dup_str);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik sss_sifp_free_string(test_ctx.dbus_ctx, &dup_str);
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik assert_null(dup_str);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strdup_null(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik char *dup_str = sss_sifp_strdup(test_ctx.dbus_ctx, NULL);
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik assert_null(dup_str);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strcat_valid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, "hello ", "world");
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal("hello world", cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strcat_left_null(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, NULL, "world");
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal("world", cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strcat_right_null(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, "hello ", NULL);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal("hello ", cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_strcat_both_null(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, NULL, NULL);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(cat);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_object_path_valid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in = "/object/path";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_object_path(ctx, reply, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in, path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_object_path_invalid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t path_in = 10;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_UINT16, &path_in,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_object_path(ctx, reply, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_not_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_object_path_list_valid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char **path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in[] = {"/object/path1", "/object/path2"};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char **paths = path_in;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int path_in_len = 2;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_OBJECT_PATH,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &paths, path_in_len,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_object_path_list(ctx, reply, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; path_out[i] != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(i < path_in_len);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in[i], path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string_array(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_object_path_list_invalid(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char **path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in = "/object/path";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_object_path_list(ctx, reply, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_not_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_bool(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t in = 1;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bool out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_BOOLEAN_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_bool(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(in == out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int16(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int16_t in = INT16_MIN;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int16_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_INT16_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int16(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint16(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t in = UINT16_MAX;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_UINT16_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint16(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int32(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int32_t in = INT32_MIN;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int32_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_INT32_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int32(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint32(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t in = UINT32_MAX;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_UINT32_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint32(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int64(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int64_t in = INT64_MIN;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int64_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_INT64_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int64(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint64(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint64_t in = UINT64_MAX;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint64_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_UINT64_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint64(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_string(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *in = "test value";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_STRING_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_string(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_object_path(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *in = "/object/path";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_string(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březinavoid test_sss_sifp_parse_attr_string_dict(void **state)
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina{
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessage *reply = test_ctx.reply;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter var_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter array_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter dict_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina dbus_bool_t bret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_error ret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_attr **attrs = NULL;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *name = "test-attr";
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina struct {
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *key;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *value;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina } data = {"key", "value"};
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_table_t *out;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_key_t key;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_value_t value;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina char **values;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina int hret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina /* prepare message */
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina dbus_message_iter_init_append(reply, &iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_ARRAY_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &var_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&var_iter, DBUS_TYPE_ARRAY,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &array_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&array_iter,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_DICT_ENTRY,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina NULL, &dict_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &data.key);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &data.value);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&var_iter, &array_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&iter, &var_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(attrs[0]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(attrs[1]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(attrs[0]->num_values, 1);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING_DICT);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_string_equal(attrs[0]->name, name);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina ret = sss_sifp_find_attr_as_string_dict(attrs, name, &out);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(hash_count(out), 1);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina key.type = HASH_KEY_STRING;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina key.str = discard_const(data.key);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hret = hash_lookup(out, &key, &value);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(hret, HASH_SUCCESS);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(value.type, HASH_VALUE_PTR);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(value.ptr);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina values = value.ptr;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(values[0]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_string_equal(values[0], data.value);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(values[1]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_free_attrs(ctx, &attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina}
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_bool_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t in_array[] = {1, 1, 0, 0, 1};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bool *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_BOOLEAN_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(dbus_bool_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_bool_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(in[i] == out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_bool_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina bool *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_BOOLEAN_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(dbus_bool_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_bool_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int16_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int16_t in_array[] = {10, 15, -10, -15, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int16_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int16_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_INT16_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(int16_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int16_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_int16_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina int16_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_INT16_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(int16_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_int16_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint16_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t in_array[] = {10, 15, 8885, 3224, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint16_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_UINT16_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(uint16_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint16_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_uint16_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina uint16_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_UINT16_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(uint16_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_uint16_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int32_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int32_t in_array[] = {10, 15, -10, -15, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int32_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int32_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_INT32_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(int32_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int32_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_int32_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina int32_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_INT32_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(int32_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_int32_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint32_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t in_array[] = {10, 15, 8885, 3224, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_UINT32_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(uint32_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint32_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_uint32_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina uint32_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_UINT32_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(uint32_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_uint32_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_int64_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int64_t in_array[] = {10, 15, -10, -15, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int64_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int64_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_INT64_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(int64_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_int64_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_int64_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina int64_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_INT64_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(int64_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_int64_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_uint64_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 5;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint64_t in_array[] = {10, 15, 8885, 3224, 5559};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint64_t *in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint64_t *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_UINT64_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(uint64_t));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint64_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_uint64_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina uint64_t *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_UINT64_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(uint64_t));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_uint64_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_string_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 6;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *in_array[] = {"I", "don't", "like", "writing", "unit", "tests"};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char **in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char * const *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_array(reply, DBUS_TYPE_STRING_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(const char*));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_string_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char * const *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_STRING_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(const char*));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_object_path_array(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int num_values = 2;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *in_array[] = {"/object/path1", "/object/path2"};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char **in = in_array;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int out_num;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char * const *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina unsigned int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
b7080f1a2c6c97224c41f6347ca3743e1054faecPavel Březina reply_variant_array(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, num_values,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina (uint8_t*)in, sizeof(const char*));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, num_values);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(num_values, out_num);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; i < num_values; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(in[i], out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březinavoid test_sss_sifp_parse_attr_object_path_array_empty(void **state)
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina{
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina DBusMessage *reply = test_ctx.reply;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_error ret;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_attr **attrs = NULL;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char *name = "test-attr";
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int num_values = 0;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina unsigned int out_num;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina const char * const *out;
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* prepare message */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina reply_variant_array(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, num_values,
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina NULL, sizeof(const char*));
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina /* test */
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_OK);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_non_null(attrs[0]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs[1]);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->num_values, num_values);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_string_equal(attrs[0]->name, name);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_int_equal(num_values, out_num);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(out);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina sss_sifp_free_attrs(ctx, &attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina assert_null(attrs);
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina}
973be642f3d33ba21ea9c06791295f09efcdba46Pavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březinavoid test_sss_sifp_parse_attr_string_dict_array(void **state)
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina{
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina return;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessage *reply = test_ctx.reply;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter var_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter array_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter dict_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBusMessageIter val_iter;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina dbus_bool_t bret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_error ret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_attr **attrs = NULL;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *name = "test-attr";
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina static struct {
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *key;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina const char *values[];
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina } data = {"key", {"value1", "value2", "value3"}};
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina unsigned int num_values = 3;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_table_t *out;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_key_t key;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hash_value_t value;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina char **values;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina unsigned int i;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina int hret;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina /* prepare message */
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina dbus_message_iter_init_append(reply, &iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_ARRAY_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_ARRAY_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &var_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&var_iter, DBUS_TYPE_ARRAY,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_ARRAY_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &array_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&array_iter,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_DICT_ENTRY,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina NULL, &dict_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &data.key);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_ARRAY,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina DBUS_TYPE_STRING_AS_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &val_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina for (i = 0; i < num_values; i++) {
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_append_basic(&val_iter, DBUS_TYPE_STRING,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina &data.values[i]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina }
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&dict_iter, &val_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&var_iter, &array_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina bret = dbus_message_iter_close_container(&iter, &var_iter);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_true(bret);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(attrs[0]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(attrs[1]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(attrs[0]->num_values, 1);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING_DICT);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_string_equal(attrs[0]->name, name);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina ret = sss_sifp_find_attr_as_string_dict(attrs, name, &out);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(hash_count(out), 1);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina key.type = HASH_KEY_STRING;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina key.str = discard_const(data.key);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina hret = hash_lookup(out, &key, &value);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(hret, HASH_SUCCESS);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_int_equal(value.type, HASH_VALUE_PTR);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(value.ptr);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina values = value.ptr;
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina for (i = 0; i < num_values; i++) {
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_non_null(values[i]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_string_equal(values[i], data.values[i]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina }
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(values[i]);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina sss_sifp_free_attrs(ctx, &attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina assert_null(attrs);
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina}
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_list(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter array_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter dict_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter var_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina struct {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t value;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina } data[] = {{"attr1", 1}, {"attr2", 2}, {"attr3", 3}, {NULL, 0}};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_STRING_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_VARIANT_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&array_iter,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_DICT_ENTRY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina NULL, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_UINT32_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_UINT32,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].value);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr_list(ctx, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[i]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[i]->type, SSS_SIFP_ATTR_TYPE_UINT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[i]->name, data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint32(attrs, data[i].name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(data[i].value, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_parse_attr_list_empty(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter array_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_STRING_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_VARIANT_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_parse_attr_list(ctx, reply, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_fetch_attr(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name = "test-attr";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t in = UINT32_MAX;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina reply_variant_basic(reply, DBUS_TYPE_UINT32_AS_STRING, &in);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_fetch_attr(ctx, "/test/object", "test.com", name, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[0]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[1]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[0]->name, name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint32(attrs, name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(in, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_fetch_all_attrs(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter array_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter dict_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter var_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_attr **attrs = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina struct {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t value;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina } data[] = {{"attr1", 1}, {"attr2", 2}, {"attr3", 3}, {NULL, 0}};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina uint32_t out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_STRING_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_VARIANT_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&array_iter,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_DICT_ENTRY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina NULL, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_UINT32_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_UINT32,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].value);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_fetch_all_attrs(ctx, "/test/object", "test.com", &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[i]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(attrs[i]->type, SSS_SIFP_ATTR_TYPE_UINT32);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(attrs[i]->name, data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_uint32(attrs, data[i].name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(data[i].value, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_attrs(ctx, &attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_fetch_object(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter array_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter dict_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessageIter var_iter;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path = "/test/object";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *iface = "test.com";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_object *object = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina struct {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *name;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *value;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina } data[] = {{"name", "test-object"}, {"a1", "a"}, {"a2", "b"}, {NULL, 0}};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *out;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_message_iter_init_append(reply, &iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_STRING_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_VARIANT_AS_STRING
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&array_iter,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_DICT_ENTRY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina NULL, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_STRING_AS_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_STRING,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &data[i].value);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_fetch_object(ctx, path, iface, &object);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object->attrs);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object->name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object->object_path);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object->interface);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(object->name, "test-object");
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(object->object_path, path);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(object->interface, iface);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; data[i].name != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(object->attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(object->attrs[i]->num_values, 1);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(object->attrs[i]->type, SSS_SIFP_ATTR_TYPE_STRING);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(object->attrs[i]->name, data[i].name);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina ret = sss_sifp_find_attr_as_string(object->attrs, data[i].name, &out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(data[i].value, out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(object->attrs[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_object(ctx, &object);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(object);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_invoke_list_zeroargs(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char **path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in[] = {"/object/path1", "/object/path2"};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char **paths = path_in;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int path_in_len = 2;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_OBJECT_PATH,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &paths, path_in_len,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina ret = sss_sifp_invoke_list_ex(ctx, SSS_SIFP_PATH, SSS_SIFP_IFACE,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina "MyMethod", &path_out, DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; path_out[i] != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(i < path_in_len);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in[i], path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string_array(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_invoke_list_withargs(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char **path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in[] = {"/object/path1", "/object/path2"};
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char **paths = path_in;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *arg = "first-arg";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int path_in_len = 2;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int i;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_OBJECT_PATH,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina &paths, path_in_len,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina ret = sss_sifp_invoke_list_ex(ctx, SSS_SIFP_PATH, SSS_SIFP_IFACE,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina "MyMethod", &path_out,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina DBUS_TYPE_STRING, &arg,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina for (i = 0; path_out[i] != NULL; i++) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(i < path_in_len);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in[i], path_out[i]);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string_array(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_invoke_find_zeroargs(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in = "/object/path";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina ret = sss_sifp_invoke_find_ex(ctx, SSS_SIFP_PATH, SSS_SIFP_IFACE,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina "MyMethod", &path_out, DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in, path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinavoid test_sss_sifp_invoke_find_withargs(void **state)
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBusMessage *reply = test_ctx.reply;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina dbus_bool_t bret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_error ret;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *path_in = "/object/path";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina char *path_out = NULL;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina const char *arg = "first-arg";
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* prepare message */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_true(bret);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* test */
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina ret = sss_sifp_invoke_find_ex(ctx, SSS_SIFP_PATH, SSS_SIFP_IFACE,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina "MyMethod", &path_out,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina DBUS_TYPE_STRING, &arg,
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina DBUS_TYPE_INVALID);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_non_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_string_equal(path_in, path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina sss_sifp_free_string(ctx, &path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina assert_null(path_out);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březinavoid test_sss_sifp_list_domains(void **state)
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina{
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessage *msg_paths = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessage *msg_ldap = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessage *msg_ipa = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina dbus_bool_t bret;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_error ret;
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina const char *in[] = {SSS_SIFP_PATH "/Domains/LDAP",
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina SSS_SIFP_PATH "/Domains/IPA"};
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char **paths = in;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char *names[] = {"LDAP", "IPA"};
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina char **out = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina int in_len = 2;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina int i;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina msg_paths = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(msg_paths);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina msg_ldap = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(msg_ldap);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina msg_ipa = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(msg_ipa);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* prepare message */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_append_args(msg_paths, DBUS_TYPE_ARRAY,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_OBJECT_PATH,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina &paths, in_len,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_INVALID);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina reply_variant_basic(msg_ldap, DBUS_TYPE_STRING_AS_STRING, &names[0]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina reply_variant_basic(msg_ipa, DBUS_TYPE_STRING_AS_STRING, &names[1]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_paths);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_ldap);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_ipa);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* test */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina ret = sss_sifp_list_domains(ctx, &out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina for (i = 0; i < in_len; i++) {
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out[i]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_string_equal(out[i], names[i]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina }
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_null(out[i]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_free_string_array(ctx, &out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_null(out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* messages are unrefed in the library */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina}
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březinavoid test_sss_sifp_fetch_domain_by_name(void **state)
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina{
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessage *msg_path = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessage *msg_props = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessageIter iter;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessageIter array_iter;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessageIter dict_iter;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBusMessageIter var_iter;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina dbus_bool_t bret;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_error ret;
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina const char *in =SSS_SIFP_PATH "/Domains/LDAP";
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char *name = "LDAP";
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char *prop = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_object *out = NULL;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina struct {
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char *name;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina const char *value;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina } props[] = {{"name", name}, {"a1", "a"}, {"a2", "b"}, {NULL, 0}};
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina int i;
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina msg_path = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(msg_path);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina msg_props = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(msg_props);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* prepare message */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_append_args(msg_path, DBUS_TYPE_OBJECT_PATH, &in,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_INVALID);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina dbus_message_iter_init_append(msg_props, &iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_STRING_AS_STRING
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_VARIANT_AS_STRING
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina &array_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina for (i = 0; props[i].name != NULL; i++) {
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_open_container(&array_iter,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_DICT_ENTRY,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina NULL, &dict_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina &props[i].name);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina DBUS_TYPE_STRING_AS_STRING,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina &var_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_STRING,
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina &props[i].value);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina }
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina bret = dbus_message_iter_close_container(&iter, &array_iter);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_true(bret);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_path);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_props);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* test */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina ret = sss_sifp_fetch_domain_by_name(ctx, name, &out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out->attrs);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out->name);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out->object_path);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out->interface);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_string_equal(out->name, name);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_string_equal(out->object_path, in);
2a45f13e3139063d3a5842119e7377c8c98aea1dPavel Březina assert_string_equal(out->interface, IFACE_IFP_DOMAINS);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina for (i = 0; props[i].name != NULL; i++) {
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_non_null(out->attrs[i]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_int_equal(out->attrs[i]->num_values, 1);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_int_equal(out->attrs[i]->type, SSS_SIFP_ATTR_TYPE_STRING);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_string_equal(out->attrs[i]->name, props[i].name);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina ret = sss_sifp_find_attr_as_string(out->attrs, props[i].name, &prop);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_int_equal(ret, SSS_SIFP_OK);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_string_equal(props[i].value, prop);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina }
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_null(out->attrs[i]);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina sss_sifp_free_object(ctx, &out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina assert_null(out);
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina /* messages are unrefed in the library */
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina}
0bb98b7700b1b61f5b0a20b93279d5c2c391007fPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březinaint main(int argc, const char *argv[])
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina{
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int rv;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int no_cleanup = 0;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina poptContext pc;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina int opt;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina struct poptOption long_options[] = {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina POPT_AUTOHELP
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina SSSD_DEBUG_OPTS
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina _("Do not delete the test database after a test run"), NULL },
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina POPT_TABLEEND
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina };
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strdup_valid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strdup_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_valid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_left_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_right_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_both_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_valid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_invalid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_list_valid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_list_invalid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int16,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint16,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_dict,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path_array_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_dict_array,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_list,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_list_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_parser),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_attr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_all_attrs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_object,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_list_zeroargs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_list_withargs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_find_zeroargs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_find_withargs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_list_domains,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_domain_by_name,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_setup, test_teardown_api),
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina };
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina /* Set debug level to invalid value so we can deside if -d 0 was used. */
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina debug_level = SSSDBG_INVALID;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina while((opt = poptGetNextOpt(pc)) != -1) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina switch(opt) {
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina default:
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina fprintf(stderr, "\nInvalid option %s: %s\n\n",
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina poptBadOption(pc, 0), poptStrerror(opt));
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina poptPrintUsage(pc, stderr, 0);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina return 1;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina }
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina poptFreeContext(pc);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina return rv;
f43c6a9ae2aea13b7a83fd932139f9352efbfcadPavel Březina}