sbus_codegen_tests.c revision 46ee931314e6a5517f5c6b6b14f759364be119cc
/*
SSSD
sbus_codegen tests.
Authors:
Stef Walter <stefw@redhat.com>
Copyright (C) Red Hat, Inc 2014
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <check.h>
#include <talloc.h>
#include <tevent.h>
#include <popt.h>
#include "sbus/sssd_dbus_meta.h"
#include "tests/sbus_codegen_tests_generated.h"
#include "util/util_errors.h"
#define N_ELEMENTS(arr) \
/* The following 2 macros were taken from check's project source files (0.9.10)
*/
#ifndef _ck_assert_uint
#define _ck_assert_uint(X, OP, Y) do { \
ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%ju, "#Y"==%ju", _ck_x, _ck_y); \
} while (0)
#endif /* _ck_assert_uint */
#ifndef ck_assert_uint_eq
#define ck_assert_uint_eq(X, Y) _ck_assert_uint(X, ==, Y)
#endif /* ck_assert_uint_eq */
static const struct sbus_arg_meta *
const char *name)
{
const struct sbus_arg_meta *arg;
return arg;
}
return NULL;
}
{
/* Explicit C Symbol */
}
{
const struct sbus_method_meta *method;
const struct sbus_arg_meta *arg;
}
{
const struct sbus_property_meta *prop;
}
{
const struct sbus_signal_meta *signal;
const struct sbus_arg_meta *arg;
}
static int
{
/*
* The above arguments should match the handler signature,
* and the below finish function should have the right signature.
*
* Not called, just testing compilation
*/
}
static int
const char *where)
{
/*
* One argument, no return value, yet a finish function should
* have been generated.
*
* Not called, just testing compilation
*/
}
static int
{
/*
* Raw handler, no finish function, no special arguments.
*
* Not called, just testing compilation
*/
return 0;
}
{
struct com_planetexpress_Ship vtable = {
{ &com_planetexpress_Ship_meta, 0 },
NULL,
};
/*
* These are not silly tests:
* - Will fail compilation if c-symbol name was not respected
* - Will fail if method order was not respected
*/
}
{
/* constants for com.planetexpress.Pilot */
}
TCase *create_defs_tests(void)
{
/* Do some testing */
return tc;
}
/* This is a handler which has all the basic arguments types */
double arg_double_array[], int len_double_array,
const char *arg_string_array[], int len_string_array,
const char *arg_object_path_array[], int len_object_path_array)
{
int i;
/* Only called for leela, so double check here */
/* Murge the various values for test case */
arg_byte++;
arg_int16++;
arg_uint16++;
arg_int32++;
arg_uint32++;
arg_int64++;
arg_uint64++;
arg_double++;
arg_string = "bears, beets, battlestar galactica";
arg_object_path = "/another/object/path";
for (i = 0; i < len_byte_array; i++)
arg_byte_array[i]++;
for (i = 0; i < len_int16_array; i++)
arg_int16_array[i]++;
for (i = 0; i < len_uint16_array; i++)
arg_uint16_array[i]++;
for (i = 0; i < len_int32_array; i++)
arg_int32_array[i]++;
for (i = 0; i < len_uint32_array; i++)
arg_uint32_array[i]++;
for (i = 0; i < len_int64_array; i++)
arg_int64_array[i]++;
for (i = 0; i < len_uint64_array; i++)
arg_uint64_array[i]++;
for (i = 0; i < len_double_array; i++)
arg_double_array[i]++;
for (i = 0; i < len_double_array; i++) {
arg_string_array[i] = "beets";
}
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++) {
arg_object_path_array[i] = "/changed";
}
/* And reply with those values */
}
} while(0);
static const bool pilot_bool = true;
void *instance_data,
bool *val)
{
}
static const char *pilot_full_name = "Turanga Leela";
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,
{
}
static const double pilot_double = 3.14;
void *instance_data,
double *double_val)
{
}
static const char *pilot_string = "leela";
void *instance_data,
const char **string_val)
{
}
static const char *pilot_path = "/path/leela";
void *instance_data,
const char **path_val)
{
*path_val = pilot_path;
}
void *instance_data,
const char **string_val)
{
*string_val = NULL;
}
void *instance_data,
const char **path_val)
{
}
} while(0);
void *instance_data,
{
}
void *instance_data,
{
}
void *instance_data,
{
}
void *instance_data,
{
}
void *instance_data,
{
}
void *instance_data,
{
}
void *instance_data,
{
}
static double pilot_double_array[] = { 3.14, 0 };
void *instance_data,
{
}
void *data,
const char ***arr_out,
int *arr_len)
{
}
void *data,
const char ***arr_out,
int *arr_len)
{
}
struct test_pilot pilot_iface = {
{ &test_pilot_meta, 0 },
.Eject = eject_handler,
};
{
int ret;
"Crash into the billboard");
return EOK;
}
{
unsigned char arg_byte = 11;
double arg_double = 1.1;
const char *arg_string = "hello";
const char *arg_object_path = "/original/object/path";
double *arr_double = v_double;
char **arr_string = v_string;
char **arr_object_path = v_object_path;
&error,
ck_assert_int_eq(arr_int32[0], 0);
}
{
}
const char *object_path,
const char *iface,
const char *prop,
int type,
void *val)
{
"Get",
&error,
}
{
const char *string_val;
const char *path_val;
double double_val;
/* If a string getter returns NULL, the caller should receive "" */
/* If a string getter returns NULL, the caller should receive "/" */
}
{
int n = 0, i = 0;;
const char **strings;
const char *s;
do {
n++;
} while (dbus_message_iter_next(&arriter));
/* Allocating on NULL is bad, but this is unit test */
do {
i++;
} while (dbus_message_iter_next(&arriter));
*nels = n;
} else {
/* Fixed types are easy */
}
}
const char *object_path,
const char *iface,
const char *prop,
int type,
void **values,
int *nels)
{
"Get",
&error,
}
} while(0); \
{
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;
/* No property should be returned twice */
switch (p->type) {
case DBUS_TYPE_BOOLEAN:
break;
case DBUS_TYPE_STRING:
break;
case DBUS_TYPE_BYTE:
break;
case DBUS_TYPE_INT16:
break;
case DBUS_TYPE_UINT16:
break;
case DBUS_TYPE_INT32:
break;
case DBUS_TYPE_UINT32:
break;
case DBUS_TYPE_INT64:
break;
case DBUS_TYPE_UINT64:
break;
case DBUS_TYPE_DOUBLE:
break;
case DBUS_TYPE_OBJECT_PATH:
break;
default:
/* Not handled */
return;
}
/* This attribute was handled, get the next one */
p->handled = true;
}
{
double *double_arr_val;
int len;
int type;
int n = 0, i = 0;;
const char *s;
do {
n++;
} while (dbus_message_iter_next(&arriter));
/* Allocating on NULL is bad, but this is unit test */
do {
i++;
} while (dbus_message_iter_next(&arriter));
len = n;
}
switch (p->type) {
case DBUS_TYPE_STRING:
break;
case DBUS_TYPE_BYTE:
break;
case DBUS_TYPE_INT16:
break;
case DBUS_TYPE_UINT16:
break;
case DBUS_TYPE_INT32:
break;
case DBUS_TYPE_UINT32:
break;
case DBUS_TYPE_INT64:
break;
case DBUS_TYPE_UINT64:
break;
case DBUS_TYPE_DOUBLE:
break;
case DBUS_TYPE_OBJECT_PATH:
break;
default:
/* Not handled */
return;
}
p->handled = true;
}
{
char *attr_name;
int i;
int num_prop;
struct prop_test pilot_properties[] = {
{ "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 } },
"GetAll",
&error,
/* GetAll reply is an array of dictionaries */
num_prop = 0;
do {
for (i=0; pilot_properties[i].name; i++) {
} else {
}
break;
}
}
num_prop++;
} while(dbus_message_iter_next(&arriter));
/* All known properties must be handled now */
for (i=0; pilot_properties[i].name; i++) {
}
/* Also all properties returned from the bus must be accounted for */
}
TCase *create_handler_tests(void)
{
#if false
#endif
return tc;
}
Suite *create_suite(void)
{
suite_add_tcase(s, create_defs_tests ());
suite_add_tcase(s, create_handler_tests ());
return s;
}
{
int opt;
int failure_count;
struct poptOption long_options[] = {
};
switch (opt) {
default:
return 1;
}
}
suite = create_suite();
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
}