X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Ftests%2Fgdbus-introspection.c;h=84ba23cd74577000a7e155ec77fdff8384294334;hb=356a3987cee7ceddcb3fe623edf0bd2881895add;hp=a93c776de92e015a2e807523d3d20c03111f2d51;hpb=869b4c68332f36377bbdfd186e37f6194ae5ed5a;p=platform%2Fupstream%2Fglib.git diff --git a/gio/tests/gdbus-introspection.c b/gio/tests/gdbus-introspection.c index a93c776..84ba23c 100644 --- a/gio/tests/gdbus-introspection.c +++ b/gio/tests/gdbus-introspection.c @@ -13,9 +13,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: David Zeuthen */ @@ -34,18 +32,14 @@ static GMainLoop *loop = NULL; /* ---------------------------------------------------------------------------------------------------- */ static void -introspection_on_proxy_appeared (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - GDBusProxy *proxy, - gpointer user_data) +test_introspection (GDBusProxy *proxy) { GError *error; const gchar *xml_data; GDBusNodeInfo *node_info; - const GDBusInterfaceInfo *interface_info; - const GDBusMethodInfo *method_info; - const GDBusSignalInfo *signal_info; + GDBusInterfaceInfo *interface_info; + GDBusMethodInfo *method_info; + GDBusSignalInfo *signal_info; GVariant *result; error = NULL; @@ -62,7 +56,7 @@ introspection_on_proxy_appeared (GDBusConnection *connection, &error); g_assert_no_error (error); g_assert (result != NULL); - g_variant_get (result, "(s)", &xml_data); + g_variant_get (result, "(&s)", &xml_data); node_info = g_dbus_node_info_new_for_xml (xml_data, &error); g_assert_no_error (error); @@ -79,7 +73,8 @@ introspection_on_proxy_appeared (GDBusConnection *connection, g_assert (method_info == NULL); method_info = g_dbus_interface_info_lookup_method (interface_info, "Introspect"); g_assert (method_info != NULL); - g_assert (method_info->in_args == NULL); + g_assert (method_info->in_args != NULL); + g_assert (method_info->in_args[0] == NULL); g_assert (method_info->out_args != NULL); g_assert (method_info->out_args[0] != NULL); g_assert (method_info->out_args[1] == NULL); @@ -105,46 +100,202 @@ introspection_on_proxy_appeared (GDBusConnection *connection, } static void -introspection_on_proxy_vanished (GDBusConnection *connection, - const gchar *name, - gpointer user_data) +test_introspection_parser (void) { + GDBusProxy *proxy; + GDBusConnection *connection; + GError *error; + + error = NULL; + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, + NULL, + &error); + g_assert_no_error (error); + error = NULL; + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "com.example.TestService", /* name */ + "/com/example/TestObject", /* object path */ + "com.example.Frob", /* interface */ + NULL, /* GCancellable */ + &error); + g_assert_no_error (error); + + /* this is safe; testserver will exit once the bus goes away */ + g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL)); + + _g_assert_property_notify (proxy, "g-name-owner"); + + test_introspection (proxy); + + g_object_unref (proxy); + g_object_unref (connection); } +/* check that a parse-generate roundtrip produces identical results + */ static void -test_introspection_parser (void) +test_generate (void) { - guint watcher_id; - - session_bus_up (); - - watcher_id = g_bus_watch_proxy (G_BUS_TYPE_SESSION, - "com.example.TestService", - G_BUS_NAME_WATCHER_FLAGS_NONE, - "/com/example/TestObject", - "com.example.Frob", - G_TYPE_DBUS_PROXY, - G_DBUS_PROXY_FLAGS_NONE, - introspection_on_proxy_appeared, - introspection_on_proxy_vanished, - NULL, - NULL); - - /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return - * until one can connect to the bus but that's not how things work right now - */ - usleep (500 * 1000); - /* this is safe; testserver will exit once the bus goes away */ - g_assert (g_spawn_command_line_async ("./gdbus-testserver.py", NULL)); + GDBusNodeInfo *info; + GDBusNodeInfo *info2; + GDBusInterfaceInfo *iinfo; + GDBusMethodInfo *minfo; + GDBusSignalInfo *sinfo; + GDBusArgInfo *arginfo; + GDBusPropertyInfo *pinfo; + GDBusAnnotationInfo *aninfo; + const gchar *data = + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; + + GString *string; + GString *string2; + GError *error; + + error = NULL; + info = g_dbus_node_info_new_for_xml (data, &error); + g_assert_no_error (error); + + iinfo = g_dbus_node_info_lookup_interface (info, "com.example.Frob"); + aninfo = iinfo->annotations[0]; + g_assert_cmpstr (aninfo->key, ==, "foo"); + g_assert_cmpstr (aninfo->value, ==, "bar"); + g_assert (iinfo->annotations[1] == NULL); + minfo = g_dbus_interface_info_lookup_method (iinfo, "PairReturn"); + g_assert_cmpstr (g_dbus_annotation_info_lookup (minfo->annotations, "org.freedesktop.DBus.GLib.Async"), ==, ""); + arginfo = minfo->in_args[0]; + g_assert_cmpstr (arginfo->name, ==, "somenumber"); + g_assert_cmpstr (arginfo->signature, ==, "u"); + g_assert (minfo->in_args[1] == NULL); + arginfo = minfo->out_args[0]; + g_assert_cmpstr (arginfo->name, ==, "somestring"); + g_assert_cmpstr (arginfo->signature, ==, "s"); + g_assert (minfo->out_args[1] == NULL); + sinfo = g_dbus_interface_info_lookup_signal (iinfo, "HelloWorld"); + arginfo = sinfo->args[0]; + g_assert_cmpstr (arginfo->name, ==, "greeting"); + g_assert_cmpstr (arginfo->signature, ==, "s"); + g_assert (sinfo->args[1] == NULL); + pinfo = g_dbus_interface_info_lookup_property (iinfo, "y"); + g_assert_cmpstr (pinfo->signature, ==, "y"); + g_assert_cmpint (pinfo->flags, ==, G_DBUS_PROPERTY_INFO_FLAGS_READABLE | + G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE); - g_main_loop_run (loop); + string = g_string_new (""); + g_dbus_node_info_generate_xml (info, 2, string); - g_bus_unwatch_proxy (watcher_id); + info2 = g_dbus_node_info_new_for_xml (string->str, &error); + string2 = g_string_new (""); + g_dbus_node_info_generate_xml (info2, 2, string2); - /* tear down bus */ - session_bus_down (); + g_assert_cmpstr (string->str, ==, string2->str); + g_string_free (string, TRUE); + g_string_free (string2, TRUE); + + g_dbus_node_info_unref (info); + g_dbus_node_info_unref (info2); } +/* test that omitted direction attributes default to 'out' for signals, + * and 'in' for methods. + */ +static void +test_default_direction (void) +{ + GDBusNodeInfo *info; + GDBusInterfaceInfo *iinfo; + GDBusMethodInfo *minfo; + GDBusSignalInfo *sinfo; + GDBusArgInfo *arginfo; + const gchar *data = + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; + + GError *error; + + error = NULL; + info = g_dbus_node_info_new_for_xml (data, &error); + g_assert_no_error (error); + + iinfo = g_dbus_node_info_lookup_interface (info, "com.example.Frob"); + sinfo = g_dbus_interface_info_lookup_signal (iinfo, "HelloWorld"); + g_assert (sinfo->args != NULL); + arginfo = sinfo->args[0]; + g_assert_cmpstr (arginfo->name, ==, "greeting"); + g_assert (sinfo->args[1] == NULL); + minfo = g_dbus_interface_info_lookup_method (iinfo, "Sleep"); + g_assert (minfo->in_args != NULL); + arginfo = minfo->in_args[0]; + g_assert_cmpstr (arginfo->name, ==, "timeout"); + g_assert (minfo->in_args[1] == NULL); + + g_dbus_node_info_unref (info); +} + +static void +test_extra_data (void) +{ + GDBusNodeInfo *info; + const gchar *data = + " " + " " + " Blah blah" + " " + " " + " " + " See example" + " " + " " + " " + " " + " More docs" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; + GError *error; + + error = NULL; + info = g_dbus_node_info_new_for_xml (data, &error); + g_assert_no_error (error); + + g_dbus_node_info_unref (info); +} /* ---------------------------------------------------------------------------------------------------- */ @@ -152,18 +303,22 @@ int main (int argc, char *argv[]) { - g_type_init (); + gint ret; + g_test_init (&argc, &argv, NULL); /* all the tests rely on a shared main loop */ loop = g_main_loop_new (NULL, FALSE); - /* all the tests use a session bus with a well-known address that we can bring up and down - * using session_bus_up() and session_bus_down(). - */ - g_unsetenv ("DISPLAY"); - g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE); - g_test_add_func ("/gdbus/introspection-parser", test_introspection_parser); - return g_test_run(); + g_test_add_func ("/gdbus/introspection-generate", test_generate); + g_test_add_func ("/gdbus/introspection-default-direction", test_default_direction); + g_test_add_func ("/gdbus/introspection-extra-data", test_extra_data); + + ret = session_bus_run (); + + while (g_main_context_iteration (NULL, FALSE)); + g_main_loop_unref (loop); + + return ret; }