From 1b0b248030e954d6d81c3b0102bb7bd2efc4998d Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 28 Feb 2014 12:00:46 +0100 Subject: [PATCH 2/6] logger tests: use a GVariant as params --- tests/logger/dbus/test-tpl-log-iter-pidgin.c | 56 +++++++++++++--------------- tests/logger/dbus/test-tpl-log-walker.c | 54 +++++++++++++-------------- 2 files changed, 51 insertions(+), 59 deletions(-) diff --git a/tests/logger/dbus/test-tpl-log-iter-pidgin.c b/tests/logger/dbus/test-tpl-log-iter-pidgin.c index 63ad87e..b4dd916 100644 --- a/tests/logger/dbus/test-tpl-log-iter-pidgin.c +++ b/tests/logger/dbus/test-tpl-log-iter-pidgin.c @@ -48,9 +48,9 @@ setup (PidginTestCaseFixture* fixture, { GArray *features; GError *error = NULL; - GHashTable *params = (GHashTable *) user_data; - GValue *boxed_params; - const gchar *account_path; + GVariant *params = (GVariant *) user_data; + GHashTable *asv; + const gchar *account_path = NULL; fixture->main_loop = g_main_loop_new (NULL, FALSE); g_assert (fixture->main_loop != NULL); @@ -74,15 +74,14 @@ setup (PidginTestCaseFixture* fixture, g_assert (fixture->account_service != NULL); /* account-path will be set-up as parameter as well, this is not an issue */ - account_path = tp_asv_get_string (params, "account-path"); + g_variant_lookup (params, "account-path", "&o", &account_path); g_assert (account_path != NULL); - boxed_params = tp_g_value_slice_new_boxed (TP_HASH_TYPE_STRING_VARIANT_MAP, - params); - g_object_set_property (G_OBJECT (fixture->account_service), - "parameters", - boxed_params); - tp_g_value_slice_free (boxed_params); + asv = tp_asv_from_vardict (params); + g_object_set (G_OBJECT (fixture->account_service), + "parameters", asv, + NULL); + g_hash_table_unref (asv); tp_dbus_daemon_register_object (fixture->bus, account_path, @@ -92,9 +91,7 @@ setup (PidginTestCaseFixture* fixture, g_assert (fixture->factory != NULL); fixture->account = tp_client_factory_ensure_account (fixture->factory, - tp_asv_get_string (params, "account-path"), - tp_asv_to_vardict (params), - &error); + account_path, params, &error); g_assert_no_error (error); g_assert (fixture->account != NULL); @@ -808,38 +805,37 @@ test_rewind (PidginTestCaseFixture *fixture, } +static GVariant * +create_params (void) +{ + GVariantDict dict; + + g_variant_dict_init (&dict, NULL); + g_variant_dict_insert (&dict, "account", "s", "user"); + g_variant_dict_insert (&dict, "server", "s", "irc.freenode.net"); + g_variant_dict_insert (&dict, "account-path", "o", + TP_ACCOUNT_OBJECT_PATH_BASE "foo/irc/baz"); + + return g_variant_dict_end (&dict); +} + gint main (gint argc, gchar **argv) { - GHashTable *params; gint retval; g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id="); - params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify) tp_g_value_slice_free); - g_assert (params != NULL); - - g_hash_table_insert (params, "account", - tp_g_value_slice_new_static_string ("user")); - g_hash_table_insert (params, "server", - tp_g_value_slice_new_static_string ("irc.freenode.net")); - g_hash_table_insert (params, "account-path", - tp_g_value_slice_new_static_string ( - TP_ACCOUNT_OBJECT_PATH_BASE "foo/irc/baz")); - g_test_add ("/log-iter-xml/get-events", - PidginTestCaseFixture, params, + PidginTestCaseFixture, create_params (), setup, test_get_events, teardown); g_test_add ("/log-iter-xml/rewind", - PidginTestCaseFixture, params, + PidginTestCaseFixture, create_params (), setup, test_rewind, teardown); retval = g_test_run (); - g_hash_table_unref (params); - return retval; } diff --git a/tests/logger/dbus/test-tpl-log-walker.c b/tests/logger/dbus/test-tpl-log-walker.c index 5edb5d1..4d0c289 100644 --- a/tests/logger/dbus/test-tpl-log-walker.c +++ b/tests/logger/dbus/test-tpl-log-walker.c @@ -50,9 +50,9 @@ setup (WalkerTestCaseFixture* fixture, { GArray *features; GError *error = NULL; - GHashTable *params = (GHashTable *) user_data; - GValue *boxed_params; - const gchar *account_path; + GVariant *params = (GVariant *) user_data; + GHashTable *asv; + const gchar *account_path = NULL; fixture->main_loop = g_main_loop_new (NULL, FALSE); g_assert (fixture->main_loop != NULL); @@ -74,15 +74,14 @@ setup (WalkerTestCaseFixture* fixture, g_assert (fixture->account_service != NULL); /* account-path will be set-up as parameter as well, this is not an issue */ - account_path = tp_asv_get_string (params, "account-path"); + g_variant_lookup (params, "account-path", "&o", &account_path); g_assert (account_path != NULL); - boxed_params = tp_g_value_slice_new_boxed (TP_HASH_TYPE_STRING_VARIANT_MAP, - params); - g_object_set_property (G_OBJECT (fixture->account_service), - "parameters", - boxed_params); - tp_g_value_slice_free (boxed_params); + asv = tp_asv_from_vardict (params); + g_object_set (G_OBJECT (fixture->account_service), + "parameters", asv, + NULL); + g_hash_table_unref (asv); tp_dbus_daemon_register_object (fixture->bus, account_path, @@ -92,9 +91,7 @@ setup (WalkerTestCaseFixture* fixture, g_assert (fixture->factory != NULL); fixture->account = tp_client_factory_ensure_account (fixture->factory, - tp_asv_get_string (params, "account-path"), - tp_asv_to_vardict (params), - &error); + account_path, params, &error); g_assert_no_error (error); g_assert (fixture->account != NULL); @@ -423,37 +420,36 @@ test_rewind (WalkerTestCaseFixture *fixture, g_object_unref (user5); } +static GVariant * +create_params (void) +{ + GVariantDict dict; + + g_variant_dict_init (&dict, NULL); + g_variant_dict_insert (&dict, "account", "s", "user@collabora.co.uk"); + g_variant_dict_insert (&dict, "account-path", "o", + TP_ACCOUNT_OBJECT_PATH_BASE + "gabble/jabber/user_40collabora_2eco_2euk"); + + return g_variant_dict_end (&dict); +} gint main (gint argc, gchar **argv) { - GHashTable *params; gint retval; g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id="); - params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify) tp_g_value_slice_free); - g_assert (params != NULL); - - g_hash_table_insert (params, "account", - tp_g_value_slice_new_static_string ("user@collabora.co.uk")); - g_hash_table_insert (params, "account-path", - tp_g_value_slice_new_static_string ( - TP_ACCOUNT_OBJECT_PATH_BASE - "gabble/jabber/user_40collabora_2eco_2euk")); - g_test_add ("/log-walker/get-events", - WalkerTestCaseFixture, params, + WalkerTestCaseFixture, create_params (), setup, test_get_events, teardown); g_test_add ("/log-walker/rewind", - WalkerTestCaseFixture, params, + WalkerTestCaseFixture, create_params (), setup, test_rewind, teardown); retval = g_test_run (); - g_hash_table_unref (params); - return retval; } -- 1.8.5.3