From 52ead0b584510765ec9386c43dc8bee3629c936e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 14:02:42 +0000 Subject: [PATCH 2/4] Improve coverage of TpConnectionManager test * test prepare_async in every situation where we previously tested call_when_ready * test is_prepared (CORE) in the same situations * test get_invalidated in the same situations This brings us closer to being able to deprecate call_when_ready and is_ready. --- tests/dbus/cm.c | 158 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 122 insertions(+), 36 deletions(-) diff --git a/tests/dbus/cm.c b/tests/dbus/cm.c index c31f682..bab6051 100644 --- a/tests/dbus/cm.c +++ b/tests/dbus/cm.c @@ -15,6 +15,11 @@ #include "tests/lib/echo-cm.h" #include "tests/lib/util.h" +typedef enum { + ACTIVATE_CM = (1 << 0), + USE_CWR = (1 << 1) +} TestFlags; + typedef struct { GMainLoop *mainloop; TpDBusDaemon *dbus; @@ -736,10 +741,11 @@ ready_or_not (TpConnectionManager *self, static void test_nothing_ready (Test *test, - gconstpointer data G_GNUC_UNUSED) + gconstpointer data) { gchar *name; guint info_source; + TestFlags flags = GPOINTER_TO_INT (data); test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, "nonexistent_cm", @@ -750,15 +756,28 @@ test_nothing_ready (Test *test, g_test_bug ("18291"); - tp_connection_manager_call_when_ready (test->cm, ready_or_not, - test, NULL, NULL); - g_main_loop_run (test->mainloop); - g_assert (test->error != NULL); - g_clear_error (&test->error); + if (flags & USE_CWR) + { + tp_connection_manager_call_when_ready (test->cm, ready_or_not, + test, NULL, NULL); + g_main_loop_run (test->mainloop); + g_assert (test->error != NULL); + g_clear_error (&test->error); + } + else + { + tp_tests_proxy_run_until_prepared_or_failed (test->cm, NULL, + &test->error); + + g_assert_error (test->error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN); + } g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "nonexistent_cm"); g_assert_cmpuint (tp_connection_manager_is_ready (test->cm), ==, FALSE); + g_assert_cmpuint (tp_proxy_is_prepared (test->cm, + TP_CONNECTION_MANAGER_FEATURE_CORE), ==, FALSE); + g_assert (tp_proxy_get_invalidated (test->cm) == NULL); g_assert_cmpuint (tp_connection_manager_is_running (test->cm), ==, FALSE); g_assert_cmpuint (tp_connection_manager_get_info_source (test->cm), ==, TP_CM_INFO_SOURCE_NONE); @@ -774,10 +793,11 @@ test_nothing_ready (Test *test, static void test_file_ready (Test *test, - gconstpointer data G_GNUC_UNUSED) + gconstpointer data) { gchar *name; guint info_source; + TestFlags flags = GPOINTER_TO_INT (data); test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, "spurious", @@ -788,15 +808,25 @@ test_file_ready (Test *test, g_test_bug ("18291"); - tp_connection_manager_call_when_ready (test->cm, ready_or_not, - test, NULL, NULL); - g_main_loop_run (test->mainloop); - g_assert_no_error (test->error); + if (flags & USE_CWR) + { + tp_connection_manager_call_when_ready (test->cm, ready_or_not, + test, NULL, NULL); + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + } + else + { + tp_tests_proxy_run_until_prepared (test->cm, NULL); + } g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "spurious"); g_assert_cmpuint (tp_connection_manager_is_ready (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_is_running (test->cm), ==, FALSE); + g_assert_cmpuint (tp_proxy_is_prepared (test->cm, + TP_CONNECTION_MANAGER_FEATURE_CORE), ==, TRUE); + g_assert (tp_proxy_get_invalidated (test->cm) == NULL); g_assert_cmpuint (tp_connection_manager_get_info_source (test->cm), ==, TP_CM_INFO_SOURCE_FILE); @@ -812,10 +842,11 @@ test_file_ready (Test *test, static void test_complex_file_ready (Test *test, - gconstpointer data G_GNUC_UNUSED) + gconstpointer data) { gchar *name; guint info_source; + TestFlags flags = GPOINTER_TO_INT (data); test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, "test_manager_file", @@ -826,13 +857,23 @@ test_complex_file_ready (Test *test, g_test_bug ("18291"); - tp_connection_manager_call_when_ready (test->cm, ready_or_not, - test, NULL, NULL); - g_main_loop_run (test->mainloop); - g_assert_no_error (test->error); + if (flags & USE_CWR) + { + tp_connection_manager_call_when_ready (test->cm, ready_or_not, + test, NULL, NULL); + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + } + else + { + tp_tests_proxy_run_until_prepared (test->cm, NULL); + } g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "test_manager_file"); + g_assert_cmpuint (tp_proxy_is_prepared (test->cm, + TP_CONNECTION_MANAGER_FEATURE_CORE), ==, TRUE); + g_assert (tp_proxy_get_invalidated (test->cm) == NULL); g_assert_cmpuint (tp_connection_manager_is_ready (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_is_running (test->cm), ==, FALSE); g_assert_cmpuint (tp_connection_manager_get_info_source (test->cm), ==, @@ -860,7 +901,7 @@ test_dbus_ready (Test *test, { gchar *name; guint info_source; - const gboolean activate = GPOINTER_TO_INT (data); + const TestFlags flags = GPOINTER_TO_INT (data); test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, @@ -870,7 +911,7 @@ test_dbus_ready (Test *test, g_assert_no_error (test->error); g_test_queue_unref (test->cm); - if (activate) + if (flags & ACTIVATE_CM) { g_test_bug ("23524"); @@ -887,13 +928,23 @@ test_dbus_ready (Test *test, g_test_bug ("18291"); } - tp_connection_manager_call_when_ready (test->cm, ready_or_not, - test, NULL, NULL); - g_main_loop_run (test->mainloop); - g_assert_no_error (test->error); + if (flags & USE_CWR) + { + tp_connection_manager_call_when_ready (test->cm, ready_or_not, + test, NULL, NULL); + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + } + else + { + tp_tests_proxy_run_until_prepared (test->cm, NULL); + } g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "example_echo"); + g_assert_cmpuint (tp_proxy_is_prepared (test->cm, + TP_CONNECTION_MANAGER_FEATURE_CORE), ==, TRUE); + g_assert (tp_proxy_get_invalidated (test->cm) == NULL); g_assert_cmpuint (tp_connection_manager_is_ready (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_is_running (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_get_info_source (test->cm), ==, @@ -914,7 +965,7 @@ test_dbus_fallback (Test *test, { gchar *name; guint info_source; - const gboolean activate = GPOINTER_TO_INT (data); + const TestFlags flags = GPOINTER_TO_INT (data); TpBaseConnectionManager *service_cm_as_base; gboolean ok; @@ -939,7 +990,7 @@ test_dbus_fallback (Test *test, g_assert_no_error (test->error); g_test_queue_unref (test->cm); - if (activate) + if (flags & ACTIVATE_CM) { g_test_bug ("23524"); @@ -956,13 +1007,23 @@ test_dbus_fallback (Test *test, g_test_bug ("18291"); } - tp_connection_manager_call_when_ready (test->cm, ready_or_not, - test, NULL, NULL); - g_main_loop_run (test->mainloop); - g_assert_no_error (test->error); + if (flags & USE_CWR) + { + tp_connection_manager_call_when_ready (test->cm, ready_or_not, + test, NULL, NULL); + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + } + else + { + tp_tests_proxy_run_until_prepared (test->cm, NULL); + } g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "example_echo"); + g_assert_cmpuint (tp_proxy_is_prepared (test->cm, + TP_CONNECTION_MANAGER_FEATURE_CORE), ==, TRUE); + g_assert (tp_proxy_get_invalidated (test->cm) == NULL); g_assert_cmpuint (tp_connection_manager_is_ready (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_is_running (test->cm), ==, TRUE); g_assert_cmpuint (tp_connection_manager_get_info_source (test->cm), ==, @@ -1005,6 +1066,13 @@ on_listed_connection_managers (TpConnectionManager * const * cms, g_assert (tp_connection_manager_is_running (echo)); g_assert (!tp_connection_manager_is_running (spurious)); + g_assert (tp_proxy_is_prepared (echo, TP_CONNECTION_MANAGER_FEATURE_CORE)); + g_assert (tp_proxy_is_prepared (spurious, + TP_CONNECTION_MANAGER_FEATURE_CORE)); + + g_assert (tp_proxy_get_invalidated (echo) == NULL); + g_assert (tp_proxy_get_invalidated (spurious) == NULL); + g_assert (tp_connection_manager_is_ready (echo)); g_assert (tp_connection_manager_is_ready (spurious)); @@ -1045,18 +1113,36 @@ main (int argc, g_test_add ("/cm/dbus (old)", Test, NULL, setup, test_dbus_got_info, teardown); - g_test_add ("/cm/nothing", Test, NULL, setup, test_nothing_ready, - teardown); - g_test_add ("/cm/file", Test, NULL, setup, test_file_ready, teardown); - g_test_add ("/cm/file (complex)", Test, NULL, setup, + g_test_add ("/cm/nothing", Test, GINT_TO_POINTER (0), + setup, test_nothing_ready, teardown); + g_test_add ("/cm/nothing/cwr", Test, GINT_TO_POINTER (USE_CWR), + setup, test_nothing_ready, teardown); + g_test_add ("/cm/file", Test, GINT_TO_POINTER (0), + setup, test_file_ready, teardown); + g_test_add ("/cm/file/cwr", Test, GINT_TO_POINTER (USE_CWR), + setup, test_file_ready, teardown); + g_test_add ("/cm/file/complex", Test, GINT_TO_POINTER (0), setup, test_complex_file_ready, teardown); - g_test_add ("/cm/dbus", Test, GINT_TO_POINTER (FALSE), setup, + g_test_add ("/cm/file/complex/cwr", Test, GINT_TO_POINTER (USE_CWR), setup, + test_complex_file_ready, teardown); + g_test_add ("/cm/dbus", Test, GINT_TO_POINTER (0), setup, test_dbus_ready, teardown); - g_test_add ("/cm/dbus-and-activate", Test, GINT_TO_POINTER (TRUE), setup, + g_test_add ("/cm/dbus/cwr", Test, GINT_TO_POINTER (USE_CWR), setup, test_dbus_ready, teardown); - g_test_add ("/cm/dbus-fallback", Test, GINT_TO_POINTER (FALSE), setup, + g_test_add ("/cm/dbus/activate", Test, GINT_TO_POINTER (ACTIVATE_CM), + setup, test_dbus_ready, teardown); + g_test_add ("/cm/dbus/activate/cwr", Test, + GINT_TO_POINTER (USE_CWR|ACTIVATE_CM), + setup, test_dbus_ready, teardown); + g_test_add ("/cm/dbus-fallback", Test, GINT_TO_POINTER (0), setup, + test_dbus_fallback, teardown); + g_test_add ("/cm/dbus-fallback/cwr", Test, GINT_TO_POINTER (USE_CWR), setup, test_dbus_fallback, teardown); - g_test_add ("/cm/dbus-fallback-activate", Test, GINT_TO_POINTER (TRUE), + g_test_add ("/cm/dbus-fallback/activate", Test, + GINT_TO_POINTER (ACTIVATE_CM), + setup, test_dbus_fallback, teardown); + g_test_add ("/cm/dbus-fallback/activate/cwr", Test, + GINT_TO_POINTER (ACTIVATE_CM | USE_CWR), setup, test_dbus_fallback, teardown); g_test_add ("/cm/list", Test, NULL, setup, test_list, teardown); -- 1.7.9.1