sbus_codegen_tests.c revision 8dc21698c4ed699801d2b6f9135b3d6cb8512917
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen sbus_codegen tests.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen Stef Walter <stefw@redhat.com>
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen Copyright (C) Red Hat, Inc 2014
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen This program is free software; you can redistribute it and/or modify
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen it under the terms of the GNU General Public License as published by
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen the Free Software Foundation; either version 3 of the License, or
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (at your option) any later version.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen This program is distributed in the hope that it will be useful,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen GNU General Public License for more details.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen You should have received a copy of the GNU General Public License
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "tests/sbus_codegen_tests_generated.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* The following 2 macros were taken from check's project source files (0.9.10)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#endif /* _ck_assert_uint */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#endif /* ck_assert_uint_eq */
d22301419109ed4a38351715e6760011421dadecTimo Sirainenstatic const struct sbus_arg_meta *
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ck_assert_str_eq(com_planetexpress_Ship_meta.name, "com.planetexpress.Ship");
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ck_assert(com_planetexpress_Ship_meta.methods != NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(com_planetexpress_Ship_meta.signals != NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(com_planetexpress_Ship_meta.properties != NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Explicit C Symbol */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(test_pilot_meta.signals == NULL); /* no signals */
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ck_assert(test_pilot_meta.properties != NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(method->name, "MoveUniverse");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg = find_arg(method->out_args, "where_we_crashed");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(arg->name, "where_we_crashed");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen prop = sbus_meta_find_property(&com_planetexpress_Ship_meta, "Color");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_int_eq(prop->flags, SBUS_PROPERTY_READABLE);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen signal = sbus_meta_find_signal(&com_planetexpress_Ship_meta, "BecameSentient");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(signal->name, "BecameSentient");
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainenmock_move_universe(struct sbus_request *dbus_req, void *data,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * The above arguments should match the handler signature,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * and the below finish function should have the right signature.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * Not called, just testing compilation
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return com_planetexpress_Ship_MoveUniverse_finish(dbus_req, "here");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenmock_crash_now(struct sbus_request *dbus_req, void *data,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * One argument, no return value, yet a finish function should
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * have been generated.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * Not called, just testing compilation
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return com_planetexpress_Ship_crash_now_finish(dbus_req);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenmock_land(struct sbus_request *req, void *data)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * Raw handler, no finish function, no special arguments.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * Not called, just testing compilation
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * These are not silly tests:
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * - Will fail compilation if c-symbol name was not respected
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen * - Will fail if method order was not respected
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(vtable.crash_now == mock_crash_now);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(vtable.MoveUniverse == mock_move_universe);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(COM_PLANETEXPRESS_SHIP, "com.planetexpress.Ship");
fbd918f47f591f8084fd52b207ef29515ddd11b9Timo Sirainen ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE, "MoveUniverse");
fbd918f47f591f8084fd52b207ef29515ddd11b9Timo Sirainen ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_CRASH_NOW, "Crash");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_BECAMESENTIENT, "BecameSentient");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_COLOR, "Color");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* constants for com.planetexpress.Pilot */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(TEST_PILOT, "com.planetexpress.Pilot");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(TEST_PILOT_FULLNAME, "FullName");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Do some testing */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* This is a handler which has all the basic arguments types */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic int eject_handler(struct sbus_request *req, void *instance_data,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int16_t arg_int16, uint16_t arg_uint16, int32_t arg_int32,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t arg_uint32, int64_t arg_int64, uint64_t arg_uint64,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen double arg_double, const char *arg_string, const char *arg_object_path,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int16_t arg_int16_array[], int len_int16_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint16_t arg_uint16_array[], int len_uint16_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int32_t arg_int32_array[], int len_int32_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t arg_uint32_array[], int len_uint32_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int64_t arg_int64_array[], int len_int64_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint64_t arg_uint64_array[], int len_uint64_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen double arg_double_array[], int len_double_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *arg_string_array[], int len_string_array,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *arg_object_path_array[], int len_object_path_array)
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* Only called for leela, so double check here */
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen ck_assert_str_eq(instance_data, "Crash into the billboard");
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* Murge the various values for test case */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(arg_int64 == INT64_C(-6666666666666666));
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert(arg_uint64 == UINT64_C(7777777777777777));
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_string = "bears, beets, battlestar galactica";
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen ck_assert_str_eq(arg_object_path, "/original/object/path");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_byte_array = talloc_memdup(req, arg_byte_array, sizeof(uint8_t) * len_byte_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_byte_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_int16_array = talloc_memdup(req, arg_int16_array, sizeof(int16_t) * len_int16_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_int16_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_uint16_array = talloc_memdup(req, arg_uint16_array, sizeof(uint16_t) * len_uint16_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_uint16_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_int32_array = talloc_memdup(req, arg_int32_array, sizeof(int32_t) * len_int32_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_int32_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_uint32_array = talloc_memdup(req, arg_uint32_array, sizeof(uint32_t) * len_uint32_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_uint32_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_int64_array = talloc_memdup(req, arg_int64_array, sizeof(int64_t) * len_int64_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_int64_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_uint64_array = talloc_memdup(req, arg_uint64_array, sizeof(uint64_t) * len_uint64_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_uint64_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_double_array = talloc_memdup(req, arg_double_array, sizeof(double) * len_double_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_double_array; i++)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_string_array = talloc_memdup(req, arg_string_array, sizeof(char *) * len_string_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_double_array; i++) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(arg_string_array[i], "bears");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen arg_object_path_array = talloc_memdup(req, arg_object_path_array, sizeof(char *) * len_object_path_array);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < len_object_path_array; i++) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ck_assert_str_eq(arg_object_path_array[i], "/original");
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)
void *data,
char **values;
int hret;
{ &test_pilot_meta, 0 },
{ &test_special_meta, 0},
int ret;
return EOK;
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;
const char *value;
&error,
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) {