f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter/*
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter SSSD
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter sbus_codegen tests.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Authors:
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Stef Walter <stefw@redhat.com>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Copyright (C) Red Hat, Inc 2014
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter This program is free software; you can redistribute it and/or modify
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter it under the terms of the GNU General Public License as published by
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter the Free Software Foundation; either version 3 of the License, or
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter (at your option) any later version.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter This program is distributed in the hope that it will be useful,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter but WITHOUT ANY WARRANTY; without even the implied warranty of
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter GNU General Public License for more details.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter You should have received a copy of the GNU General Public License
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter along with this program. If not, see <http://www.gnu.org/licenses/>.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter*/
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include <stdlib.h>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include <check.h>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include <talloc.h>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include <tevent.h>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include <popt.h>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include "common.h"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include "sbus/sssd_dbus.h"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include "sbus/sssd_dbus_meta.h"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#include "util/util_errors.h"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter/*
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter * Although one would normally rely on the codegen to generate these
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter * structures, we want to test this functionality *before* we test
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter * the codegen in sbus_codegen_tests ... so these are hand rolled.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#define PILOT_IFACE "test.Pilot"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter#define PILOT_BLINK "Blink"
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter#define PILOT_EAT "Eat"
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek#define PILOT_CRASH "Crash"
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek#define PILOT_IFACE_INTROSPECT \
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" \
f7adbb15dbdcb79e291f7cf361a400ce25f7b382Pavel Březina "<node name=\"/test/leela\">\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <method name=\"Introspect\">\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <arg type=\"s\" name=\"data\" direction=\"out\" />\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " </method>\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " </interface>\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <method name=\"Get\">\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"s\" name=\"interface_name\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"s\" name=\"property_name\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"v\" name=\"value\" direction=\"out\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " </method>\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <method name=\"Set\">\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"s\" name=\"interface_name\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"s\" name=\"property_name\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"v\" name=\"value\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " </method>\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <method name=\"GetAll\">\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"s\" name=\"interface_name\" direction=\"in\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " <arg type=\"a{sv}\" name=\"props\" direction=\"out\" />\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " </method>\n" \
b742179ac0790068380618ab72a06af18544f09cPavel Březina " </interface>\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <interface name=\"test.Pilot\">\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <method name=\"Blink\" />\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " <method name=\"Eat\" />\n" \
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek " <method name=\"Crash\" />\n" \
80d0bd38268c02fd32f62b02ae59f19229ca1a79Pavel Březina " </interface>\n" \
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek "</node>\n"
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter/* our vtable */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstruct pilot_vtable {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter struct sbus_vtable vtable;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter sbus_msg_handler_fn Blink;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter sbus_msg_handler_fn Eat;
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek sbus_msg_handler_fn Crash;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter};
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterconst struct sbus_method_meta pilot_methods[] = {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_BLINK, /* method name */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter NULL, /* in args: manually parsed */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter NULL, /* out args: manually parsed */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter offsetof(struct pilot_vtable, Blink),
615316359a8cef049f1bb4e8fef5fd52cb1755faPavel Březina NULL
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter },
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter {
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter PILOT_EAT, /* method name */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter NULL, /* in args: manually parsed */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter NULL, /* out args: manually parsed */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter offsetof(struct pilot_vtable, Eat),
615316359a8cef049f1bb4e8fef5fd52cb1755faPavel Březina NULL
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter },
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek {
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek PILOT_CRASH, /* method name */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek NULL, /* in args: manually parsed */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek NULL, /* out args: manually parsed */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek offsetof(struct pilot_vtable, Crash),
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek NULL
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek },
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter { NULL, }
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter};
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterconst struct sbus_interface_meta pilot_meta = {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_IFACE, /* name */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter pilot_methods,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter NULL, /* no signals */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter NULL, /* no properties */
4f7f714e118e95896fac5239c7a8b529c39a4758Jakub Hrozek NULL, /* no GetAll invoker */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter};
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstatic int blink_handler(struct sbus_request *req, void *data)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBusError error = DBUS_ERROR_INIT;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_int32_t duration = 0;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_bool_t crashed;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(req->intf->vtable->meta == &pilot_meta);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(data != NULL);
66277b21179d95f6e96abed01a20ccbccf27ce99Pavel Březina ck_assert(data == req->intf->handler_data);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina ck_assert_str_eq(req->intf->path, req->path);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina if (strcmp(req->path, "/test/fry") == 0) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert_str_eq(data, "Don't crash");
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina } else if (strcmp(req->path, "/test/leela") == 0) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert_str_eq(data, "Crash into the billboard");
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter } else {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_abort();
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter }
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter if (!dbus_message_get_args (req->message, &error,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INT32, &duration,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID)) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter sbus_request_fail_and_finish(req, &error);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_error_free(&error);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return EOK;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter }
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Pilot crashes when eyes closed too long */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter crashed = (duration > 5);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return sbus_request_return_and_finish(req,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_BOOLEAN, &crashed,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walterstatic int eat_handler(struct sbus_request *req, void *data)
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter{
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_int32_t integer;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_bool_t boolean;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter const char **array;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter int count;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter if (!sbus_request_parse_or_finish (req,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INT32, &integer,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &count,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_BOOLEAN, &boolean,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INVALID)) {
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter return EOK; /* handled */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter }
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert_int_eq(integer, 5);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(boolean == TRUE);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert_int_eq(count, 3);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert_str_eq(array[0], "one");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert_str_eq(array[1], "two");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert_str_eq(array[2], "three");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter return sbus_request_return_and_finish(req, DBUS_TYPE_INVALID);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter}
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozekstatic int crash_handler(struct sbus_request *req, void *data)
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek{
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek /* Pilot crashes by returning a malformed UTF-8 string */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek const char *invalid = "ad\351la\357d";
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek return sbus_request_return_and_finish(req,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBUS_TYPE_STRING, &invalid,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBUS_TYPE_INVALID);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek}
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstruct pilot_vtable pilot_impl = {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter { &pilot_meta, 0 },
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter .Blink = blink_handler,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter .Eat = eat_handler,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek .Crash = crash_handler,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter};
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstatic int pilot_test_server_init(struct sbus_connection *server, void *unused)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter int ret;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_impl.vtable, "/test/leela",
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech discard_const("Crash into the billboard"));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert_int_eq(ret, EOK);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_impl.vtable, "/test/fry",
626d8217a2e578ba641ae3c968752aa15284a210Petr Čech discard_const("Don't crash"));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert_int_eq(ret, EOK);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return EOK;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef WalterSTART_TEST(test_raw_handler)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter TALLOC_CTX *ctx;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBusConnection *client;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBusError error = DBUS_ERROR_INIT;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBusMessage *reply;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_bool_t crashed;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_int32_t duration;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ctx = talloc_new(NULL);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Leela crashes with a duration higher than 5 */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter duration = 10;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter reply = test_dbus_call_sync(client,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter "/test/leela",
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_IFACE,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_BLINK,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter &error,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INT32, &duration,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(reply != NULL);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(!dbus_error_is_set(&error));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(dbus_message_get_args(reply, NULL,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_BOOLEAN, &crashed,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_message_unref (reply);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(crashed == true);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Fry daesn't crash with a duration lower than 5 */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter duration = 1;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter reply = test_dbus_call_sync(client,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter "/test/fry",
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_IFACE,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter PILOT_BLINK,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter &error,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INT32, &duration,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(reply != NULL);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(!dbus_error_is_set(&error));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(dbus_message_get_args(reply, NULL,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_BOOLEAN, &crashed,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter DBUS_TYPE_INVALID));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter dbus_message_unref (reply);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(crashed == FALSE);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter talloc_free(ctx);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}
f5e47e1d65f80ffdb1893feab18583a74d661214Stef WalterEND_TEST
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef WalterSTART_TEST(test_request_parse_ok)
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter{
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter const char *args[] = { "one", "two", "three" };
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter const char **array;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter TALLOC_CTX *ctx;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusConnection *client;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusError error = DBUS_ERROR_INIT;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusMessage *reply;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_bool_t boolean;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_int32_t integer;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter int count;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ctx = talloc_new(NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter boolean = TRUE;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter integer = 5;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter count = 3;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter array = args;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter reply = test_dbus_call_sync(client,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter "/test/leela",
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter PILOT_IFACE,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter PILOT_EAT,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter &error,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INT32, &integer,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, count,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_BOOLEAN, &boolean,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INVALID);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(reply != NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(!dbus_error_is_set(&error));
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(dbus_message_get_args(reply, NULL,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INVALID));
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_message_unref (reply);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter talloc_free(ctx);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter}
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef WalterEND_TEST
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef WalterSTART_TEST(test_request_parse_bad_args)
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter{
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter TALLOC_CTX *ctx;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusConnection *client;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusError error = DBUS_ERROR_INIT;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBusMessage *reply;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ctx = talloc_new(NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter reply = test_dbus_call_sync(client,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter "/test/leela",
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter PILOT_IFACE,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter PILOT_EAT,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter &error,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_INVALID); /* bad agruments */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(reply == NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(dbus_error_is_set(&error));
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(dbus_error_has_name(&error, DBUS_ERROR_INVALID_ARGS));
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter dbus_error_free(&error);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter talloc_free(ctx);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter}
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef WalterEND_TEST
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub HrozekSTART_TEST(test_request_dontcrash)
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek{
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek#ifdef HAVE_DBUSBASICVALUE
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek TALLOC_CTX *ctx;
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBusConnection *client;
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBusError error = DBUS_ERROR_INIT;
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBusMessage *reply;
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek ctx = talloc_new(NULL);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek reply = test_dbus_call_sync(client,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek "/test/leela",
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek PILOT_IFACE,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek PILOT_CRASH,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek &error,
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek DBUS_TYPE_INVALID); /* bad agruments */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek ck_assert(reply == NULL);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek ck_assert(dbus_error_is_set(&error));
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek ck_assert(dbus_error_has_name(&error, DBUS_ERROR_INVALID_ARGS));
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek dbus_error_free(&error);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek talloc_free(ctx);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek#endif /* HAVE_DBUSBASICVALUE */
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek}
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub HrozekEND_TEST
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub HrozekSTART_TEST(test_introspection)
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek{
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek TALLOC_CTX *ctx;
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBusConnection *client;
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBusError error = DBUS_ERROR_INIT;
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBusMessage *reply;
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek char *xml;
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek ctx = talloc_new(NULL);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek reply = test_dbus_call_sync(client,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek "/test/leela",
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBUS_INTROSPECT_INTERFACE,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBUS_INTROSPECT_METHOD,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek &error,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBUS_TYPE_INVALID); /* bad agruments */
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek ck_assert(reply != NULL);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek ck_assert(!dbus_error_is_set(&error));
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek ck_assert(dbus_message_get_args(reply, NULL,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBUS_TYPE_STRING, &xml,
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek DBUS_TYPE_INVALID));
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek ck_assert_str_eq(PILOT_IFACE_INTROSPECT, xml);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek dbus_message_unref(reply);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek talloc_free(ctx);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek}
42c28b9424b6ef8a0021b124773e171dd5defaddJakub HrozekEND_TEST
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub HrozekSTART_TEST(test_sbus_new_error)
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek{
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek TALLOC_CTX *ctx;
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek DBusError *error;
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ctx = talloc_new(NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR, "Input-output error");
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(error != NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_is_set(error));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek talloc_free(error);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR,
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek "The answer should have been %d", 42);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(error != NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_is_set(error));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek talloc_free(error);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek /* NULL message must also work */
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR, NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(error != NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_is_set(error));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek talloc_free(error);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek talloc_free(ctx);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek}
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub HrozekEND_TEST
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek
f5e47e1d65f80ffdb1893feab18583a74d661214Stef WalterTCase *create_sbus_tests(void)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter TCase *tc = tcase_create("tests");
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter tcase_add_test(tc, test_raw_handler);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter tcase_add_test(tc, test_request_parse_ok);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter tcase_add_test(tc, test_request_parse_bad_args);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek tcase_add_test(tc, test_request_dontcrash);
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek tcase_add_test(tc, test_introspection);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek tcase_add_test(tc, test_sbus_new_error);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return tc;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef WalterSuite *create_suite(void)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Suite *s = suite_create("sbus");
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter suite_add_tcase(s, create_sbus_tests());
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return s;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterint main(int argc, const char *argv[])
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter{
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter int opt;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter poptContext pc;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter int failure_count;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Suite *suite;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter SRunner *sr;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter struct poptOption long_options[] = {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter POPT_AUTOHELP
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter POPT_TABLEEND
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter };
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter while ((opt = poptGetNextOpt(pc)) != -1) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter switch (opt) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter default:
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter fprintf(stderr, "\nInvalid option %s: %s\n\n",
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter poptBadOption(pc, 0), poptStrerror(opt));
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter poptPrintUsage(pc, stderr, 0);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return 1;
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter }
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter }
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter poptFreeContext(pc);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter suite = create_suite();
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter sr = srunner_create(suite);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter srunner_run_all(sr, CK_ENV);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter failure_count = srunner_ntests_failed(sr);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter srunner_free(sr);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter}