1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
27 #include "gdbus-tests.h"
29 /* all tests rely on a shared mainloop */
30 static GMainLoop *loop = NULL;
32 /* ---------------------------------------------------------------------------------------------------- */
33 /* Test introspection parser */
34 /* ---------------------------------------------------------------------------------------------------- */
37 test_introspection (GDBusProxy *proxy)
40 const gchar *xml_data;
41 GDBusNodeInfo *node_info;
42 GDBusInterfaceInfo *interface_info;
43 GDBusMethodInfo *method_info;
44 GDBusSignalInfo *signal_info;
50 * Invoke Introspect(), then parse the output.
52 result = g_dbus_proxy_call_sync (proxy,
53 "org.freedesktop.DBus.Introspectable.Introspect",
55 G_DBUS_CALL_FLAGS_NONE,
59 g_assert_no_error (error);
60 g_assert (result != NULL);
61 g_variant_get (result, "(&s)", &xml_data);
63 node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
64 g_assert_no_error (error);
65 g_assert (node_info != NULL);
67 /* for now we only check a couple of things. TODO: check more things */
69 interface_info = g_dbus_node_info_lookup_interface (node_info, "com.example.NonExistantInterface");
70 g_assert (interface_info == NULL);
72 interface_info = g_dbus_node_info_lookup_interface (node_info, "org.freedesktop.DBus.Introspectable");
73 g_assert (interface_info != NULL);
74 method_info = g_dbus_interface_info_lookup_method (interface_info, "NonExistantMethod");
75 g_assert (method_info == NULL);
76 method_info = g_dbus_interface_info_lookup_method (interface_info, "Introspect");
77 g_assert (method_info != NULL);
78 g_assert (method_info->in_args == NULL);
79 g_assert (method_info->out_args != NULL);
80 g_assert (method_info->out_args[0] != NULL);
81 g_assert (method_info->out_args[1] == NULL);
82 g_assert_cmpstr (method_info->out_args[0]->signature, ==, "s");
84 interface_info = g_dbus_node_info_lookup_interface (node_info, "com.example.Frob");
85 g_assert (interface_info != NULL);
86 signal_info = g_dbus_interface_info_lookup_signal (interface_info, "TestSignal");
87 g_assert (signal_info != NULL);
88 g_assert (signal_info->args != NULL);
89 g_assert (signal_info->args[0] != NULL);
90 g_assert_cmpstr (signal_info->args[0]->signature, ==, "s");
91 g_assert (signal_info->args[1] != NULL);
92 g_assert_cmpstr (signal_info->args[1]->signature, ==, "o");
93 g_assert (signal_info->args[2] != NULL);
94 g_assert_cmpstr (signal_info->args[2]->signature, ==, "v");
95 g_assert (signal_info->args[3] == NULL);
97 g_dbus_node_info_unref (node_info);
98 g_variant_unref (result);
100 g_main_loop_quit (loop);
104 test_introspection_parser (void)
107 GDBusConnection *connection;
112 /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
113 * until one can connect to the bus but that's not how things work right now
118 connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
121 g_assert_no_error (error);
123 proxy = g_dbus_proxy_new_sync (connection,
124 G_DBUS_PROXY_FLAGS_NONE,
125 NULL, /* GDBusInterfaceInfo */
126 "com.example.TestService", /* name */
127 "/com/example/TestObject", /* object path */
128 "com.example.Frob", /* interface */
129 NULL, /* GCancellable */
131 g_assert_no_error (error);
133 /* this is safe; testserver will exit once the bus goes away */
134 g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
136 _g_assert_property_notify (proxy, "g-name-owner");
138 test_introspection (proxy);
140 g_object_unref (proxy);
141 g_object_unref (connection);
144 /* ---------------------------------------------------------------------------------------------------- */
151 g_test_init (&argc, &argv, NULL);
153 /* all the tests rely on a shared main loop */
154 loop = g_main_loop_new (NULL, FALSE);
156 /* all the tests use a session bus with a well-known address that we can bring up and down
157 * using session_bus_up() and session_bus_down().
159 g_unsetenv ("DISPLAY");
160 g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
162 g_test_add_func ("/gdbus/introspection-parser", test_introspection_parser);