From c2daaa85b9c84d80e75d5c362ff228c85e11b581 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Aug 2013 18:00:08 +0100 Subject: [PATCH] some tests: give better diagnostics on failure Bug: https://bugs.freedesktop.org/show_bug.cgi?id=67900 Signed-off-by: Simon McVittie --- tests/wocky-porter-test.c | 104 +++++++++++++++++++++++++----------- tests/wocky-test-sasl-auth-server.c | 91 ++++++++++++++++++++++--------- 2 files changed, 139 insertions(+), 56 deletions(-) diff --git a/tests/wocky-porter-test.c b/tests/wocky-porter-test.c index d36bc00..5d40a39 100644 --- a/tests/wocky-porter-test.c +++ b/tests/wocky-porter-test.c @@ -50,6 +50,7 @@ send_stanza_received_cb (GObject *source, GAsyncResult *res, WockyStanza *expected; s = wocky_xmpp_connection_recv_stanza_finish (connection, res, &error); + g_assert_no_error (error); g_assert (s != NULL); expected = g_queue_pop_head (data->expected_stanzas); @@ -78,8 +79,12 @@ static void send_stanza_cb (GObject *source, GAsyncResult *res, gpointer user_data) { test_data_t *data = (test_data_t *) user_data; - g_assert (wocky_porter_send_finish ( - WOCKY_PORTER (source), res, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_porter_send_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); data->outstanding--; g_main_loop_quit (data->loop); @@ -91,12 +96,12 @@ send_stanza_cancelled_cb (GObject *source, GAsyncResult *res, { test_data_t *data = (test_data_t *) user_data; GError *error = NULL; + gboolean ok; - g_assert (!wocky_porter_send_finish ( - WOCKY_PORTER (source), res, &error)); - g_assert (error->domain == G_IO_ERROR); - g_assert (error->code == G_IO_ERROR_CANCELLED); + ok = wocky_porter_send_finish (WOCKY_PORTER (source), res, &error); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED); g_error_free (error); + g_assert (!ok); data->outstanding--; g_main_loop_quit (data->loop); @@ -200,8 +205,12 @@ sched_close_cb (GObject *source, gpointer user_data) { test_data_t *test = (test_data_t *) user_data; - g_assert (wocky_porter_close_finish ( - WOCKY_PORTER (source), res, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_porter_close_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -213,9 +222,13 @@ close_sent_cb (GObject *source, gpointer user_data) { test_data_t *test = (test_data_t *) user_data; + GError *error = NULL; + gboolean ok; - g_assert (wocky_xmpp_connection_send_close_finish ( - WOCKY_XMPP_CONNECTION (source), res, NULL)); + ok = wocky_xmpp_connection_send_close_finish (WOCKY_XMPP_CONNECTION (source), + res, &error); + g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -397,8 +410,12 @@ test_close_sched_close_cb (GObject *source, gpointer user_data) { test_data_t *test = (test_data_t *) user_data; - g_assert (wocky_porter_close_finish ( - WOCKY_PORTER (source), res, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_porter_close_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -573,9 +590,13 @@ test_remote_close_in_close_send_cb (GObject *source, gpointer user_data) { test_data_t *data = (test_data_t *) user_data; + GError *error = NULL; + gboolean ok; - g_assert (wocky_xmpp_connection_send_close_finish ( - WOCKY_XMPP_CONNECTION (source), res, NULL)); + ok = wocky_xmpp_connection_send_close_finish (WOCKY_XMPP_CONNECTION (source), + res, &error); + g_assert_no_error (error); + g_assert (ok); data->outstanding--; g_main_loop_quit (data->loop); @@ -635,10 +656,12 @@ test_close_cancel_force_closed_cb (GObject *source, { test_data_t *test = (test_data_t *) user_data; GError *error = NULL; + gboolean ok; - wocky_porter_force_close_finish ( + ok = wocky_porter_force_close_finish ( WOCKY_PORTER (source), res, &error); g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -826,7 +849,7 @@ test_handler_priority_10 (WockyPorter *porter, wocky_stanza_get_type_info (stanza, NULL, &sub_type); /* This handler is supposed to only handle the get stanza */ - g_assert (sub_type == WOCKY_STANZA_SUB_TYPE_GET); + g_assert_cmpint (sub_type, ==, WOCKY_STANZA_SUB_TYPE_GET); return TRUE; } @@ -1063,7 +1086,7 @@ test_handler_stanza_terminate_cb (WockyPorter *porter, test_expected_stanza_received (test, stanza); id = wocky_node_get_attribute (wocky_stanza_get_top_node (stanza), "id"); - g_assert (!wocky_strdiff (id, "5")); + g_assert_cmpstr (id, ==, "5"); return TRUE; } @@ -1200,10 +1223,13 @@ test_cancel_sent_stanza_cancelled (GObject *source, gpointer user_data) { test_data_t *test = (test_data_t *) user_data; + GError *error = NULL; + gboolean ok; /* Stanza has already be sent to _finish success */ - g_assert (wocky_porter_send_finish ( - WOCKY_PORTER (source), res, NULL)); + ok = wocky_porter_send_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -1289,8 +1315,12 @@ test_send_iq_sent_cb (GObject *source, gpointer user_data) { test_data_t *data = (test_data_t *) user_data; - g_assert (wocky_porter_send_finish ( - WOCKY_PORTER (source), res, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_porter_send_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); data->outstanding--; g_main_loop_quit (data->loop); @@ -1407,9 +1437,11 @@ test_send_iq_reply_cb (GObject *source, { test_data_t *test = (test_data_t *) user_data; WockyStanza *reply; + GError *error = NULL; reply = wocky_porter_send_iq_finish (WOCKY_PORTER (source), - res, NULL); + res, &error); + g_assert_no_error (error); g_assert (reply != NULL); test_expected_stanza_received (test, reply); @@ -2076,7 +2108,7 @@ test_handler_filter_from_juliet_cb (WockyPorter *porter, const gchar *from; from = wocky_stanza_get_from (stanza); - g_assert (!wocky_strdiff (from, "juliet@example.com")); + g_assert_cmpstr (from, ==, "juliet@example.com"); test_expected_stanza_received (test, stanza); return TRUE; @@ -2311,8 +2343,12 @@ test_unref_when_closed_cb (GObject *source, gpointer user_data) { test_data_t *test = (test_data_t *) user_data; - g_assert (wocky_porter_close_finish ( - WOCKY_PORTER (source), res, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_porter_close_finish (WOCKY_PORTER (source), res, &error); + g_assert_no_error (error); + g_assert (ok); /* Porter has been closed, unref it */ g_object_unref (test->session_in); @@ -2492,10 +2528,11 @@ test_stream_error_force_close_cb (GObject *source, { test_data_t *test = (test_data_t *) user_data; GError *error = NULL; + gboolean ok; - wocky_porter_force_close_finish ( - WOCKY_PORTER (source), res, &error); + ok = wocky_porter_force_close_finish (WOCKY_PORTER (source), res, &error); g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -2595,10 +2632,11 @@ test_close_force_force_closed_cb (GObject *source, { test_data_t *test = (test_data_t *) user_data; GError *error = NULL; + gboolean ok; - wocky_porter_force_close_finish ( - WOCKY_PORTER (source), res, &error); + ok = wocky_porter_force_close_finish (WOCKY_PORTER (source), res, &error); g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -3278,9 +3316,11 @@ sent_second_or_third_stanza_cb ( { test_data_t *test = user_data; GError *error = NULL; + gboolean ok; - wocky_porter_send_finish (WOCKY_PORTER (source), result, &error); + ok = wocky_porter_send_finish (WOCKY_PORTER (source), result, &error); g_assert_no_error (error); + g_assert (ok); test->outstanding--; g_main_loop_quit (test->loop); @@ -3295,9 +3335,11 @@ sent_first_stanza_cb ( test_data_t *test = user_data; WockyStanza *third_stanza; GError *error = NULL; + gboolean ok; - wocky_porter_send_finish (WOCKY_PORTER (source), result, &error); + ok = wocky_porter_send_finish (WOCKY_PORTER (source), result, &error); g_assert_no_error (error); + g_assert (ok); third_stanza = wocky_stanza_build (WOCKY_STANZA_TYPE_MESSAGE, WOCKY_STANZA_SUB_TYPE_NONE, NULL, NULL, diff --git a/tests/wocky-test-sasl-auth-server.c b/tests/wocky-test-sasl-auth-server.c index 35c8328..57973bc 100644 --- a/tests/wocky-test-sasl-auth-server.c +++ b/tests/wocky-test-sasl-auth-server.c @@ -195,9 +195,13 @@ features_sent (GObject *source, { TestSaslAuthServer *self = TEST_SASL_AUTH_SERVER (user_data); TestSaslAuthServerPrivate *priv = self->priv; + gboolean ok; + GError *error = NULL; - g_assert (wocky_xmpp_connection_send_stanza_finish ( - WOCKY_XMPP_CONNECTION (source), res, NULL)); + ok = wocky_xmpp_connection_send_stanza_finish ( + WOCKY_XMPP_CONNECTION (source), res, &error); + g_assert_no_error (error); + g_assert (ok); wocky_xmpp_connection_recv_stanza_async (WOCKY_XMPP_CONNECTION (source), priv->cancellable, received_stanza, user_data); @@ -212,9 +216,13 @@ stream_open_sent (GObject *source, TestSaslAuthServer *self = TEST_SASL_AUTH_SERVER(user_data); TestSaslAuthServerPrivate * priv = self->priv; WockyStanza *stanza; + gboolean ok; + GError *error = NULL; - g_assert (wocky_xmpp_connection_send_open_finish ( - WOCKY_XMPP_CONNECTION (source), res, NULL)); + ok = wocky_xmpp_connection_send_open_finish ( + WOCKY_XMPP_CONNECTION (source), res, &error); + g_assert_no_error (error); + g_assert (ok); /* Send stream features */ stanza = wocky_stanza_new ("features", WOCKY_XMPP_NS_STREAM); @@ -233,11 +241,15 @@ stream_open_received (GObject *source, { TestSaslAuthServer *self = TEST_SASL_AUTH_SERVER(user_data); TestSaslAuthServerPrivate * priv = self->priv; + GError *error = NULL; + gboolean ok; - g_assert (wocky_xmpp_connection_recv_open_finish ( + ok = wocky_xmpp_connection_recv_open_finish ( WOCKY_XMPP_CONNECTION (source), res, NULL, NULL, NULL, NULL, NULL, - NULL)); + &error); + g_assert_no_error (error); + g_assert (ok); wocky_xmpp_connection_send_open_async (priv->conn, NULL, "testserver", "1.0", NULL, "0-HA2", @@ -249,8 +261,13 @@ post_auth_close_sent (GObject *source, GAsyncResult *result, gpointer user_data) { - g_assert (wocky_xmpp_connection_send_close_finish ( - WOCKY_XMPP_CONNECTION (source), result, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_xmpp_connection_send_close_finish ( + WOCKY_XMPP_CONNECTION (source), result, &error); + g_assert_no_error (error); + g_assert (ok); } static void @@ -308,8 +325,13 @@ post_auth_features_sent (GObject *source, { TestSaslAuthServer *self = TEST_SASL_AUTH_SERVER(user_data); TestSaslAuthServerPrivate * priv = self->priv; - g_assert (wocky_xmpp_connection_send_stanza_finish ( - WOCKY_XMPP_CONNECTION (source), result, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_xmpp_connection_send_stanza_finish ( + WOCKY_XMPP_CONNECTION (source), result, &error); + g_assert_no_error (error); + g_assert (ok); wocky_xmpp_connection_recv_stanza_async (WOCKY_XMPP_CONNECTION (source), priv->cancellable, post_auth_recv_stanza, user_data); @@ -322,8 +344,13 @@ post_auth_open_sent (GObject *source, { TestSaslAuthServer *tsas = TEST_SASL_AUTH_SERVER (user_data); TestSaslAuthServerPrivate *priv = tsas->priv; - g_assert (wocky_xmpp_connection_send_open_finish ( - WOCKY_XMPP_CONNECTION (source), result, NULL)); + gboolean ok; + GError *error = NULL; + + ok = wocky_xmpp_connection_send_open_finish ( + WOCKY_XMPP_CONNECTION (source), result, &error); + g_assert_no_error (error); + g_assert (ok); /* if our caller wanted control back, hand it back here: */ if (priv->result != NULL) @@ -354,10 +381,15 @@ post_auth_open_received (GObject *source, GAsyncResult *result, gpointer user_data) { - g_assert (wocky_xmpp_connection_recv_open_finish ( + GError *error = NULL; + gboolean ok; + + ok = wocky_xmpp_connection_recv_open_finish ( WOCKY_XMPP_CONNECTION (source), result, NULL, NULL, NULL, NULL, NULL, - user_data)); + &error); + g_assert_no_error (error); + g_assert (ok); wocky_xmpp_connection_send_open_async ( WOCKY_XMPP_CONNECTION (source), NULL, "testserver", "1.0", NULL, "0-HA1", @@ -369,8 +401,13 @@ success_sent (GObject *source, GAsyncResult *result, gpointer user_data) { - g_assert (wocky_xmpp_connection_send_stanza_finish ( - WOCKY_XMPP_CONNECTION (source), result, NULL)); + GError *error = NULL; + gboolean ok; + + ok = wocky_xmpp_connection_send_stanza_finish ( + WOCKY_XMPP_CONNECTION (source), result, &error); + g_assert_no_error (error); + g_assert (ok); wocky_xmpp_connection_reset (WOCKY_XMPP_CONNECTION (source)); @@ -384,7 +421,7 @@ auth_succeeded (TestSaslAuthServer *self, const gchar *challenge) TestSaslAuthServerPrivate *priv = self->priv; WockyStanza *s; - g_assert (priv->state < AUTH_STATE_AUTHENTICATED); + g_assert_cmpint (priv->state, <, AUTH_STATE_AUTHENTICATED); priv->state = AUTH_STATE_AUTHENTICATED; s = wocky_stanza_new ("success", WOCKY_XMPP_NS_SASL_AUTH); @@ -404,10 +441,14 @@ failure_sent (GObject *source, TestSaslAuthServer *tsas = TEST_SASL_AUTH_SERVER (user_data); TestSaslAuthServerPrivate *priv = tsas->priv; GSimpleAsyncResult *r = priv->result; + GError *error = NULL; + gboolean ok; priv->result = NULL; - g_assert (wocky_xmpp_connection_send_stanza_finish ( - WOCKY_XMPP_CONNECTION (source), result, NULL)); + ok = wocky_xmpp_connection_send_stanza_finish ( + WOCKY_XMPP_CONNECTION (source), result, &error); + g_assert_no_error (error); + g_assert (ok); if (r != NULL) { @@ -426,7 +467,7 @@ not_authorized (TestSaslAuthServer *self) TestSaslAuthServerPrivate *priv = self->priv; WockyStanza *s; - g_assert (priv->state < AUTH_STATE_AUTHENTICATED); + g_assert_cmpint (priv->state, <, AUTH_STATE_AUTHENTICATED); priv->state = AUTH_STATE_AUTHENTICATED; s = wocky_stanza_build (WOCKY_STANZA_TYPE_FAILURE, @@ -450,12 +491,12 @@ check_sasl_return (TestSaslAuthServer *self, int ret) { case SASL_BADAUTH: /* Bad password provided */ - g_assert (priv->problem == SERVER_PROBLEM_INVALID_PASSWORD); + g_assert_cmpint (priv->problem, ==, SERVER_PROBLEM_INVALID_PASSWORD); not_authorized (self); return FALSE; case SASL_NOUSER: /* Unknown user */ - g_assert (priv->problem == SERVER_PROBLEM_INVALID_USERNAME); + g_assert_cmpint (priv->problem, ==, SERVER_PROBLEM_INVALID_USERNAME); not_authorized (self); return FALSE; default: @@ -623,7 +664,7 @@ handle_auth (TestSaslAuthServer *self, WockyStanza *stanza) &response_len); } - g_assert (priv->state == AUTH_STATE_STARTED); + g_assert_cmpint (priv->state, ==, AUTH_STATE_STARTED); gjdd = wocky_node_get_attribute_ns (auth, "client-uses-full-bind-result", WOCKY_GOOGLE_NS_AUTH); switch (priv->problem) @@ -664,7 +705,7 @@ handle_auth (TestSaslAuthServer *self, WockyStanza *stanza) #else challenge = ""; challenge_len = 0; - g_assert (!wocky_strdiff ("PLAIN", priv->selected_mech)); + g_assert_cmpstr ("PLAIN", ==, priv->selected_mech); /* response format: ^@ u s e r ^@ p a s s */ /* require at least 1 char user and password */ if (response_len >= 4) @@ -751,7 +792,7 @@ handle_response (TestSaslAuthServer *self, WockyStanza *stanza) return; } - g_assert (priv->state == AUTH_STATE_CHALLENGE); + g_assert_cmpint (priv->state, ==, AUTH_STATE_CHALLENGE); if (wocky_stanza_get_top_node (stanza)->content != NULL) { -- 1.8.4.rc1