f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter sbus_codegen tests.
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Stef Walter <stefw@redhat.com>
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter Copyright (C) Red Hat, Inc 2014
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 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 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 * 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.
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" \
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter/* our vtable */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterconst struct sbus_method_meta pilot_methods[] = {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstatic int blink_handler(struct sbus_request *req, void *data)
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert(req->intf->vtable->meta == &pilot_meta);
71c9027d4192bf149afa4fcf9fef93bf6e901121Pavel Březina } else if (strcmp(req->path, "/test/leela") == 0) {
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter ck_assert_str_eq(data, "Crash into the billboard");
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter if (!dbus_message_get_args (req->message, &error,
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Pilot crashes when eyes closed too long */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walterstatic int eat_handler(struct sbus_request *req, void *data)
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &count,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter return sbus_request_return_and_finish(req, DBUS_TYPE_INVALID);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozekstatic int crash_handler(struct sbus_request *req, void *data)
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek /* Pilot crashes by returning a malformed UTF-8 string */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walterstatic int pilot_test_server_init(struct sbus_connection *server, void *unused)
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_impl.vtable, "/test/leela",
9fa95168d80beba04b333b06edc492ecb8b085a1Pavel Březina ret = sbus_conn_register_iface(server, &pilot_impl.vtable, "/test/fry",
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Leela crashes with a duration higher than 5 */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* Fry daesn't crash with a duration lower than 5 */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, count,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter ck_assert(dbus_error_has_name(&error, DBUS_ERROR_INVALID_ARGS));
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek ck_assert(dbus_error_has_name(&error, DBUS_ERROR_INVALID_ARGS));
6b01dae732eedee808f32a9cdd4b5656a9f839c4Jakub Hrozek#endif /* HAVE_DBUSBASICVALUE */
42c28b9424b6ef8a0021b124773e171dd5defaddJakub Hrozek client = test_dbus_setup_mock(ctx, NULL, pilot_test_server_init, NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR, "Input-output error");
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR,
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek /* NULL message must also work */
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek error = sbus_error_new(ctx, DBUS_ERROR_IO_ERROR, NULL);
87729e3a6c56383642a8d3a86b2856487f2ee064Jakub Hrozek ck_assert(dbus_error_has_name(error, DBUS_ERROR_IO_ERROR));
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter tcase_add_test(tc, test_request_parse_bad_args);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
f5e47e1d65f80ffdb1893feab18583a74d661214Stef Walter return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);