sbus_codegen_tests.c revision 9b0e541f37f780c31c69c22c663589b87e4e788b
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu sbus_codegen tests.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Stef Walter <stefw@redhat.com>
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Copyright (C) Red Hat, Inc 2014
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu This program is free software; you can redistribute it and/or modify
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu it under the terms of the GNU General Public License as published by
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu the Free Software Foundation; either version 3 of the License, or
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (at your option) any later version.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu This program is distributed in the hope that it will be useful,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu but WITHOUT ANY WARRANTY; without even the implied warranty of
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu GNU General Public License for more details.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu You should have received a copy of the GNU General Public License
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu along with this program. If not, see <http://www.gnu.org/licenses/>.
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance#include "tests/sbus_codegen_tests_generated.h"
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu/* The following 2 macros were taken from check's project source files (0.9.10)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu#endif /* _ck_assert_uint */
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu#endif /* ck_assert_uint_eq */
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maederstatic const struct sbus_arg_meta *
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiufind_arg(const struct sbus_arg_meta *args,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu for (arg = args; arg->name != NULL; arg++) {
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(com_planetexpress_Ship_meta.name, "com.planetexpress.Ship");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(com_planetexpress_Ship_meta.methods != NULL);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(com_planetexpress_Ship_meta.signals != NULL);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(com_planetexpress_Ship_meta.properties != NULL);
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance /* Explicit C Symbol */
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot");
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance ck_assert(test_pilot_meta.methods != NULL);
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance ck_assert(test_pilot_meta.signals == NULL); /* no signals */
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance ck_assert(test_pilot_meta.properties != NULL);
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(method->name, "MoveUniverse");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu arg = find_arg(method->in_args, "smoothly");
9475501a6acf48434052d9e6f4a05ed6681eaaabFrancisc Nicolae Bungiu ck_assert_str_eq(arg->name, "smoothly");
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance arg = find_arg(method->out_args, "where_we_crashed");
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance ck_assert_str_eq(arg->name, "where_we_crashed");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu const struct sbus_property_meta *prop;
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance prop = sbus_meta_find_property(&com_planetexpress_Ship_meta, "Color");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(prop->name, "Color");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_int_eq(prop->flags, SBUS_PROPERTY_READABLE);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu const struct sbus_signal_meta *signal;
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu signal = sbus_meta_find_signal(&com_planetexpress_Ship_meta, "BecameSentient");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(signal->name, "BecameSentient");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu arg = find_arg(signal->args, "gender");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(arg->name, "gender");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiumock_move_universe(struct sbus_request *dbus_req, void *data,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu bool arg_smoothly, uint32_t arg_speed_factor)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * The above arguments should match the handler signature,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * and the below finish function should have the right signature.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * Not called, just testing compilation
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return com_planetexpress_Ship_MoveUniverse_finish(dbus_req, "here");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiumock_crash_now(struct sbus_request *dbus_req, void *data,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * One argument, no return value, yet a finish function should
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * have been generated.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * Not called, just testing compilation
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return com_planetexpress_Ship_crash_now_finish(dbus_req);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiumock_land(struct sbus_request *req, void *data)
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder * Raw handler, no finish function, no special arguments.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * Not called, just testing compilation
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu struct com_planetexpress_Ship vtable = {
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu { &com_planetexpress_Ship_meta, 0 },
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance * These are not silly tests:
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * - Will fail compilation if c-symbol name was not respected
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu * - Will fail if method order was not respected
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(vtable.crash_now == mock_crash_now);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(vtable.MoveUniverse == mock_move_universe);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert(vtable.Land == mock_land);
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance ck_assert_str_eq(COM_PLANETEXPRESS_SHIP, "com.planetexpress.Ship");
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE, "MoveUniverse");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_CRASH_NOW, "Crash");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_BECAMESENTIENT, "BecameSentient");
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_COLOR, "Color");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu /* constants for com.planetexpress.Pilot */
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance ck_assert_str_eq(TEST_PILOT, "com.planetexpress.Pilot");
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance ck_assert_str_eq(TEST_PILOT_FULLNAME, "FullName");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu /* Do some testing */
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu tcase_add_test(tc, test_interfaces);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu tcase_add_test(tc, test_properties);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu/* This is a handler which has all the basic arguments types */
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiustatic int eject_handler(struct sbus_request *req, void *instance_data,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu int16_t arg_int16, uint16_t arg_uint16, int32_t arg_int32,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu uint32_t arg_uint32, int64_t arg_int64, uint64_t arg_uint64,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu double arg_double, const char *arg_string, const char *arg_object_path,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu uint8_t arg_byte_array[], int len_byte_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu int16_t arg_int16_array[], int len_int16_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu uint16_t arg_uint16_array[], int len_uint16_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu int32_t arg_int32_array[], int len_int32_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu uint32_t arg_uint32_array[], int len_uint32_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu int64_t arg_int64_array[], int len_int64_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu uint64_t arg_uint64_array[], int len_uint64_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu double arg_double_array[], int len_double_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu const char *arg_string_array[], int len_string_array,
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu const char *arg_object_path_array[], int len_object_path_array)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu /* Only called for leela, so double check here */
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_str_eq(instance_data, "Crash into the billboard");
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu /* Murge the various values for test case */
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_uint_eq(arg_uint16, 3333);
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ck_assert_int_eq(arg_int32, -44444444);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance ck_assert_uint_eq(arg_uint32, 55555555);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_string = "bears, beets, battlestar galactica";
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance ck_assert_str_eq(arg_object_path, "/original/object/path");
f20c085644aa49702488405bc2d4245cf0e5a713Felix Gabriel Mance arg_object_path = "/another/object/path";
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_byte_array = talloc_memdup(req, arg_byte_array, sizeof(uint8_t) * len_byte_array);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance for (i = 0; i < len_byte_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_int16_array = talloc_memdup(req, arg_int16_array, sizeof(int16_t) * len_int16_array);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance for (i = 0; i < len_int16_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_uint16_array = talloc_memdup(req, arg_uint16_array, sizeof(uint16_t) * len_uint16_array);
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance for (i = 0; i < len_uint16_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_int32_array = talloc_memdup(req, arg_int32_array, sizeof(int32_t) * len_int32_array);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance for (i = 0; i < len_int32_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_uint32_array = talloc_memdup(req, arg_uint32_array, sizeof(uint32_t) * len_uint32_array);
2713ec15465bd1e643f6310d7048b5a30ad55c83Christian Maeder for (i = 0; i < len_uint32_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_int64_array = talloc_memdup(req, arg_int64_array, sizeof(int64_t) * len_int64_array);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance for (i = 0; i < len_int64_array; i++)
2713ec15465bd1e643f6310d7048b5a30ad55c83Christian Maeder arg_uint64_array = talloc_memdup(req, arg_uint64_array, sizeof(uint64_t) * len_uint64_array);
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance for (i = 0; i < len_uint64_array; i++)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance arg_double_array = talloc_memdup(req, arg_double_array, sizeof(double) * len_double_array);
f20c085644aa49702488405bc2d4245cf0e5a713Felix Gabriel Mance for (i = 0; i < len_double_array; i++)
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance arg_string_array = talloc_memdup(req, arg_string_array, sizeof(char *) * len_string_array);
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance for (i = 0; i < len_double_array; i++) {
9a160cb31a4d2b1a193f3229c79b38efc517152cFrancisc Nicolae Bungiu ck_assert_str_eq(arg_string_array[i], "bears");
arg_object_path_array = talloc_memdup(req, arg_object_path_array, sizeof(char *) * len_object_path_array);
for (i = 0; i < len_object_path_array; i++) {
static const bool pilot_bool = true;
void *instance_data,
bool *val)
void *instance_data,
const char **name)
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
double *double_val)
void *instance_data,
const char **string_val)
void *instance_data,
const char **path_val)
void *instance_data,
const char **string_val)
void *instance_data,
const char **path_val)
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *instance_data,
void *data,
const char ***arr_out,
int *arr_len)
void *data,
const char ***arr_out,
int *arr_len)
{ &test_pilot_meta, 0 },
int ret;
return EOK;
&error,
const char *object_path,
const char *iface,
const char *prop,
int type,
void *val)
&error,
const char *string_val;
const char *path_val;
double double_val;
const char **strings;
*nels = n;
const char *object_path,
const char *iface,
const char *prop,
int type,
void **values,
int *nels)
&error,
const char **string_arr_val;
int string_arr_len;
const char **path_arr_val;
int path_arr_len;
int byte_arr_len;
int int16_arr_len;
int uint16_arr_len;
int int32_arr_len;
int uint32_arr_len;
int int64_arr_len;
int uint64_arr_len;
double *double_arr_val;
int double_arr_len;
struct prop_test {
const char *name;
bool handled;
int length;
int type;
union prop_value {
bool bool_val;
const char *string_val;
const char *path_val;
double double_val;
const char **string_arr_val;
const char **path_arr_val;
double *double_arr_val;
} value;
const char *string_val;
const char *path_val;
double double_val;
int type;
switch (p->type) {
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_STRING:
case DBUS_TYPE_BYTE:
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_OBJECT_PATH:
p->handled = true;
double *double_arr_val;
int len;
int type;
len = n;
switch (p->type) {
case DBUS_TYPE_STRING:
case DBUS_TYPE_BYTE:
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_OBJECT_PATH:
p->handled = true;
char *attr_name;
int num_prop;
{ "byte_array", false, N_ELEMENTS(pilot_byte_array), DBUS_TYPE_BYTE, { .byte_arr_val = pilot_byte_array } },
{ "int16_array", false, N_ELEMENTS(pilot_int16_array), DBUS_TYPE_INT16, { .int16_arr_val = pilot_int16_array } },
{ "uint16_array", false, N_ELEMENTS(pilot_uint16_array), DBUS_TYPE_UINT16, { .uint16_arr_val = pilot_uint16_array } },
{ "int32_array", false, N_ELEMENTS(pilot_int32_array), DBUS_TYPE_INT32, { .int32_arr_val = pilot_int32_array } },
{ "uint32_array", false, N_ELEMENTS(pilot_uint32_array), DBUS_TYPE_UINT32, { .uint32_arr_val = pilot_uint32_array } },
{ "int64_array", false, N_ELEMENTS(pilot_int64_array), DBUS_TYPE_INT64, { .int64_arr_val = pilot_int64_array } },
{ "uint64_array", false, N_ELEMENTS(pilot_uint64_array), DBUS_TYPE_UINT64, { .uint64_arr_val = pilot_uint64_array } },
{ "double_array", false, N_ELEMENTS(pilot_double_array), DBUS_TYPE_DOUBLE, { .double_arr_val = pilot_double_array } },
{ "string_array", false, N_ELEMENTS(pilot_string_array), DBUS_TYPE_STRING, { .string_arr_val = pilot_string_array } },
{ "object_path_array", false, N_ELEMENTS(pilot_path_array), DBUS_TYPE_OBJECT_PATH, { .path_arr_val = pilot_path_array } },
&error,
num_prop = 0;
num_prop++;
return tc;
int opt;
int failure_count;
switch (opt) {