summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-18 15:12:04 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-05-12 12:30:41 +0200
commit515abe51c6248a0a862be1b5073d3a6975d58e9b (patch)
tree10cb7ada7aa89f0640ae0709992d56e5dce44be7
parente3761c4c807b66b8e9a4408f51c81fd4fd4a8248 (diff)
test prepare_before_signalling_connected_async
-rw-r--r--tests/dbus/proxy-preparation.c94
-rw-r--r--tests/lib/my-conn-proxy.c61
-rw-r--r--tests/lib/my-conn-proxy.h15
3 files changed, 164 insertions, 6 deletions
diff --git a/tests/dbus/proxy-preparation.c b/tests/dbus/proxy-preparation.c
index 7b6f0d96..c3139854 100644
--- a/tests/dbus/proxy-preparation.c
+++ b/tests/dbus/proxy-preparation.c
@@ -50,6 +50,19 @@ setup (Test *test,
}
static void
+disconnect_and_destroy_conn (Test *test)
+{
+ tp_cli_connection_run_disconnect (TP_CONNECTION (test->my_conn), -1,
+ &test->error, NULL);
+ g_assert_no_error (test->error);
+
+ tp_clear_object (&test->connection);
+ tp_clear_object (&test->base_connection);
+ tp_clear_object (&test->my_conn);
+
+}
+
+static void
teardown (Test *test,
gconstpointer data)
{
@@ -59,12 +72,7 @@ teardown (Test *test,
g_main_loop_unref (test->mainloop);
test->mainloop = NULL;
- tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL);
- g_assert_no_error (test->error);
-
- g_object_unref (test->connection);
- g_object_unref (test->base_connection);
- g_object_unref (test->my_conn);
+ disconnect_and_destroy_conn (test);
}
static void
@@ -286,6 +294,78 @@ test_retry_dep (Test *test,
TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY_DEP));
}
+static void
+recreate_connection (Test *test)
+{
+ gchar *name;
+ gchar *conn_path;
+
+ disconnect_and_destroy_conn (test);
+
+ test->base_connection = tp_tests_object_new_static_class (
+ TP_TESTS_TYPE_SIMPLE_CONNECTION,
+ "account", "me@test.com",
+ "protocol", "simple",
+ NULL);
+ g_assert (test->base_connection != NULL);
+
+ g_assert (tp_base_connection_register (test->base_connection, "simple",
+ &name, &conn_path, &test->error));
+ g_assert_no_error (test->error);
+
+ test->connection = tp_connection_new (test->dbus, name, conn_path,
+ &test->error);
+ g_assert_no_error (test->error);
+
+ test->my_conn = g_object_new (TP_TESTS_TYPE_MY_CONN_PROXY,
+ "dbus-daemon", test->dbus,
+ "bus-name", tp_proxy_get_bus_name (test->connection),
+ "object-path", tp_proxy_get_object_path (test->connection),
+ NULL);
+ g_assert (test->my_conn != NULL);
+
+ g_free (name);
+ g_free (conn_path);
+}
+
+static void
+test_before_connected (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ GQuark features[] = { TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED, 0 };
+ GQuark connected[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
+
+ /* We need a not yet connected connection */
+ recreate_connection (test);
+
+ g_assert_cmpuint (test->my_conn->before_connected_state, ==,
+ BEFORE_CONNECTED_STATE_UNPREPARED);
+
+ /* Connection is not yet connected, prepare the feature */
+ tp_proxy_prepare_async (test->my_conn, features, prepare_cb, test);
+
+ g_main_loop_run (test->mainloop);
+ g_assert_no_error (test->error);
+
+ g_assert (tp_proxy_is_prepared (test->my_conn,
+ TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED));
+
+ g_assert_cmpuint (test->my_conn->before_connected_state, ==,
+ BEFORE_CONNECTED_STATE_NOT_CONNECTED);
+
+ tp_cli_connection_call_connect (test->connection, -1, NULL, NULL, NULL, NULL);
+
+ /* Wait that CONNECTED is announced */
+ tp_proxy_prepare_async (test->my_conn, connected, prepare_cb, test);
+
+ g_main_loop_run (test->mainloop);
+ g_assert_no_error (test->error);
+
+ /* state has been updated */
+ g_assert_cmpuint (test->my_conn->before_connected_state, ==,
+ BEFORE_CONNECTED_STATE_CONNECTED);
+}
+
int
main (int argc,
char **argv)
@@ -315,6 +395,8 @@ main (int argc,
test_retry, teardown);
g_test_add ("/proxy-preparation/retry-dep", Test, NULL, setup,
test_retry_dep, teardown);
+ g_test_add ("/proxy-preparation/before-connected", Test, NULL, setup,
+ test_before_connected, teardown);
return g_test_run ();
}
diff --git a/tests/lib/my-conn-proxy.c b/tests/lib/my-conn-proxy.c
index 765688b6..69045d77 100644
--- a/tests/lib/my-conn-proxy.c
+++ b/tests/lib/my-conn-proxy.c
@@ -31,6 +31,7 @@ enum {
FEAT_FAIL_DEP,
FEAT_RETRY,
FEAT_RETRY_DEP,
+ FEAT_BEFORE_CONNECTED,
N_FEAT
};
@@ -154,6 +155,53 @@ prepare_retry_dep_async (TpProxy *proxy,
g_object_unref (result);
}
+static void
+prepare_before_connected_async (TpProxy *proxy,
+ const TpProxyFeature *feature,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy;
+ GSimpleAsyncResult *result;
+
+ g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE));
+
+ result = g_simple_async_result_new ((GObject *) proxy, callback, user_data,
+ prepare_before_connected_async);
+
+ if (tp_connection_get_status (TP_CONNECTION (self), NULL) ==
+ TP_CONNECTION_STATUS_CONNECTED)
+ self->before_connected_state = BEFORE_CONNECTED_STATE_CONNECTED;
+ else
+ self->before_connected_state = BEFORE_CONNECTED_STATE_NOT_CONNECTED;
+
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+static void
+prepare_before_connected_before_async (TpProxy *proxy,
+ const TpProxyFeature *feature,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy;
+ GSimpleAsyncResult *result;
+
+ g_assert (tp_proxy_is_prepared (proxy, TP_TESTS_MY_CONN_PROXY_FEATURE_CORE));
+
+ g_assert_cmpuint (tp_connection_get_status (TP_CONNECTION (proxy), NULL), ==,
+ TP_CONNECTION_STATUS_CONNECTING);
+
+ result = g_simple_async_result_new ((GObject *) proxy, callback, user_data,
+ prepare_before_connected_before_async);
+
+ self->before_connected_state = BEFORE_CONNECTED_STATE_CONNECTED;
+
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
static const TpProxyFeature *
list_features (TpProxyClass *cls G_GNUC_UNUSED)
{
@@ -211,6 +259,13 @@ list_features (TpProxyClass *cls G_GNUC_UNUSED)
features[FEAT_RETRY_DEP].prepare_async = prepare_retry_dep_async;
features[FEAT_RETRY_DEP].depends_on = need_retry;
+ features[FEAT_BEFORE_CONNECTED].name =
+ TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED;
+ features[FEAT_BEFORE_CONNECTED].prepare_async =
+ prepare_before_connected_async;
+ features[FEAT_BEFORE_CONNECTED].prepare_before_signalling_connected_async =
+ prepare_before_connected_before_async;
+
return features;
}
@@ -275,3 +330,9 @@ tp_tests_my_conn_proxy_get_feature_quark_retry_dep (void)
{
return g_quark_from_static_string ("tp-my-conn-proxy-feature-retry-dep");
}
+
+GQuark
+tp_tests_my_conn_proxy_get_feature_quark_before_connected (void)
+{
+ return g_quark_from_static_string ("tp-my-conn-proxy-feature-before-connected");
+}
diff --git a/tests/lib/my-conn-proxy.h b/tests/lib/my-conn-proxy.h
index cc5505b9..cfc82160 100644
--- a/tests/lib/my-conn-proxy.h
+++ b/tests/lib/my-conn-proxy.h
@@ -25,10 +25,19 @@ struct _TpTestsMyConnProxyClass {
TpConnectionClass parent_class;
};
+typedef enum
+{
+ BEFORE_CONNECTED_STATE_UNPREPARED = 0,
+ BEFORE_CONNECTED_STATE_NOT_CONNECTED,
+ BEFORE_CONNECTED_STATE_CONNECTED,
+} TpTestsMyConnProxyBeforeConnectedState;
+
+
struct _TpTestsMyConnProxy {
TpConnection parent;
gboolean retry_feature_success;
+ TpTestsMyConnProxyBeforeConnectedState before_connected_state;
};
GType tp_tests_my_conn_proxy_get_type (void);
@@ -95,6 +104,12 @@ GQuark tp_tests_my_conn_proxy_get_feature_quark_retry (void) G_GNUC_CONST;
(tp_tests_my_conn_proxy_get_feature_quark_retry_dep ())
GQuark tp_tests_my_conn_proxy_get_feature_quark_retry_dep (void) G_GNUC_CONST;
+/* Can be prepared before the connection is connected and block announcing the
+ * connected state */
+#define TP_TESTS_MY_CONN_PROXY_FEATURE_BEFORE_CONNECTED \
+ (tp_tests_my_conn_proxy_get_feature_quark_before_connected ())
+GQuark tp_tests_my_conn_proxy_get_feature_quark_before_connected (void) G_GNUC_CONST;
+
G_END_DECLS
#endif /* #ifndef __TP_TESTS_MY_CONN_PROXY_H__ */