diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/sbus_codegen_tests.c | 166 | ||||
-rwxr-xr-x | src/tests/sbus_codegen_tests.xml | 45 | ||||
-rw-r--r-- | src/tests/sbus_codegen_tests_generated.c | 79 | ||||
-rw-r--r-- | src/tests/sbus_codegen_tests_generated.h | 24 |
4 files changed, 314 insertions, 0 deletions
diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c new file mode 100644 index 000000000..6b2abf8bc --- /dev/null +++ b/src/tests/sbus_codegen_tests.c @@ -0,0 +1,166 @@ +/* + SSSD + + sbus_codegen tests. + + Authors: + Stef Walter <stefw@redhat.com> + + Copyright (C) Red Hat, Inc 2014 + + This program is free software; you can redistribute it and/or modify + 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" + +static const struct sbus_arg_meta * +find_arg(const struct sbus_arg_meta *args, + const char *name) +{ + const struct sbus_arg_meta *arg; + for (arg = args; arg->name != NULL; arg++) { + if (strcmp (arg->name, name) == 0) + return arg; + } + + return NULL; +} + +START_TEST(test_interfaces) +{ + ck_assert_str_eq(com_planetexpress_Ship_meta.name, "com.planetexpress.Ship"); + ck_assert(com_planetexpress_Ship_meta.methods != NULL); + ck_assert(com_planetexpress_Ship_meta.signals != NULL); + ck_assert(com_planetexpress_Ship_meta.properties != NULL); + + /* Explicit C Symbol */ + ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot"); + ck_assert(test_pilot_meta.methods == NULL); /* no methods */ + ck_assert(test_pilot_meta.signals == NULL); /* no signals */ + ck_assert(test_pilot_meta.properties != NULL); + +} +END_TEST + +START_TEST(test_methods) +{ + const struct sbus_method_meta *method; + const struct sbus_arg_meta *arg; + + method = sbus_meta_find_method(&com_planetexpress_Ship_meta, "MoveUniverse"); + ck_assert(method != NULL); + ck_assert_str_eq(method->name, "MoveUniverse"); + ck_assert(method->in_args != NULL); + ck_assert(method->out_args != NULL); + + arg = find_arg(method->in_args, "smoothly"); + ck_assert(arg != NULL); + ck_assert_str_eq(arg->name, "smoothly"); + ck_assert_str_eq(arg->type, "b"); + + 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 + +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); + + /* 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); + srunner_set_fork_status(sr, CK_FORK); + /* 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); +} diff --git a/src/tests/sbus_codegen_tests.xml b/src/tests/sbus_codegen_tests.xml new file mode 100755 index 000000000..0def3585a --- /dev/null +++ b/src/tests/sbus_codegen_tests.xml @@ -0,0 +1,45 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <!-- + This file should exercise as many aspects of the sbus_codegen as + possible. See sbus_codegen_test.c for verification. + --> + + <!-- + This is an interface, it will get a sbus_interface_meta struct. + Its name will be com_planetexpress_Ship__meta, since no c symbol + is specified. + --> + <interface name="com.planetexpress.Ship"> + <!-- A property --> + <property name="Color" type="s" access="read"/> + + <!-- A method with two in and one out argument --> + <method name="MoveUniverse"> + <!-- This is a boolean arg --> + <arg name="smoothly" type="b" direction="in"/> + <!-- This is an uint32 arg --> + <arg name="speed_factor" type="u" direction="in"/> + <!-- This is a string arg --> + <arg name="where_we_crashed" type="s" direction="out"/> + </method> + + <!-- A signal with one argument --> + <signal name="BecameSentient"> + <arg name="gender" type="s"/> + </signal> + </interface> + + <!-- + Another interface. It's C name will be test_pilot, since we've overridden + the c symbol name. + --> + <interface name="com.planetexpress.Pilot"> + <annotation value="test_pilot" name="org.freedesktop.DBus.GLib.CSymbol"/> + + <!-- A property --> + <property name="FullName" type="s" access="readwrite"/> + </interface> + +</node> diff --git a/src/tests/sbus_codegen_tests_generated.c b/src/tests/sbus_codegen_tests_generated.c new file mode 100644 index 000000000..556eea12c --- /dev/null +++ b/src/tests/sbus_codegen_tests_generated.c @@ -0,0 +1,79 @@ +/* The following definitions are auto-generated from sbus_codegen_tests.xml */ + +#include "util/util.h" +#include "sbus/sssd_dbus.h" +#include "sbus/sssd_dbus_meta.h" + +/* arguments for com.planetexpress.Ship.MoveUniverse */ +const struct sbus_arg_meta com_planetexpress_Ship_MoveUniverse__in[] = { + { "smoothly", "b" }, + { "speed_factor", "u" }, + { NULL, } +}; + +/* arguments for com.planetexpress.Ship.MoveUniverse */ +const struct sbus_arg_meta com_planetexpress_Ship_MoveUniverse__out[] = { + { "where_we_crashed", "s" }, + { NULL, } +}; + +/* methods for com.planetexpress.Ship */ +const struct sbus_method_meta com_planetexpress_Ship__methods[] = { + { + "MoveUniverse", /* name */ + com_planetexpress_Ship_MoveUniverse__in, + com_planetexpress_Ship_MoveUniverse__out, + }, + { NULL, } +}; + +/* arguments for com.planetexpress.Ship.BecameSentient */ +const struct sbus_arg_meta com_planetexpress_Ship_BecameSentient__args[] = { + { "gender", "s" }, + { NULL, } +}; + +/* signals for com.planetexpress.Ship */ +const struct sbus_signal_meta com_planetexpress_Ship__signals[] = { + { + "BecameSentient", /* name */ + com_planetexpress_Ship_BecameSentient__args + }, + { NULL, } +}; + +/* property info for com.planetexpress.Ship */ +const struct sbus_property_meta com_planetexpress_Ship__properties[] = { + { + "Color", /* name */ + "s", /* signature */ + SBUS_PROPERTY_READABLE, + }, + { NULL, } +}; + +/* interface info for com.planetexpress.Ship */ +const struct sbus_interface_meta com_planetexpress_Ship_meta = { + "com.planetexpress.Ship", /* name */ + com_planetexpress_Ship__methods, + com_planetexpress_Ship__signals, + com_planetexpress_Ship__properties +}; + +/* property info for com.planetexpress.Pilot */ +const struct sbus_property_meta test_pilot__properties[] = { + { + "FullName", /* name */ + "s", /* signature */ + SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE, + }, + { NULL, } +}; + +/* interface info for com.planetexpress.Pilot */ +const struct sbus_interface_meta test_pilot_meta = { + "com.planetexpress.Pilot", /* name */ + NULL, /* no methods */ + NULL, /* no signals */ + test_pilot__properties +}; diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h new file mode 100644 index 000000000..c3a23c870 --- /dev/null +++ b/src/tests/sbus_codegen_tests_generated.h @@ -0,0 +1,24 @@ +/* The following declarations are auto-generated from sbus_codegen_tests.xml */ + +#ifndef __SBUS_CODEGEN_TESTS_XML__ +#define __SBUS_CODEGEN_TESTS_XML__ + +#include "sbus/sssd_dbus.h" + +/* ------------------------------------------------------------------------ + * DBus Interface Metadata + * + * These structure definitions are filled in with the information about + * the interfaces, methods, properties and so on. + * + * The actual definitions are found in the accompanying C file next + * to this header. + */ + +/* interface info for com.planetexpress.Ship */ +extern const struct sbus_interface_meta com_planetexpress_Ship_meta; + +/* interface info for com.planetexpress.Pilot */ +extern const struct sbus_interface_meta test_pilot_meta; + +#endif /* __SBUS_CODEGEN_TESTS_XML__ */ |