sbus_codegen_tests.c revision a8f6a9dd171f89ecfb41822901805b5c73b5ea77
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin/*
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin SSSD
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin sbus_codegen tests.
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin Authors:
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin Stef Walter <stefw@redhat.com>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin Copyright (C) Red Hat, Inc 2014
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is free software; you can redistribute it and/or modify
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen it under the terms of the GNU General Public License as published by
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the Free Software Foundation; either version 3 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin This program is distributed in the hope that it will be useful,
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin but WITHOUT ANY WARRANTY; without even the implied warranty of
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin GNU General Public License for more details.
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin You should have received a copy of the GNU General Public License
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin along with this program. If not, see <http://www.gnu.org/licenses/>.
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin*/
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include <stdlib.h>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include <check.h>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include <talloc.h>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include <tevent.h>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include <popt.h>
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
f2dddcb17c7d7e94cc69563d3c99f9d035224ecctrawick#include "sbus/sssd_dbus_meta.h"
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin#include "tests/sbus_codegen_tests_generated.h"
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrinstatic const struct sbus_arg_meta *
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrinfind_arg(const struct sbus_arg_meta *args,
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin const char *name)
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin{
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin const struct sbus_arg_meta *arg;
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin for (arg = args; arg->name != NULL; arg++) {
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin if (strcmp (arg->name, name) == 0)
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin return arg;
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin }
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin return NULL;
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin}
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrinSTART_TEST(test_interfaces)
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin{
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ck_assert_str_eq(com_planetexpress_Ship_meta.name, "com.planetexpress.Ship");
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin ck_assert(com_planetexpress_Ship_meta.methods != NULL);
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin ck_assert(com_planetexpress_Ship_meta.signals != NULL);
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin ck_assert(com_planetexpress_Ship_meta.properties != NULL);
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
727872d18412fc021f03969b8641810d8896820bhumbedooh /* Explicit C Symbol */
0d0ba3a410038e179b695446bb149cce6264e0abnd ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot");
727872d18412fc021f03969b8641810d8896820bhumbedooh ck_assert(test_pilot_meta.methods == NULL); /* no methods */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh ck_assert(test_pilot_meta.signals == NULL); /* no signals */
0d0ba3a410038e179b695446bb149cce6264e0abnd ck_assert(test_pilot_meta.properties != NULL);
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
727872d18412fc021f03969b8641810d8896820bhumbedooh}
0d0ba3a410038e179b695446bb149cce6264e0abndEND_TEST
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abndSTART_TEST(test_methods)
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh{
0d0ba3a410038e179b695446bb149cce6264e0abnd const struct sbus_method_meta *method;
0d0ba3a410038e179b695446bb149cce6264e0abnd const struct sbus_arg_meta *arg;
0d0ba3a410038e179b695446bb149cce6264e0abnd
727872d18412fc021f03969b8641810d8896820bhumbedooh method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse");
0d0ba3a410038e179b695446bb149cce6264e0abnd ck_assert(method != NULL);
0d0ba3a410038e179b695446bb149cce6264e0abnd ck_assert_str_eq(method->name, "MoveUniverse");
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh ck_assert(method->in_args != NULL);
1a1356f375e36db7bee379ea0684ab389579f798rbowen ck_assert(method->out_args != NULL);
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
0d0ba3a410038e179b695446bb149cce6264e0abnd arg = find_arg(method->in_args, "smoothly");
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd ck_assert(arg != NULL);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd ck_assert_str_eq(arg->name, "smoothly");
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd ck_assert_str_eq(arg->type, "b");
109b93ded5941c5c5fdbc05a2a16286ed4f7e5c8minfrin
arg = find_arg(method->out_args, "where_we_crashed");
ck_assert(arg != NULL);
ck_assert_str_eq(arg->name, "where_we_crashed");
ck_assert_str_eq(arg->type, "s");
}
END_TEST
START_TEST(test_properties)
{
const struct sbus_property_meta *prop;
prop = sbus_meta_find_property(&com_planetexpress_Ship_meta, "Color");
ck_assert(prop != NULL);
ck_assert_str_eq(prop->name, "Color");
ck_assert_str_eq(prop->type, "s");
ck_assert_int_eq(prop->flags, SBUS_PROPERTY_READABLE);
}
END_TEST
START_TEST(test_signals)
{
const struct sbus_signal_meta *signal;
const struct sbus_arg_meta *arg;
signal = sbus_meta_find_signal(&com_planetexpress_Ship_meta, "BecameSentient");
ck_assert(signal != NULL);
ck_assert_str_eq(signal->name, "BecameSentient");
ck_assert(signal->args != NULL);
arg = find_arg(signal->args, "gender");
ck_assert(arg != NULL);
ck_assert_str_eq(arg->name, "gender");
ck_assert_str_eq(arg->type, "s");
}
END_TEST
static int
mock_move_universe(struct sbus_request *dbus_req, void *data)
{
/* not called */
return 0;
}
static int
mock_crash_now(struct sbus_request *dbus_req, void *data)
{
/* not called */
return 0;
}
START_TEST(test_vtable)
{
struct com_planetexpress_Ship vtable = {
{ &com_planetexpress_Ship_meta, 0 },
mock_move_universe,
mock_crash_now,
};
/*
* These are not silly tests:
* - Will fail compilation if c-symbol name was not respected
* - Will fail if method order was not respected
*/
ck_assert(vtable.crash_now == mock_crash_now);
ck_assert(vtable.MoveUniverse == mock_move_universe);
}
END_TEST
START_TEST(test_constants)
{
ck_assert_str_eq(COM_PLANETEXPRESS_SHIP, "com.planetexpress.Ship");
ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_MOVEUNIVERSE, "MoveUniverse");
ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_CRASH_NOW, "Crash");
ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_BECAMESENTIENT, "BecameSentient");
ck_assert_str_eq(COM_PLANETEXPRESS_SHIP_COLOR, "Color");
/* constants for com.planetexpress.Pilot */
ck_assert_str_eq(TEST_PILOT, "com.planetexpress.Pilot");
ck_assert_str_eq(TEST_PILOT_FULLNAME, "FullName");
}
END_TEST
Suite *create_suite(void)
{
Suite *s = suite_create("sbus_codegen");
TCase *tc = tcase_create("defs");
/* Do some testing */
tcase_add_test(tc, test_interfaces);
tcase_add_test(tc, test_methods);
tcase_add_test(tc, test_properties);
tcase_add_test(tc, test_signals);
tcase_add_test(tc, test_vtable);
tcase_add_test(tc, test_constants);
/* Add all test cases to the test suite */
suite_add_tcase(s, tc);
return s;
}
int main(int argc, const char *argv[])
{
int opt;
poptContext pc;
int failure_count;
Suite *suite;
SRunner *sr;
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_TABLEEND
};
pc = poptGetContext(argv[0], argc, argv, long_options, 0);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
return 1;
}
}
poptFreeContext(pc);
suite = create_suite();
sr = srunner_create(suite);
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
srunner_run_all(sr, CK_ENV);
failure_count = srunner_ntests_failed(sr);
srunner_free(sr);
return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}