b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter sbus_codegen tests.
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Stef Walter <stefw@redhat.com>
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter Copyright (C) Red Hat, Inc 2014
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 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 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/>.
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik/* The following 2 macros were taken from check's project source files (0.9.10)
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#endif /* _ck_assert_uint */
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
1a94716209e40a9ccaedc7e70f9de961d1cced48Lukas Slebodnik#endif /* ck_assert_uint_eq */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walterstatic const struct sbus_arg_meta *
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char *name)
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 /* Explicit C Symbol */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert(test_pilot_meta.signals == NULL); /* no signals */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter arg = find_arg(method->out_args, "where_we_crashed");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_str_eq(arg->name, "where_we_crashed");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter prop = sbus_meta_find_property(&com_planetexpress_Ship_meta, "Color");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter ck_assert_int_eq(prop->flags, SBUS_PROPERTY_READABLE);
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio sig = sbus_meta_find_signal(&com_planetexpress_Ship_meta, "BecameSentient");
01f852fcb27e0a0a07e2b8b51e7e838a256b485fFabiano Fidêncio ck_assert_str_eq(sig->name, "BecameSentient");
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltermock_move_universe(struct sbus_request *dbus_req, void *data,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * The above arguments should match the handler signature,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * and the below finish function should have the right signature.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter return com_planetexpress_Ship_MoveUniverse_finish(dbus_req, "here");
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltermock_crash_now(struct sbus_request *dbus_req, void *data,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter const char *where)
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * One argument, no return value, yet a finish function should
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * have been generated.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter return com_planetexpress_Ship_crash_now_finish(dbus_req);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Raw handler, no finish function, no special arguments.
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter * Not called, just testing compilation
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 ck_assert(vtable.MoveUniverse == mock_move_universe);
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 /* 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");
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter /* Do some testing */
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 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 uint16_t arg_uint16_array[], int len_uint16_array,
1203e462650f035b0df2304075d60b9a99e36715Stef Walter uint32_t arg_uint32_array[], int len_uint32_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 /* Only called for leela, so double check here */
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(instance_data, "Crash into the billboard");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter /* Murge the various values for test case */
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_int64 == INT64_C(-6666666666666666));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_uint64 == UINT64_C(7777777777777777));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter arg_string = "bears, beets, battlestar galactica";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_object_path, "/original/object/path");
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_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_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_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_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_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_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_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_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 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 /* And reply with those values */
1203e462650f035b0df2304075d60b9a99e36715Stef Walter return test_pilot_Eject_finish(req, arg_byte, arg_boolean, arg_int16,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_boolean_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_full_name = "Turanga Leela";
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_full_name_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **name)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_byte_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int16_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint16_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int32_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint32_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int64_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint64_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_double_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_string_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_objpath_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char **path_val)
58229439447d5617913a5a2e173b78105c694842Pavel Březinavoid pilot_get_null_string_handler(struct sbus_request *dbus_req,
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozekvoid pilot_get_null_path_handler(struct sbus_request *dbus_req,
5de968e80ade1c02d1907834dcff95e9fc9ad10aJakub Hrozek const char **path_val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define array_getter_body(in, out, outlen) do { \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_byte_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_byte_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int16_t pilot_int16_array[] = { -123, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int16_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int16_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint16_t pilot_uint16_array[] = { 123, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint16_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint16_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int32_t pilot_int32_array[] = { -456, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int32_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int32_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint32_t pilot_uint32_array[] = { 456, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint32_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint32_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic int64_t pilot_int64_array[] = { -789, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_int64_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_int64_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic uint64_t pilot_uint64_array[] = { 789, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_uint64_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_uint64_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic double pilot_double_array[] = { 3.14, 0 };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_double_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_double_array, arr_out, arr_len);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic const char *pilot_string_array[] = { "Turanga", "Leela" };
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekvoid pilot_get_string_array_handler(struct sbus_request *dbus_req,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char ***arr_out,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_string_array, arr_out, arr_len);
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 const char ***arr_out,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek array_getter_body(pilot_path_array, arr_out, arr_len);
ac744223411099a862a747e7168a30255c003bf7Pavel Březinavoid special_get_array_dict_sas(struct sbus_request *sbus_req,
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina .get_null_string = pilot_get_null_string_handler,
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,
ac744223411099a862a747e7168a30255c003bf7Pavel Březina .get_array_dict_sas = special_get_array_dict_sas
1203e462650f035b0df2304075d60b9a99e36715Stef Walterstatic int pilot_test_server_init(struct sbus_connection *server, void *unused)
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_iface.vtable, "/test/leela",
ac744223411099a862a747e7168a30255c003bf7Pavel Březinastatic int special_test_server_init(struct sbus_connection *server, void *unused)
ac744223411099a862a747e7168a30255c003bf7Pavel Březina ret = sbus_conn_register_iface(server, &special_iface.vtable,
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_int64_t arg_int64 = INT64_C(-6666666666666666);
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik dbus_uint64_t arg_uint64 = UINT64_C(7777777777777777);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter const char *arg_object_path = "/original/object/path";
1203e462650f035b0df2304075d60b9a99e36715Stef Walter dbus_int16_t v_int16[] = { 1, -22, 333, -4444 };
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) };
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech const char *v_string[] = { "bears", "bears", "bears" };
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech const char *v_object_path[] = { "/original", "/original" };
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech char **arr_object_path = discard_const(v_object_path);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter int len_object_path = N_ELEMENTS(v_object_path);
1203e462650f035b0df2304075d60b9a99e36715Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
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_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,
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_int64 == INT64_C(-6666666666666665));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arg_uint64 == UINT64_C(7777777777777778));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_string, "bears, beets, battlestar galactica");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arg_object_path, "/another/object/path");
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_int64[0] == INT64_C(-6666666666666665));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_int64[1] == INT64_C(7777777777777778));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_uint64[0] == UINT64_C(7777777777777778));
8dc21698c4ed699801d2b6f9135b3d6cb8512917Lukas Slebodnik ck_assert(arr_uint64[1] == UINT64_C(888888888888888889));
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_object_path[0], "/changed");
1203e462650f035b0df2304075d60b9a99e36715Stef Walter ck_assert_str_eq(arr_object_path[1], "/changed");
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void parse_get_reply(DBusMessage *reply, const int type, void *val)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_VARIANT);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&variter), type);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "boolean",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "FullName",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "byte",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int16",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint16",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int32",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint32",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "int64",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "uint64",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "double",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "string",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek call_get(client, "/test/leela", test_pilot_meta.name, "object_path",
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",
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",
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void parse_get_array_reply(DBusMessage *reply, const int type,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_VARIANT);
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 if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
b9941359b3181c42f415530d5ccad0f4664d85faLukas Slebodnik int n = 0, i = 0;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *s;
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek /* Allocating on NULL is bad, but this is unit test */
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek /* Fixed types are easy */
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek dbus_message_iter_get_fixed_array(&arriter, values, nels);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozekstatic void call_get_array(DBusConnection *client,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek const char *prop,
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek parse_get_array_reply(reply, type, values, nels);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek#define _check_array(reply, len, known, fn) do { \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek} while(0); \
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek _check_array(reply, len, known, ck_assert_int_eq)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek _check_array(reply, len, known, ck_assert_uint_eq)
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
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 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 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 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 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 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 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 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 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_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 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_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 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_str_eq(path_arr_val[0], pilot_path_array[0]);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek ck_assert_str_eq(path_arr_val[1], pilot_path_array[1]);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina const char *hash_content[2][2] = {{"hello1", "world1"},
ac744223411099a862a747e7168a30255c003bf7Pavel Březina client = test_dbus_setup_mock(ctx, NULL, special_test_server_init, NULL);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbret = dbus_message_iter_init(reply, &it_variant);
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 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 /* dict entry */
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 dbus_message_iter_get_basic(&it_dict_entry, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbret = dbus_message_iter_next(&it_dict_entry);
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 dbus_message_iter_recurse(&it_dict_entry, &it_values);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_get_basic(&it_values, &value);
ac744223411099a862a747e7168a30255c003bf7Pavel Březina dbus_message_iter_get_basic(&it_values, &value);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozekvoid check_prop(DBusMessageIter *variter, struct prop_test *p)
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek type = dbus_message_iter_get_arg_type(variter);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* No property should be returned twice */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek switch (p->type) {
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &bool_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &string_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(string_val, p->value.string_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &byte_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int16_val, p->value.int16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint16_val, p->value.uint16_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int32_val, p->value.int32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint32_val, p->value.uint32_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &int64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(int64_val, p->value.int64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &uint64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(uint64_val, p->value.uint64_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &double_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(double_val, p->value.double_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek dbus_message_iter_get_basic(variter, &path_val);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Not handled */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* This attribute was handled, get the next one */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozekvoid check_arr_prop(DBusMessageIter *variter, struct prop_test *p)
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 if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
b9941359b3181c42f415530d5ccad0f4664d85faLukas Slebodnik int n = 0, i = 0;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek const char *s;
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Allocating on NULL is bad, but this is unit test */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek switch (p->type) {
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 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 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 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 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 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 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 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 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 ck_assert_str_eq(strings[0], pilot_path_array[0]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_str_eq(strings[1], pilot_path_array[1]);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* Not handled */
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 { "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 client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek /* GetAll reply is an array of dictionaries */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_ARRAY);
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert_int_eq(dbus_message_iter_get_arg_type(&arriter),
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_message_iter_recurse(&dictiter, &variter);
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 /* All known properties must be handled now */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek ck_assert(pilot_properties[i].handled == true);
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);
90e04eae7e54ec892a6f239783df94dab5d1ed9aJakub Hrozek tcase_add_test(tc, test_get_basic_array_types);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);