From 8cf81e5722d93548aac8e9c08f33fb5771fa249b Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 27 Feb 2014 11:57:40 +0100 Subject: [PATCH 07/11] stop using tp_message_peek() in tests --- tests/dbus/cm-message.c | 182 ++++++++++++++++++++++++++-------------------- tests/dbus/text-channel.c | 11 ++- tests/lib/echo-chan.c | 8 +- 3 files changed, 117 insertions(+), 84 deletions(-) diff --git a/tests/dbus/cm-message.c b/tests/dbus/cm-message.c index f014fd1..9d3b925 100644 --- a/tests/dbus/cm-message.c +++ b/tests/dbus/cm-message.c @@ -49,11 +49,12 @@ test_new_from_parts (Test *test, GPtrArray *parts; TpHandle sender; TpMessage *msg; - const GHashTable *part; + GVariant *part; GVariant *part_vardict; gboolean valid; const gchar *s; gchar *token; + guint u; parts = g_ptr_array_new_full (2, (GDestroyNotify) g_hash_table_unref); @@ -82,19 +83,21 @@ test_new_from_parts (Test *test, g_assert (TP_IS_CM_MESSAGE (msg)); g_assert_cmpuint (tp_message_count_parts (msg), ==, 2); - part = tp_message_peek (msg, 0); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-sender", NULL), ==, - sender); - g_assert_cmpstr (tp_asv_get_string (part, "message-sender-id"), ==, - "bob"); - g_assert_cmpstr (tp_asv_get_string (part, "message-token"), ==, - "token"); - - part = tp_message_peek (msg, 1); - g_assert_cmpstr (tp_asv_get_string (part, "content-type"), ==, - "text/plain"); - g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, - "Badger"); + part = tp_message_dup_part (msg, 0); + g_variant_lookup (part, "message-sender", "u", &u); + g_assert_cmpuint (u, ==, sender); + g_variant_lookup (part, "message-sender-id", "&s", &s); + g_assert_cmpstr (s, ==, "bob"); + g_variant_lookup (part, "message-token", "&s", &s); + g_assert_cmpstr (s, ==, "token"); + g_variant_unref (part); + + part = tp_message_dup_part (msg, 1); + g_variant_lookup (part, "content-type", "&s", &s); + g_assert_cmpstr (s, ==, "text/plain"); + g_variant_lookup (part, "content", "&s", &s); + g_assert_cmpstr (s, ==, "Badger"); + g_variant_unref (part); part_vardict = tp_message_dup_part (msg, 1); g_assert_cmpstr (g_variant_get_type_string (part_vardict), ==, "a{sv}"); @@ -131,7 +134,9 @@ test_new_text (Test *test, { TpHandle sender; TpMessage *msg; - const GHashTable *part; + GVariant *part; + guint u; + const gchar *s; sender = tp_handle_ensure (test->contact_repo, "bob", NULL, &test->error); g_assert_no_error (test->error); @@ -141,20 +146,24 @@ test_new_text (Test *test, g_assert (TP_IS_CM_MESSAGE (msg)); g_assert_cmpuint (tp_message_count_parts (msg), ==, 2); - part = tp_message_peek (msg, 0); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-sender", NULL), ==, - sender); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-type", NULL), ==, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); - g_assert_cmpstr (tp_asv_get_string (part, "message-sender-id"), ==, - "bob"); - g_assert_cmpstr (tp_asv_get_string (part, "message-token"), ==, NULL); - - part = tp_message_peek (msg, 1); - g_assert_cmpstr (tp_asv_get_string (part, "content-type"), ==, - "text/plain"); - g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, - "builds some stuff"); + part = tp_message_dup_part (msg, 0); + g_variant_lookup (part, "message-sender", "u", &u); + g_assert_cmpuint (u, ==, sender); + g_variant_lookup (part, "message-type", "u", &u); + g_assert_cmpuint (u, ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); + g_variant_lookup (part, "message-sender-id", "&s", &s); + g_assert_cmpstr (s, ==, "bob"); + s = NULL; + g_variant_lookup (part, "message-token", "&s", &s); + g_assert_cmpstr (s, ==, NULL); + g_variant_unref (part); + + part = tp_message_dup_part (msg, 1); + g_variant_lookup (part, "content-type", "&s", &s); + g_assert_cmpstr (s, ==, "text/plain"); + g_variant_lookup (part, "content", "&s", &s); + g_assert_cmpstr (s, ==, "builds some stuff"); + g_variant_unref (part); g_assert_cmpuint (tp_message_get_message_type (msg), ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); @@ -177,8 +186,9 @@ test_set_message (Test *test, { TpHandle sender; TpMessage *msg, *echo; - const GHashTable *part; - GPtrArray *echo_parts; + GVariant *part, *echo_parts, *echo_part; + guint u; + const gchar *s; sender = tp_handle_ensure (test->contact_repo, "escher@tuxedo.cat", NULL, &test->error); @@ -199,23 +209,27 @@ test_set_message (Test *test, /* destroy the echo */ g_object_unref (echo); - part = tp_message_peek (msg, 0); - g_assert (G_VALUE_HOLDS (tp_asv_lookup (part, "delivery-echo"), - TP_ARRAY_TYPE_MESSAGE_PART_LIST)); + part = tp_message_dup_part (msg, 0); - echo_parts = tp_asv_get_boxed (part, "delivery-echo", - TP_ARRAY_TYPE_MESSAGE_PART_LIST); + echo_parts = g_variant_lookup_value (part, "delivery-echo", + G_VARIANT_TYPE ("aa{sv}")); g_assert (echo_parts != NULL); - g_assert_cmpuint (echo_parts->len, ==, 2); - - part = g_ptr_array_index (echo_parts, 0); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-type", NULL), ==, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); - - part = g_ptr_array_index (echo_parts, 1); - g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, - "meows"); - + g_assert_cmpuint (g_variant_n_children (echo_parts), ==, 2); + g_variant_unref (part); + + echo_part = g_variant_get_child_value (echo_parts, 0); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "message-type", "u", &u); + g_assert_cmpuint (u, ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); + g_variant_unref (echo_part); + + echo_part = g_variant_get_child_value (echo_parts, 1); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "content", "&s", &s); + g_assert_cmpstr (s, ==, "meows"); + g_variant_unref (echo_part); + + g_variant_unref (echo_parts); g_object_unref (msg); } @@ -225,8 +239,9 @@ test_set_message_2 (Test *test, { TpHandle sender; TpMessage *msg, *echo; - const GHashTable *part; - GPtrArray *echo_parts; + GVariant *part, *echo_parts, *echo_part; + guint u; + const gchar *s; sender = tp_handle_ensure (test->contact_repo, "escher@tuxedo.cat", NULL, &test->error); @@ -245,22 +260,27 @@ test_set_message_2 (Test *test, /* change the echo */ tp_message_set_string (echo, 1, "content", "yawns"); - part = tp_message_peek (msg, 0); - g_assert (G_VALUE_HOLDS (tp_asv_lookup (part, "delivery-echo"), - TP_ARRAY_TYPE_MESSAGE_PART_LIST)); + part = tp_message_dup_part (msg, 0); - echo_parts = tp_asv_get_boxed (part, "delivery-echo", - TP_ARRAY_TYPE_MESSAGE_PART_LIST); + echo_parts = g_variant_lookup_value (part, "delivery-echo", + G_VARIANT_TYPE ("aa{sv}")); g_assert (echo_parts != NULL); - - part = g_ptr_array_index (echo_parts, 0); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-type", NULL), ==, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); - - part = g_ptr_array_index (echo_parts, 1); - g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, - "meows"); - + g_assert_cmpuint (g_variant_n_children (echo_parts), ==, 2); + g_variant_unref (part); + + echo_part = g_variant_get_child_value (echo_parts, 0); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "message-type", "u", &u); + g_assert_cmpuint (u, ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); + g_variant_unref (echo_part); + + echo_part = g_variant_get_child_value (echo_parts, 1); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "content", "&s", &s); + g_assert_cmpstr (s, ==, "meows"); + g_variant_unref (echo_part); + + g_variant_unref (echo_parts); g_object_unref (echo); g_object_unref (msg); } @@ -280,8 +300,9 @@ test_take_message (Test *test, { TpHandle sender; TpMessage *msg, *echo; - const GHashTable *part; - GPtrArray *echo_parts; + GVariant *part, *echo_parts, *echo_part; + guint u; + const gchar *s; gboolean destroyed = FALSE; sender = tp_handle_ensure (test->contact_repo, "escher@tuxedo.cat", NULL, @@ -305,22 +326,27 @@ test_take_message (Test *test, /* ensure the message was destroyed */ g_assert (destroyed == TRUE); - part = tp_message_peek (msg, 0); - g_assert (G_VALUE_HOLDS (tp_asv_lookup (part, "delivery-echo"), - TP_ARRAY_TYPE_MESSAGE_PART_LIST)); + part = tp_message_dup_part (msg, 0); - echo_parts = tp_asv_get_boxed (part, "delivery-echo", - TP_ARRAY_TYPE_MESSAGE_PART_LIST); + echo_parts = g_variant_lookup_value (part, "delivery-echo", + G_VARIANT_TYPE ("aa{sv}")); g_assert (echo_parts != NULL); - - part = g_ptr_array_index (echo_parts, 0); - g_assert_cmpuint (tp_asv_get_uint32 (part, "message-type", NULL), ==, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); - - part = g_ptr_array_index (echo_parts, 1); - g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, - "meows"); - + g_assert_cmpuint (g_variant_n_children (echo_parts), ==, 2); + g_variant_unref (part); + + echo_part = g_variant_get_child_value (echo_parts, 0); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "message-type", "u", &u); + g_assert_cmpuint (u, ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); + g_variant_unref (echo_part); + + echo_part = g_variant_get_child_value (echo_parts, 1); + g_assert (echo_part != 0); + g_variant_lookup (echo_part, "content", "&s", &s); + g_assert_cmpstr (s, ==, "meows"); + g_variant_unref (echo_part); + + g_variant_unref (echo_parts); g_object_unref (msg); } diff --git a/tests/dbus/text-channel.c b/tests/dbus/text-channel.c index 4be83f1..f2bae6d 100644 --- a/tests/dbus/text-channel.c +++ b/tests/dbus/text-channel.c @@ -800,7 +800,8 @@ test_pending_messages_with_no_sender_id (Test *test, TpMessage *signalled_message; GList *messages; TpContact *sender; - gchar *text; + gchar *text = NULL; + GVariant *part; g_test_bug ("39172"); @@ -814,8 +815,12 @@ test_pending_messages_with_no_sender_id (Test *test, cm_message = tp_cm_message_new_text (test->base_connection, 0, TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "hi mum"); tp_message_set_uint32 (cm_message, 0, "message-sender", test->bob); - g_assert_cmpstr (NULL, ==, - tp_asv_get_string (tp_message_peek (cm_message, 0), "message-sender-id")); + + part = tp_message_dup_part (cm_message, 0); + g_variant_lookup (part, "message-sender-id", "&s", &text); + g_assert_cmpstr (NULL, ==, text); + g_variant_unref (part); + tp_message_mixin_take_received (G_OBJECT (test->chan_service), cm_message); test->wait = 1; diff --git a/tests/lib/echo-chan.c b/tests/lib/echo-chan.c index 6442378..c5a6465 100644 --- a/tests/lib/echo-chan.c +++ b/tests/lib/echo-chan.c @@ -151,7 +151,7 @@ text_send (GObject *object, TpHandle target = tp_base_channel_get_target_handle (TP_BASE_CHANNEL (self)); gchar *echo; gint64 now = time (NULL); - const GHashTable *part; + GVariant *part; const gchar *text; TpMessage *msg; @@ -159,8 +159,9 @@ text_send (GObject *object, * call tp_text_mixin_receive or tp_text_mixin_receive_with_flags * in response to network events */ - part = tp_message_peek (message, 1); - text = tp_asv_get_string (part, "content"); + part = tp_message_dup_part (message, 1); + + g_variant_lookup (part, "content", "&s", &text); switch (type) { @@ -178,6 +179,7 @@ text_send (GObject *object, type, text); echo_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; } + g_variant_unref (part); tp_message_mixin_sent (object, message, 0, "", NULL); -- 1.8.5.3