b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter/*
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter SSSD
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter sbus_codegen tests.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Authors:
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Stef Walter <stefw@redhat.com>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Copyright (C) Red Hat, Inc 2014
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter This program is free software; you can redistribute it and/or modify
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter it under the terms of the GNU General Public License as published by
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter the Free Software Foundation; either version 3 of the License, or
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter (at your option) any later version.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter This program is distributed in the hope that it will be useful,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter but WITHOUT ANY WARRANTY; without even the implied warranty of
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter GNU General Public License for more details.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter You should have received a copy of the GNU General Public License
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter along with this program. If not, see <http://www.gnu.org/licenses/>.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter*/
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik#include <stdint.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include <stdlib.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include <check.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include <talloc.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include <tevent.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include <popt.h>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include "sbus/sssd_dbus_meta.h"
1203e462650f035b0df2304075d60b9a99e36715Stef Walter#include "tests/common.h"
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter#include "tests/sbus_codegen_tests_generated.h"
1203e462650f035b0df2304075d60b9a99e36715Stef Walter#include "util/util_errors.h"
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik/* The following 2 macros were taken from check's project source files (0.9.10)
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik * http://check.sourceforge.net/
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik */
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#ifndef _ck_assert_uint
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#define _ck_assert_uint(X, OP, Y) do { \
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik uintmax_t _ck_x = (X); \
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik uintmax_t _ck_y = (Y); \
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik} while (0)
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#endif /* _ck_assert_uint */
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#ifndef ck_assert_uint_eq
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#endif /* ck_assert_uint_eq */
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstatic const struct sbus_arg_meta *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterfind_arg(const struct sbus_arg_meta *args,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *arg;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter for (arg = args; arg->name != NULL; arg++) {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter if (strcmp (arg->name, name) == 0)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return arg;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter }
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return NULL;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterSTART_TEST(test_interfaces)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(com_planetexpress_Ship_meta.name, "com.planetexpress.Ship");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(com_planetexpress_Ship_meta.methods != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(com_planetexpress_Ship_meta.signals != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(com_planetexpress_Ship_meta.properties != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter /* Explicit C Symbol */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot");
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter ck_assert(test_pilot_meta.methods != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(test_pilot_meta.signals == NULL); /* no signals */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(test_pilot_meta.properties != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterEND_TEST
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterSTART_TEST(test_methods)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_method_meta *method;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *arg;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(method != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(method->name, "MoveUniverse");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(method->in_args != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(method->out_args != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter arg = find_arg(method->in_args, "smoothly");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(arg != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->name, "smoothly");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->type, "b");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter arg = find_arg(method->out_args, "where_we_crashed");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(arg != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->name, "where_we_crashed");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->type, "s");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterEND_TEST
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterSTART_TEST(test_properties)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_property_meta *prop;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter prop = sbus_meta_find_property(&com_planetexpress_Ship_meta, "Color");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(prop != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(prop->name, "Color");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(prop->type, "s");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_int_eq(prop->flags, SBUS_PROPERTY_READABLE);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterEND_TEST
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterSTART_TEST(test_signals)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio const struct sbus_signal_meta *sig;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const struct sbus_arg_meta *arg;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio sig = sbus_meta_find_signal(&com_planetexpress_Ship_meta, "BecameSentient");
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio ck_assert(sig != NULL);
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio ck_assert_str_eq(sig->name, "BecameSentient");
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio ck_assert(sig->args != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio arg = find_arg(sig->args, "gender");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(arg != NULL);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->name, "gender");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->type, "s");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef WalterEND_TEST
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walterstatic int
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltermock_move_universe(struct sbus_request *dbus_req, void *data,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter bool arg_smoothly, uint32_t arg_speed_factor)
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter{
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter /*
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * The above arguments should match the handler signature,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * and the below finish function should have the right signature.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter *
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter */
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter ck_assert(FALSE);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter return com_planetexpress_Ship_MoveUniverse_finish(dbus_req, "here");
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter}
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walterstatic int
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltermock_crash_now(struct sbus_request *dbus_req, void *data,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter const char *where)
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter{
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter /*
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * One argument, no return value, yet a finish function should
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * have been generated.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter *
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter */
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter ck_assert(FALSE);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter return com_planetexpress_Ship_crash_now_finish(dbus_req);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter}
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walterstatic int
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltermock_land(struct sbus_request *req, void *data)
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter{
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter /*
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Raw handler, no finish function, no special arguments.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter *
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter */
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter ck_assert(FALSE);
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter return 0;
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter}
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef WalterSTART_TEST(test_vtable)
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter{
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter struct com_planetexpress_Ship vtable = {
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter { &com_planetexpress_Ship_meta, 0 },
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter mock_move_universe,
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter mock_crash_now,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter mock_land,
c3c6eb141d6a288b3da20ad6a2e5718844b2d4adPavel Reichl NULL,
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter };
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter /*
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter * These are not silly tests:
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter * - Will fail compilation if c-symbol name was not respected
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter * - Will fail if method order was not respected
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter */
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter ck_assert(vtable.crash_now == mock_crash_now);
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter ck_assert(vtable.MoveUniverse == mock_move_universe);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter ck_assert(vtable.Land == mock_land);
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter}
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef WalterEND_TEST
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter
c2cc119de8eac712c040b3993f41c967ff2278deStef WalterSTART_TEST(test_constants)
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter{
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(COM_PLANETEXPRESS_SHIP, "com.planetexpress.Ship");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE, "MoveUniverse");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_CRASH_NOW, "Crash");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_BECAMESENTIENT, "BecameSentient");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_COLOR, "Color");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter /* constants for com.planetexpress.Pilot */
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(TEST_PILOT, "com.planetexpress.Pilot");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter ck_assert_str_eq(TEST_PILOT_FULLNAME, "FullName");
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter}
c2cc119de8eac712c040b3993f41c967ff2278deStef WalterEND_TEST
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef WalterTCase *create_defs_tests(void)
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter TCase *tc = tcase_create("defs");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter /* Do some testing */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter tcase_add_test(tc, test_interfaces);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter tcase_add_test(tc, test_methods);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter tcase_add_test(tc, test_properties);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter tcase_add_test(tc, test_signals);
fcd8093c58638dc7c4f9cddfc97f273b94ce2eadStef Walter tcase_add_test(tc, test_vtable);
c2cc119de8eac712c040b3993f41c967ff2278deStef Walter tcase_add_test(tc, test_constants);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter return tc;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter}
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter/* This is a handler which has all the basic arguments types */
1203e462650f035b0df2304075d60b9a99e36715Stef Walterstatic int eject_handler(struct sbus_request *req, void *instance_data,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint8_t arg_byte, bool arg_boolean,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int16_t arg_int16, uint16_t arg_uint16, int32_t arg_int32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint32_t arg_uint32, int64_t arg_int64, uint64_t arg_uint64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter double arg_double, const char *arg_string, const char *arg_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint8_t arg_byte_array[], int len_byte_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int16_t arg_int16_array[], int len_int16_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint16_t arg_uint16_array[], int len_uint16_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int32_t arg_int32_array[], int len_int32_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint32_t arg_uint32_array[], int len_uint32_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int64_t arg_int64_array[], int len_int64_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint64_t arg_uint64_array[], int len_uint64_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter double arg_double_array[], int len_double_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter const char *arg_string_array[], int len_string_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter const char *arg_object_path_array[], int len_object_path_array)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter{
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int i;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter /* Only called for leela, so double check here */
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(instance_data, "Crash into the billboard");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter /* Murge the various values for test case */
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_byte, 11);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_byte++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arg_boolean == TRUE);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_boolean = !arg_boolean;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arg_int16, -2222);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int16++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_uint16, 3333);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint16++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arg_int32, -44444444);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int32++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_uint32, 55555555);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint32++;
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_int64 == INT64_C(-6666666666666666));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int64++;
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_uint64 == UINT64_C(7777777777777777));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint64++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arg_double == 1.1);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_double++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_string, "hello");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string = "bears, beets, battlestar galactica";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_object_path, "/original/object/path");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_object_path = "/another/object/path";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_byte_array = talloc_memdup(req, arg_byte_array, sizeof(uint8_t) * len_byte_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_byte_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_byte_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int16_array = talloc_memdup(req, arg_int16_array, sizeof(int16_t) * len_int16_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_int16_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int16_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter len_int16_array--;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint16_array = talloc_memdup(req, arg_uint16_array, sizeof(uint16_t) * len_uint16_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_uint16_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint16_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int32_array = talloc_memdup(req, arg_int32_array, sizeof(int32_t) * len_int32_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_int32_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int32_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter len_int32_array--;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint32_array = talloc_memdup(req, arg_uint32_array, sizeof(uint32_t) * len_uint32_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_uint32_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint32_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int64_array = talloc_memdup(req, arg_int64_array, sizeof(int64_t) * len_int64_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_int64_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int64_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint64_array = talloc_memdup(req, arg_uint64_array, sizeof(uint64_t) * len_uint64_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_uint64_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint64_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_double_array = talloc_memdup(req, arg_double_array, sizeof(double) * len_double_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_double_array; i++)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_double_array[i]++;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string_array = talloc_memdup(req, arg_string_array, sizeof(char *) * len_string_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_double_array; i++) {
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_string_array[i], "bears");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string_array[i] = "beets";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter }
1203e462650f035b0df2304075d60b9a99e36715Stef Walter len_string_array--;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_object_path_array = talloc_memdup(req, arg_object_path_array, sizeof(char *) * len_object_path_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter for (i = 0; i < len_object_path_array; i++) {
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_object_path_array[i], "/original");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_object_path_array[i] = "/changed";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter }
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter /* And reply with those values */
1203e462650f035b0df2304075d60b9a99e36715Stef Walter return test_pilot_Eject_finish(req, arg_byte, arg_boolean, arg_int16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint16, arg_int32, arg_uint32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int64, arg_uint64, arg_double,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string, arg_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_byte_array, len_byte_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int16_array, len_int16_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint16_array, len_uint16_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int32_array, len_int32_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint32_array, len_uint32_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_int64_array, len_int64_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_uint64_array, len_uint64_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_double_array, len_double_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string_array, len_string_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_object_path_array, len_object_path_array);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter}
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define getter_body(in, out) do { \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(dbus_req != NULL); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(out != NULL); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *out = in; \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek} while(0);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const bool pilot_bool = true;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_boolean_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek bool *val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_bool, val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_full_name = "Turanga Leela";
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_full_name_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **name)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_full_name, name);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const uint8_t pilot_byte = 42;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_byte_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint8_t *byte)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_byte, byte);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const int16_t pilot_int16 = -123;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int16_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int16_t *int16)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_int16, int16);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const uint16_t pilot_uint16 = 123;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint16_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint16_t *uint16)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_uint16, uint16);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const int32_t pilot_int32 = -456;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int32_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int32_t *int32)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_int32, int32);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const uint32_t pilot_uint32 = 456;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint32_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint32_t *uint32)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_uint32, uint32);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const int64_t pilot_int64 = -456;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int64_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int64_t *int64)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_int64, int64);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const uint64_t pilot_uint64 = 456;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint64_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint64_t *uint64)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_uint64, uint64);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const double pilot_double = 3.14;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_double_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek double *double_val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek getter_body(pilot_double, double_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_string = "leela";
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_string_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **string_val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *string_val = pilot_string;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_path = "/path/leela";
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_objpath_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **path_val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *path_val = pilot_path;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
58229439447d5617913a5a2e173b78105c694842Pavel Březinavoid pilot_get_null_string_handler(struct sbus_request *dbus_req,
58229439447d5617913a5a2e173b78105c694842Pavel Březina void *instance_data,
58229439447d5617913a5a2e173b78105c694842Pavel Březina const char **string_val)
58229439447d5617913a5a2e173b78105c694842Pavel Březina{
58229439447d5617913a5a2e173b78105c694842Pavel Březina *string_val = NULL;
58229439447d5617913a5a2e173b78105c694842Pavel Březina}
58229439447d5617913a5a2e173b78105c694842Pavel Březina
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozekvoid pilot_get_null_path_handler(struct sbus_request *dbus_req,
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek void *instance_data,
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek const char **path_val)
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek{
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek *path_val = NULL;
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek}
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define array_getter_body(in, out, outlen) do { \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(dbus_req != NULL); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(out != NULL); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(outlen != NULL); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *out = in; \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *outlen = N_ELEMENTS(in); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek} while(0);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint8_t pilot_byte_array[] = { 42, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_byte_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint8_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_byte_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int16_t pilot_int16_array[] = { -123, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int16_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int16_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int16_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint16_t pilot_uint16_array[] = { 123, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint16_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint16_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint16_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int32_t pilot_int32_array[] = { -456, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int32_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int32_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int32_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint32_t pilot_uint32_array[] = { 456, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint32_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint32_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint32_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int64_t pilot_int64_array[] = { -789, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int64_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int64_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int64_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint64_t pilot_uint64_array[] = { 789, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint64_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint64_t **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint64_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic double pilot_double_array[] = { 3.14, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_double_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *instance_data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek double **arr_out, int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_double_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_string_array[] = { "Turanga", "Leela" };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_string_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char ***arr_out,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_string_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_path_array[] = { "/some/path", "/another/path" };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_path_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *data,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char ***arr_out,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int *arr_len)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_path_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
ac744223411099a862a747e7168a30255c003bf7Pavel Březinavoid special_get_array_dict_sas(struct sbus_request *sbus_req,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina void *data,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hash_table_t **_out)
ac744223411099a862a747e7168a30255c003bf7Pavel Březina{
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hash_table_t *table;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hash_key_t key;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hash_value_t value;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina char **values;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina errno_t ret;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina int hret;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina *_out = NULL;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ret = sss_hash_create(sbus_req, 10, &table);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(ret, EOK);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values = talloc_zero_array(table, char *, 3);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values[0] = talloc_strdup(values, "hello1");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values[1] = talloc_strdup(values, "world1");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values[0] != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values[1] != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina key.type = HASH_KEY_STRING;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina key.str = talloc_strdup(table, "key1");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina value.type = HASH_VALUE_PTR;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina value.ptr = values;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hret = hash_enter(table, &key, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(hret, HASH_SUCCESS);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values = talloc_zero_array(table, char *, 3);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values[0] = talloc_strdup(values, "hello2");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina values[1] = talloc_strdup(values, "world2");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values[0] != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(values[1] != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina key.type = HASH_KEY_STRING;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina key.str = talloc_strdup(table, "key2");
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(key.str != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina value.type = HASH_VALUE_PTR;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina value.ptr = values;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina hash_enter(table, &key, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(hret, HASH_SUCCESS);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina *_out = table;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina}
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstruct test_pilot pilot_iface = {
1203e462650f035b0df2304075d60b9a99e36715Stef Walter { &test_pilot_meta, 0 },
1203e462650f035b0df2304075d60b9a99e36715Stef Walter .Eject = eject_handler,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_FullName = pilot_get_full_name_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_byte = pilot_get_byte_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_boolean = pilot_get_boolean_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int16 = pilot_get_int16_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint16 = pilot_get_uint16_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int32 = pilot_get_int32_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint32 = pilot_get_uint32_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int64 = pilot_get_int64_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint64 = pilot_get_uint64_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_double = pilot_get_double_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_string = pilot_get_string_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_object_path = pilot_get_objpath_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_null_string = pilot_get_null_string_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_null_path = pilot_get_null_path_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_byte_array = pilot_get_byte_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int16_array = pilot_get_int16_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint16_array = pilot_get_uint16_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int32_array = pilot_get_int32_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint32_array = pilot_get_uint32_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_int64_array = pilot_get_int64_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_uint64_array = pilot_get_uint64_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_double_array = pilot_get_double_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_string_array = pilot_get_string_array_handler,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_object_path_array = pilot_get_path_array_handler,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter};
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
ac744223411099a862a747e7168a30255c003bf7Pavel Březinastruct test_special special_iface = {
ac744223411099a862a747e7168a30255c003bf7Pavel Březina { &test_special_meta, 0},
ac744223411099a862a747e7168a30255c003bf7Pavel Březina .get_array_dict_sas = special_get_array_dict_sas
ac744223411099a862a747e7168a30255c003bf7Pavel Březina};
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
1203e462650f035b0df2304075d60b9a99e36715Stef Walterstatic int pilot_test_server_init(struct sbus_connection *server, void *unused)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter{
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int ret;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_iface.vtable, "/test/leela",
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech discard_const("Crash into the billboard"));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(ret, EOK);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter return EOK;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter}
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
ac744223411099a862a747e7168a30255c003bf7Pavel Březinastatic int special_test_server_init(struct sbus_connection *server, void *unused)
ac744223411099a862a747e7168a30255c003bf7Pavel Březina{
ac744223411099a862a747e7168a30255c003bf7Pavel Březina int ret;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ret = sbus_conn_register_iface(server, &special_iface.vtable,
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech "/test/special",
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech discard_const("Crash into the billboard"));
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(ret, EOK);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina return EOK;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina}
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
1203e462650f035b0df2304075d60b9a99e36715Stef WalterSTART_TEST(test_marshal_basic_types)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter{
1203e462650f035b0df2304075d60b9a99e36715Stef Walter unsigned char arg_byte = 11;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_bool_t arg_boolean = TRUE;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int16_t arg_int16 = -2222;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint16_t arg_uint16 = 3333;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int32_t arg_int32 = -44444444;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint32_t arg_uint32 = 55555555;
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_int64_t arg_int64 = INT64_C(-6666666666666666);
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_uint64_t arg_uint64 = UINT64_C(7777777777777777);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter double arg_double = 1.1;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter const char *arg_string = "hello";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter const char *arg_object_path = "/original/object/path";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter unsigned char v_byte[] = { 11, 12 };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int16_t v_int16[] = { 1, -22, 333, -4444 };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint16_t v_uint16[] = { 1, 2, 3, 4, 5 };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int32_t v_int32[] = { -1, -23, 34, -56, -90000000, 78 };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint32_t v_uint32[] = { 11111111, 22222222, 33333333 };
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_int64_t v_int64[] = { INT64_C(-6666666666666666), INT64_C(7777777777777777) };
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_uint64_t v_uint64[] = { UINT64_C(7777777777777777), INT64_C(888888888888888888) };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter double v_double[] = { 1.1, 2.2, 3.3 };
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech const char *v_string[] = { "bears", "bears", "bears" };
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech const char *v_object_path[] = { "/original", "/original" };
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter unsigned char *arr_byte = v_byte;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int16_t *arr_int16 = v_int16;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint16_t *arr_uint16 = v_uint16;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int32_t *arr_int32 = v_int32;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint32_t *arr_uint32 = v_uint32;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int64_t *arr_int64 = v_int64;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_uint64_t *arr_uint64 = v_uint64;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter double *arr_double = v_double;
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech char **arr_string = discard_const(v_string);
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech char **arr_object_path = discard_const(v_object_path);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_byte = N_ELEMENTS(v_byte);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_int16 = N_ELEMENTS(v_int16);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_uint16 = N_ELEMENTS(v_uint16);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_int32 = N_ELEMENTS(v_int32);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_uint32 = N_ELEMENTS(v_uint32);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_int64 = N_ELEMENTS(v_int64);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_uint64 = N_ELEMENTS(v_uint64);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_double = N_ELEMENTS(v_double);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_string = N_ELEMENTS(v_string);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_object_path = N_ELEMENTS(v_object_path);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter TALLOC_CTX *ctx;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBusConnection *client;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBusError error = DBUS_ERROR_INIT;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBusMessage *reply;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ctx = talloc_new(NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek ck_assert(ctx != NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek
1203e462650f035b0df2304075d60b9a99e36715Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
d8c2d3c5e6d9fa36bd6a53a40549af016924dfc3Jakub Hrozek ck_assert(client != NULL);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter reply = test_dbus_call_sync(client,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter "/test/leela",
1203e462650f035b0df2304075d60b9a99e36715Stef Walter TEST_PILOT,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter TEST_PILOT_EJECT,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter &error,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_BYTE, &arg_byte,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_BOOLEAN, &arg_boolean,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT16, &arg_int16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT16, &arg_uint16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT32, &arg_int32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT32, &arg_uint32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT64, &arg_int64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT64, &arg_uint64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_DOUBLE, &arg_double,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_STRING, &arg_string,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_OBJECT_PATH, &arg_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &arr_byte, len_byte,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT16, &arr_int16, len_int16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT16, &arr_uint16, len_uint16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &arr_int32, len_int32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &arr_uint32, len_uint32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &arr_int64, len_int64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &arr_uint64, len_uint64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &arr_double, len_double,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &arr_string, len_string,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &arr_object_path, len_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INVALID);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(reply != NULL);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(!dbus_error_is_set(&error));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(dbus_message_get_args(reply, NULL,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_BYTE, &arg_byte,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_BOOLEAN, &arg_boolean,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT16, &arg_int16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT16, &arg_uint16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT32, &arg_int32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT32, &arg_uint32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INT64, &arg_int64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_UINT64, &arg_uint64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_DOUBLE, &arg_double,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_STRING, &arg_string,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_OBJECT_PATH, &arg_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &arr_byte, &len_byte,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT16, &arr_int16, &len_int16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT16, &arr_uint16, &len_uint16,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &arr_int32, &len_int32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &arr_uint32, &len_uint32,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &arr_int64, &len_int64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &arr_uint64, &len_uint64,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &arr_double, &len_double,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &arr_string, &len_string,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &arr_object_path, &len_object_path,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter DBUS_TYPE_INVALID));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_byte, 12);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arg_boolean == FALSE);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arg_int16, -2221);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_uint16, 3334);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arg_int32, -44444443);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arg_uint32, 55555556);
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_int64 == INT64_C(-6666666666666665));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_uint64 == UINT64_C(7777777777777778));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arg_double == 2.1);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_string, "bears, beets, battlestar galactica");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_object_path, "/another/object/path");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_byte, 2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_byte[0], 12);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_byte[1], 13);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_int16, 3);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int16[0], 2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int16[1], -21);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int16[2], 334);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_uint16, 5);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint16[0], 2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint16[1], 3);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint16[2], 4);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint16[3], 5);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint16[4], 6);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_int32, 5);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int32[0], 0);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int32[1], -22);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int32[2], 35);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int32[3], -55);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(arr_int32[4], -89999999);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_uint32, 3);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint32[0], 11111112);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint32[1], 22222223);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_uint_eq(arr_uint32[2], 33333334);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_int64, 2);
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_int64[0] == INT64_C(-6666666666666665));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_int64[1] == INT64_C(7777777777777778));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_uint64, 2);
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_uint64[0] == UINT64_C(7777777777777778));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_uint64[1] == UINT64_C(888888888888888889));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_double, 3);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arr_double[0] == 2.1);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arr_double[1] == 3.2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert(arr_double[2] == 4.3);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_string, 2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_string[0], "beets");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_string[1], "beets");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_free_string_array(arr_string);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_int_eq(len_object_path, 2);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_object_path[0], "/changed");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_object_path[1], "/changed");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_free_string_array(arr_object_path);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_message_unref (reply);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter talloc_free(ctx);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter}
1203e462650f035b0df2304075d60b9a99e36715Stef WalterEND_TEST
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void parse_get_reply(DBusMessage *reply, const int type, void *val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter iter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter variter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_bool_t dbret;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbret = dbus_message_iter_init(reply, &iter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(dbret == TRUE);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_VARIANT);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_recurse(&iter, &variter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&variter), type);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_basic(&variter, val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void call_get(DBusConnection *client,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *object_path,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *iface,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int type,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void *val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessage *reply;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusError error = DBUS_ERROR_INIT;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek reply = test_dbus_call_sync(client,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek object_path,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_PROPERTIES_INTERFACE,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "Get",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek &error,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &iface,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INVALID);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(reply != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek parse_get_reply(reply, type, val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub HrozekSTART_TEST(test_get_basic_types)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek TALLOC_CTX *ctx;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusConnection *client;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_bool_t bool_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *string_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *path_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint8_t byte_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int16_t int16_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint16_t uint16_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int32_t int32_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint32_t uint32_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int64_t int64_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint64_t uint64_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek double double_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ctx = talloc_new(NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek ck_assert(ctx != NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
d8c2d3c5e6d9fa36bd6a53a40549af016924dfc3Jakub Hrozek ck_assert(client != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "boolean",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_BOOLEAN, &bool_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(bool_val == pilot_bool);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "FullName",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &string_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_val, pilot_full_name);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "byte",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_BYTE, &byte_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(byte_val, pilot_byte);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int16",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT16, &int16_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(int16_val, pilot_int16);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint16",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT16, &uint16_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(uint16_val, pilot_uint16);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int32",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT32, &int32_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(int32_val, pilot_int32);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint32",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT32, &uint32_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(uint32_val, pilot_uint32);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int64",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT64, &int64_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(int64_val, pilot_int64);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint64",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT64, &uint64_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(uint64_val, pilot_uint64);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "double",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_DOUBLE, &double_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(double_val, pilot_double);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "string",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &string_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_val, pilot_string);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "object_path",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_OBJECT_PATH, &path_val);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(path_val, pilot_path);
58229439447d5617913a5a2e173b78105c694842Pavel Březina
58229439447d5617913a5a2e173b78105c694842Pavel Březina /* If a string getter returns NULL, the caller should receive "" */
58229439447d5617913a5a2e173b78105c694842Pavel Březina call_get(client, "/test/leela", test_pilot_meta.name, "null_string",
58229439447d5617913a5a2e173b78105c694842Pavel Březina DBUS_TYPE_STRING, &string_val);
58229439447d5617913a5a2e173b78105c694842Pavel Březina ck_assert_str_eq(string_val, "");
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek /* If a string getter returns NULL, the caller should receive "/" */
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "null_path",
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek DBUS_TYPE_OBJECT_PATH, &path_val);
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek ck_assert_str_eq(path_val, "/");
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek
ba99aa00a305d298f65379e3add7536553c82455Pavel Březina talloc_free(ctx);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub HrozekEND_TEST
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void parse_get_array_reply(DBusMessage *reply, const int type,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void **values, int *nels)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter iter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter variter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessageIter arriter;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_bool_t dbret;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbret = dbus_message_iter_init(reply, &iter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(dbret == TRUE);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_VARIANT);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_recurse(&iter, &variter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&variter), DBUS_TYPE_ARRAY);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_element_type(&variter), type);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_recurse(&variter, &arriter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
b9941359b3181c42f415530d5ccad0f4664d85faLukas Slebodnik int n = 0, i = 0;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **strings;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *s;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek do {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek n++;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek } while (dbus_message_iter_next(&arriter));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek /* Allocating on NULL is bad, but this is unit test */
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek strings = talloc_array(NULL, const char *, n);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(strings != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_recurse(&variter, &arriter);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek do {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_basic(&arriter, &s);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek strings[i] = talloc_strdup(strings, s);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(strings[i] != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek i++;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek } while (dbus_message_iter_next(&arriter));
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *nels = n;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek *values = strings;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek } else {
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek /* Fixed types are easy */
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_fixed_array(&arriter, values, nels);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek }
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void call_get_array(DBusConnection *client,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *object_path,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *iface,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int type,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek void **values,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int *nels)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusMessage *reply;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusError error = DBUS_ERROR_INIT;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek reply = test_dbus_call_sync(client,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek object_path,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_PROPERTIES_INTERFACE,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek "Get",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek &error,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &iface,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, &prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INVALID);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert(reply != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek parse_get_array_reply(reply, type, values, nels);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define _check_array(reply, len, known, fn) do { \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek fn(len, 2); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek fn(reply[0], known[0]); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek fn(reply[1], known[1]); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek} while(0); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define check_int_array(reply, len, known) \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek _check_array(reply, len, known, ck_assert_int_eq)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define check_uint_array(reply, len, known) \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek _check_array(reply, len, known, ck_assert_uint_eq)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub HrozekSTART_TEST(test_get_basic_array_types)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek{
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek TALLOC_CTX *ctx;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBusConnection *client;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **string_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int string_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **path_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int path_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint8_t *byte_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int byte_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int16_t *int16_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int int16_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint16_t *uint16_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int uint16_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int32_t *int32_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int int32_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint32_t *uint32_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int uint32_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int64_t *int64_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int int64_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek uint64_t *uint64_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int uint64_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek double *double_arr_val;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek int double_arr_len;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ctx = talloc_new(NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek ck_assert(ctx != NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
d8c2d3c5e6d9fa36bd6a53a40549af016924dfc3Jakub Hrozek ck_assert(client != NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "byte_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_BYTE, (void **) &byte_arr_val, &byte_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_uint_array(byte_arr_val, byte_arr_len, pilot_byte_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "int16_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT16, (void **) &int16_arr_val, &int16_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_int_array(int16_arr_val, int16_arr_len, pilot_int16_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "uint16_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT16, (void **) &uint16_arr_val, &uint16_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_uint_array(uint16_arr_val, uint16_arr_len, pilot_uint16_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "int32_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT32, (void **) &int32_arr_val, &int32_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_int_array(int32_arr_val, int32_arr_len, pilot_int32_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "uint32_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT32, (void **) &uint32_arr_val, &uint32_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_uint_array(uint32_arr_val, uint32_arr_len, pilot_uint32_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "int64_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_INT64, (void **) &int64_arr_val, &int64_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_int_array(int64_arr_val, int64_arr_len, pilot_int64_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "uint64_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_UINT64, (void **) &uint64_arr_val, &uint64_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_uint_array(uint64_arr_val, uint64_arr_len, pilot_uint64_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "double_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_DOUBLE, (void **) &double_arr_val, &double_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek check_int_array(double_arr_val, double_arr_len, pilot_double_array);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "string_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, (void **) &string_arr_val, &string_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(string_arr_len, 2);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_arr_val[0], pilot_string_array[0]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_arr_val[1], pilot_string_array[1]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "string_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_STRING, (void **) &string_arr_val, &string_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(string_arr_len, 2);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_arr_val[0], pilot_string_array[0]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(string_arr_val[1], pilot_string_array[1]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get_array(client, "/test/leela", test_pilot_meta.name, "object_path_array",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek DBUS_TYPE_OBJECT_PATH, (void **) &path_arr_val, &path_arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(path_arr_len, 2);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(path_arr_val[0], pilot_path_array[0]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(path_arr_val[1], pilot_path_array[1]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
ba99aa00a305d298f65379e3add7536553c82455Pavel Březina talloc_free(ctx);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek}
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub HrozekEND_TEST
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek
ac744223411099a862a747e7168a30255c003bf7Pavel BřezinaSTART_TEST(test_get_array_dict_sas)
ac744223411099a862a747e7168a30255c003bf7Pavel Březina{
ac744223411099a862a747e7168a30255c003bf7Pavel Březina TALLOC_CTX *ctx;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusConnection *client;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessage *reply;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessageIter it_variant;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessageIter it_array;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessageIter it_dict;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessageIter it_dict_entry;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusMessageIter it_values;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBusError error = DBUS_ERROR_INIT;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina const char *prop = "array_dict_sas";
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_bool_t dbret;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina const char *value;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina const char *hash_content[2][2] = {{"hello1", "world1"},
ac744223411099a862a747e7168a30255c003bf7Pavel Březina {"hello2", "world2"}};
617d5161d4ec454afc673ce1836b02f82435b347Lukas Slebodnik const char **exp_values = NULL;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina int i;
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ctx = talloc_new(NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(ctx != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina client = test_dbus_setup_mock(ctx, NULL, special_test_server_init, NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(client != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina reply = test_dbus_call_sync(client,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina "/test/special",
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBUS_PROPERTIES_INTERFACE,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina "Get",
ac744223411099a862a747e7168a30255c003bf7Pavel Březina &error,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBUS_TYPE_STRING, &test_special_meta.name,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBUS_TYPE_STRING, &prop,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina DBUS_TYPE_INVALID);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(reply != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbret = dbus_message_iter_init(reply, &it_variant);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(dbret == TRUE);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_arg_type(&it_variant), DBUS_TYPE_VARIANT);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_recurse(&it_variant, &it_array);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina /* array */
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_arg_type(&it_array), DBUS_TYPE_ARRAY);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_element_type(&it_array), DBUS_TYPE_DICT_ENTRY);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina /* dict entry */
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina /* first item */
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_recurse(&it_array, &it_dict);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina for (i = 0; i < 2; i++) {
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_recurse(&it_dict, &it_dict_entry);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_arg_type(&it_dict_entry), DBUS_TYPE_STRING);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_get_basic(&it_dict_entry, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(value != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina if (strcmp(value, "key1") == 0) {
ac744223411099a862a747e7168a30255c003bf7Pavel Březina exp_values = hash_content[0];
ac744223411099a862a747e7168a30255c003bf7Pavel Březina } else if (strcmp(value, "key2") == 0) {
ac744223411099a862a747e7168a30255c003bf7Pavel Březina exp_values = hash_content[1];
ac744223411099a862a747e7168a30255c003bf7Pavel Březina } else {
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_abort_msg("Invalid key! %s", value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina }
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbret = dbus_message_iter_next(&it_dict_entry);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(dbret == TRUE);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_arg_type(&it_dict_entry), DBUS_TYPE_ARRAY);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_int_eq(dbus_message_iter_get_element_type(&it_dict_entry), DBUS_TYPE_STRING);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_recurse(&it_dict_entry, &it_values);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_get_basic(&it_values, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(value != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_str_eq(value, exp_values[0]);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbret = dbus_message_iter_next(&it_values);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_get_basic(&it_values, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert(value != NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ck_assert_str_eq(value, exp_values[1]);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_next(&it_dict);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina }
e51143e3e67c70b86dd9a67cb7e802dd96f989e1Pavel Březina
e51143e3e67c70b86dd9a67cb7e802dd96f989e1Pavel Březina talloc_free(ctx);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina}
ac744223411099a862a747e7168a30255c003bf7Pavel BřezinaEND_TEST
ac744223411099a862a747e7168a30255c003bf7Pavel Březina
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozekstruct prop_test {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *name;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek bool handled;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int length;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int type;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek union prop_value {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek bool bool_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *string_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *path_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint8_t byte_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int16_t int16_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint16_t uint16_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int32_t int32_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint32_t uint32_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int64_t int64_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint64_t uint64_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek double double_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char **string_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char **path_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint8_t *byte_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int16_t *int16_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint16_t *uint16_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int32_t *int32_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint32_t *uint32_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int64_t *int64_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint64_t *uint64_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek double *double_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek } value;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek};
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozekvoid check_prop(DBusMessageIter *variter, struct prop_test *p)
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek{
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_bool_t bool_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *string_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *path_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint8_t byte_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int16_t int16_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint16_t uint16_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int32_t int32_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint32_t uint32_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int64_t int64_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint64_t uint64_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek double double_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int type;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek type = dbus_message_iter_get_arg_type(variter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* No property should be returned twice */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(p->handled == false);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(p->type == type);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek switch (p->type) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_BOOLEAN:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &bool_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(bool_val == p->value.bool_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_STRING:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &string_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(string_val, p->value.string_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_BYTE:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &byte_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(byte_val, p->value.byte_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT16:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int16_val, p->value.int16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT16:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint16_val, p->value.uint16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT32:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int32_val, p->value.int32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT32:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint32_val, p->value.uint32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT64:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int64_val, p->value.int64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT64:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint64_val, p->value.uint64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_DOUBLE:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &double_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(double_val, p->value.double_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_OBJECT_PATH:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &path_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(path_val, p->value.path_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek default:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Not handled */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek return;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* This attribute was handled, get the next one */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek p->handled = true;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek}
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozekvoid check_arr_prop(DBusMessageIter *variter, struct prop_test *p)
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek{
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessageIter arriter;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char **strings = NULL;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint8_t *byte_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int16_t *int16_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint16_t *uint16_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int32_t *int32_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint32_t *uint32_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int64_t *int64_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek uint64_t *uint64_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek double *double_arr_val;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int len;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int type;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(variter), DBUS_TYPE_ARRAY);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek type = dbus_message_iter_get_element_type(variter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(type, p->type);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_recurse(variter, &arriter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
b9941359b3181c42f415530d5ccad0f4664d85faLukas Slebodnik int n = 0, i = 0;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *s;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek do {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek n++;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek } while (dbus_message_iter_next(&arriter));
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Allocating on NULL is bad, but this is unit test */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek strings = talloc_array(NULL, const char *, n);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(strings != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_recurse(variter, &arriter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek do {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(&arriter, &s);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek strings[i] = talloc_strdup(strings, s);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(strings[i] != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek i++;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek } while (dbus_message_iter_next(&arriter));
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek len = n;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek switch (p->type) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_STRING:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(len, 2);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(strings != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(strings[0], pilot_string_array[0]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(strings[1], pilot_string_array[1]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_BYTE:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &byte_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_uint_array(byte_arr_val, len, p->value.byte_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT16:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &int16_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_int_array(int16_arr_val, len, p->value.int16_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT16:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &uint16_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_uint_array(uint16_arr_val, len, p->value.uint16_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT32:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &int32_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_int_array(int32_arr_val, len, p->value.int32_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT32:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &uint32_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_uint_array(uint32_arr_val, len, p->value.uint32_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_INT64:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &int64_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_int_array(int64_arr_val, len, p->value.int64_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_UINT64:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &uint64_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_uint_array(uint64_arr_val, len, p->value.uint64_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_DOUBLE:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_fixed_array(&arriter, &double_arr_val, &len);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_int_array(double_arr_val, len, p->value.double_arr_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek case DBUS_TYPE_OBJECT_PATH:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(len, 2);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(strings != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(strings[0], pilot_path_array[0]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(strings[1], pilot_path_array[1]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek default:
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Not handled */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek return;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek p->handled = true;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek}
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub HrozekSTART_TEST(test_getall_basic_types)
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek{
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessage *reply;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessageIter iter;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessageIter arriter;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessageIter dictiter;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusMessageIter variter;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_bool_t dbret;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusError error = DBUS_ERROR_INIT;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek TALLOC_CTX *ctx;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBusConnection *client;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek char *attr_name;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int i;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek int num_prop;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek struct prop_test pilot_properties[] = {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "boolean", false, 0, DBUS_TYPE_BOOLEAN, { .bool_val = pilot_bool } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "FullName", false, 0, DBUS_TYPE_STRING, { .string_val = pilot_full_name } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "byte", false, 0, DBUS_TYPE_BYTE, { .byte_val = pilot_byte } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int16", false, 0, DBUS_TYPE_INT16, { .int16_val = pilot_int16 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint16", false, 0, DBUS_TYPE_UINT16, { .uint16_val = pilot_uint16 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int32", false, 0, DBUS_TYPE_INT32, { .int32_val = pilot_int32 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint32", false, 0, DBUS_TYPE_UINT32, { .uint32_val = pilot_uint32 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int64", false, 0, DBUS_TYPE_INT64, { .int64_val = pilot_int64 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint64", false, 0, DBUS_TYPE_UINT64, { .uint64_val = pilot_uint64 } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "double", false, 0, DBUS_TYPE_DOUBLE, { .double_val = pilot_double } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "string", false, 0, DBUS_TYPE_STRING, { .string_val = pilot_string } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "object_path", false, 0, DBUS_TYPE_OBJECT_PATH, { .path_val = pilot_path } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "null_string", false, 0, DBUS_TYPE_STRING, { .string_val = "" } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "null_path", false, 0, DBUS_TYPE_OBJECT_PATH, { .path_val = "/" } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "byte_array", false, N_ELEMENTS(pilot_byte_array), DBUS_TYPE_BYTE, { .byte_arr_val = pilot_byte_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int16_array", false, N_ELEMENTS(pilot_int16_array), DBUS_TYPE_INT16, { .int16_arr_val = pilot_int16_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint16_array", false, N_ELEMENTS(pilot_uint16_array), DBUS_TYPE_UINT16, { .uint16_arr_val = pilot_uint16_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int32_array", false, N_ELEMENTS(pilot_int32_array), DBUS_TYPE_INT32, { .int32_arr_val = pilot_int32_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint32_array", false, N_ELEMENTS(pilot_uint32_array), DBUS_TYPE_UINT32, { .uint32_arr_val = pilot_uint32_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "int64_array", false, N_ELEMENTS(pilot_int64_array), DBUS_TYPE_INT64, { .int64_arr_val = pilot_int64_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "uint64_array", false, N_ELEMENTS(pilot_uint64_array), DBUS_TYPE_UINT64, { .uint64_arr_val = pilot_uint64_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "double_array", false, N_ELEMENTS(pilot_double_array), DBUS_TYPE_DOUBLE, { .double_arr_val = pilot_double_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "string_array", false, N_ELEMENTS(pilot_string_array), DBUS_TYPE_STRING, { .string_arr_val = pilot_string_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { "object_path_array", false, N_ELEMENTS(pilot_path_array), DBUS_TYPE_OBJECT_PATH, { .path_arr_val = pilot_path_array } },
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek { NULL, false, 0, 0, { .bool_val = false } }};
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ctx = talloc_new(NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek ck_assert(ctx != NULL);
9b0e541f37f780c31c69c22c663589b87e4e788bJakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
d8c2d3c5e6d9fa36bd6a53a40549af016924dfc3Jakub Hrozek ck_assert(client != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek reply = test_dbus_call_sync(client,
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek "/test/leela",
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBUS_PROPERTIES_INTERFACE,
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek "GetAll",
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek &error,
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBUS_TYPE_STRING,
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek &test_pilot_meta.name,
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBUS_TYPE_INVALID);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(reply != NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* GetAll reply is an array of dictionaries */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbret = dbus_message_iter_init(reply, &iter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(dbret == TRUE);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_ARRAY);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_recurse(&iter, &arriter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek num_prop = 0;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek do {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&arriter),
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBUS_TYPE_DICT_ENTRY);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_recurse(&arriter, &dictiter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(&dictiter, &attr_name);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(dbus_message_iter_next(&dictiter) == TRUE);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&dictiter),
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek DBUS_TYPE_VARIANT);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_recurse(&dictiter, &variter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek for (i=0; pilot_properties[i].name; i++) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek if (strcmp(attr_name, pilot_properties[i].name) == 0) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek if (dbus_message_iter_get_arg_type(&variter) == DBUS_TYPE_ARRAY) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_arr_prop(&variter, &pilot_properties[i]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek } else {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek check_prop(&variter, &pilot_properties[i]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek break;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek num_prop++;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek } while(dbus_message_iter_next(&arriter));
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* All known properties must be handled now */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek for (i=0; pilot_properties[i].name; i++) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(pilot_properties[i].handled == true);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek }
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Also all properties returned from the bus must be accounted for */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_uint_eq(num_prop, N_ELEMENTS(pilot_properties)-1);
ba99aa00a305d298f65379e3add7536553c82455Pavel Březina
ba99aa00a305d298f65379e3add7536553c82455Pavel Březina talloc_free(ctx);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek}
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub HrozekEND_TEST
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek
1203e462650f035b0df2304075d60b9a99e36715Stef WalterTCase *create_handler_tests(void)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter{
1203e462650f035b0df2304075d60b9a99e36715Stef Walter TCase *tc = tcase_create("handler");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter tcase_add_test(tc, test_marshal_basic_types);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek tcase_add_test(tc, test_get_basic_types);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek tcase_add_test(tc, test_getall_basic_types);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek tcase_add_test(tc, test_get_basic_array_types);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina tcase_add_test(tc, test_get_array_dict_sas);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter return tc;
1203e462650f035b0df2304075d60b9a99e36715Stef Walter}
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef WalterSuite *create_suite(void)
1203e462650f035b0df2304075d60b9a99e36715Stef Walter{
1203e462650f035b0df2304075d60b9a99e36715Stef Walter Suite *s = suite_create("sbus_codegen");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter
1203e462650f035b0df2304075d60b9a99e36715Stef Walter suite_add_tcase(s, create_defs_tests ());
1203e462650f035b0df2304075d60b9a99e36715Stef Walter suite_add_tcase(s, create_handler_tests ());
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return s;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterint main(int argc, const char *argv[])
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter{
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter int opt;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter poptContext pc;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter int failure_count;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Suite *suite;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter SRunner *sr;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter struct poptOption long_options[] = {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter POPT_AUTOHELP
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter POPT_TABLEEND
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter };
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter while ((opt = poptGetNextOpt(pc)) != -1) {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter switch (opt) {
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter default:
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter fprintf(stderr, "\nInvalid option %s: %s\n\n",
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter poptBadOption(pc, 0), poptStrerror(opt));
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter poptPrintUsage(pc, stderr, 0);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return 1;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter }
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter }
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter poptFreeContext(pc);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter suite = create_suite();
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter sr = srunner_create(suite);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter srunner_run_all(sr, CK_ENV);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter failure_count = srunner_ntests_failed(sr);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter srunner_free(sr);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter}