80
96
gconstpointer data)
82
98
test->mainloop = g_main_loop_new (NULL, FALSE);
83
test->dbus = tp_dbus_daemon_dup (NULL);
99
test->dbus = test_dbus_daemon_dup_or_die ();
84
100
g_assert (test->dbus != NULL);
86
102
test->account = NULL;
104
test->times_notified = g_hash_table_new_full (g_str_hash, g_str_equal,
109
setup_service (Test *test,
114
tp_dbus_daemon_request_name (test->dbus,
115
TP_ACCOUNT_MANAGER_BUS_NAME, FALSE, &test->error);
116
g_assert_no_error (test->error);
118
tp_dbus_daemon_request_name (test->dbus,
119
CONN1_BUS_NAME, FALSE, &test->error);
120
g_assert_no_error (test->error);
122
tp_dbus_daemon_request_name (test->dbus,
123
CONN2_BUS_NAME, FALSE, &test->error);
124
g_assert_no_error (test->error);
126
test->account_service = g_object_new (SIMPLE_TYPE_ACCOUNT, NULL);
127
tp_dbus_daemon_register_object (test->dbus, ACCOUNT_PATH,
128
test->account_service);
132
test_get_times_notified (Test *test,
133
const gchar *property)
135
return GPOINTER_TO_UINT (g_hash_table_lookup (test->times_notified,
140
test_notify_cb (Test *test,
144
guint counter = test_get_times_notified (test, pspec->name);
146
g_hash_table_insert (test->times_notified, g_strdup (pspec->name),
147
GUINT_TO_POINTER (++counter));
151
test_set_up_account_notify (Test *test)
153
g_assert (test->account != NULL);
155
g_hash_table_remove_all (test->times_notified);
157
if (test->notify_id != 0)
159
g_signal_handler_disconnect (test->account, test->notify_id);
162
test->notify_id = g_signal_connect_swapped (test->account, "notify",
163
G_CALLBACK (test_notify_cb), test);
119
231
g_assert (test->account != NULL);
235
account_prepare_cb (GObject *source,
236
GAsyncResult *result,
239
Test *test = user_data;
240
GError *error = NULL;
242
tp_proxy_prepare_finish (source, result, &error);
243
g_assert_no_error (error);
245
g_main_loop_quit (test->mainloop);
249
test_prepare_success (Test *test,
250
gconstpointer data G_GNUC_UNUSED)
252
GQuark account_features[] = { TP_ACCOUNT_FEATURE_CORE, 0 };
253
TpConnectionStatusReason reason;
254
gchar *status = NULL;
255
gchar *message = NULL;
257
test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL);
258
g_assert (test->account != NULL);
260
tp_proxy_prepare_async (test->account, account_features,
261
account_prepare_cb, test);
262
g_main_loop_run (test->mainloop);
264
/* the obvious accessors */
265
g_assert (tp_account_is_prepared (test->account, TP_ACCOUNT_FEATURE_CORE));
266
g_assert (tp_account_is_enabled (test->account));
267
g_assert (tp_account_is_valid (test->account));
268
g_assert_cmpstr (tp_account_get_display_name (test->account), ==,
270
g_assert_cmpstr (tp_account_get_nickname (test->account), ==, "badger");
271
g_assert_cmpuint (tp_asv_size (tp_account_get_parameters (test->account)),
273
g_assert (!tp_account_get_connect_automatically (test->account));
274
g_assert (tp_account_get_has_been_online (test->account));
275
g_assert_cmpint (tp_account_get_connection_status (test->account, NULL),
276
==, TP_CONNECTION_STATUS_CONNECTED);
277
g_assert_cmpint (tp_account_get_connection_status (test->account, &reason),
278
==, TP_CONNECTION_STATUS_CONNECTED);
279
g_assert_cmpint (reason, ==, TP_CONNECTION_STATUS_REASON_REQUESTED);
281
/* the CM and protocol come from the object path */
282
g_assert_cmpstr (tp_account_get_connection_manager (test->account),
284
g_assert_cmpstr (tp_account_get_protocol (test->account), ==, "ev");
286
/* the icon name in SimpleAccount is "", so we guess based on the protocol */
287
g_assert_cmpstr (tp_account_get_icon_name (test->account), ==, "im-ev");
289
/* RequestedPresence is (Available, "available", "") */
290
g_assert_cmpint (tp_account_get_requested_presence (test->account, NULL,
291
NULL), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
292
g_assert_cmpint (tp_account_get_requested_presence (test->account, &status,
293
NULL), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
294
g_assert_cmpstr (status, ==, "available");
296
g_assert_cmpint (tp_account_get_requested_presence (test->account, NULL,
297
&message), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
298
g_assert_cmpstr (message, ==, "");
301
/* CurrentPresence is the same as RequestedPresence */
302
g_assert_cmpint (tp_account_get_current_presence (test->account, NULL,
303
NULL), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
304
g_assert_cmpint (tp_account_get_current_presence (test->account, &status,
305
NULL), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
306
g_assert_cmpstr (status, ==, "available");
308
g_assert_cmpint (tp_account_get_current_presence (test->account, NULL,
309
&message), ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
310
g_assert_cmpstr (message, ==, "");
313
/* NormalizedName and AutomaticPresence aren't available yet */
317
test_connection (Test *test,
318
gconstpointer data G_GNUC_UNUSED)
320
GQuark account_features[] = { TP_ACCOUNT_FEATURE_CORE, 0 };
321
GHashTable *change = tp_asv_new (NULL, NULL);
324
test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL);
325
g_assert (test->account != NULL);
327
tp_proxy_prepare_async (test->account, account_features,
328
account_prepare_cb, test);
329
g_main_loop_run (test->mainloop);
331
g_assert (tp_account_is_prepared (test->account, TP_ACCOUNT_FEATURE_CORE));
333
/* a connection turns up */
335
test_set_up_account_notify (test);
336
tp_asv_set_object_path (change, "Connection", CONN1_PATH);
337
tp_asv_set_uint32 (change, "ConnectionStatus",
338
TP_CONNECTION_STATUS_CONNECTING);
339
tp_asv_set_uint32 (change, "ConnectionStatusReason",
340
TP_CONNECTION_STATUS_REASON_REQUESTED);
341
tp_svc_account_emit_account_property_changed (test->account_service, change);
342
g_hash_table_remove_all (change);
344
while (test_get_times_notified (test, "connection") < 1)
345
g_main_context_iteration (NULL, TRUE);
347
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
348
conn = tp_account_get_connection (test->account);
349
g_assert_cmpstr (tp_proxy_get_object_path (conn), ==, CONN1_PATH);
350
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
352
/* ensure the same connection - no change notification */
354
test_set_up_account_notify (test);
355
conn = tp_account_ensure_connection (test->account, CONN1_PATH);
356
g_assert_cmpstr (tp_proxy_get_object_path (conn), ==, CONN1_PATH);
357
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 0);
359
/* a no-op "change" */
361
test_set_up_account_notify (test);
362
tp_asv_set_object_path (change, "Connection", CONN1_PATH);
363
tp_asv_set_uint32 (change, "ConnectionStatus",
364
TP_CONNECTION_STATUS_CONNECTING);
365
tp_asv_set_uint32 (change, "ConnectionStatusReason",
366
TP_CONNECTION_STATUS_REASON_REQUESTED);
367
tp_svc_account_emit_account_property_changed (test->account_service, change);
368
g_hash_table_remove_all (change);
370
test_proxy_run_until_dbus_queue_processed (test->account);
372
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 0);
373
conn = tp_account_get_connection (test->account);
374
g_assert_cmpstr (tp_proxy_get_object_path (conn), ==, CONN1_PATH);
375
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 0);
377
/* atomically flip from one connection to another (unlikely) */
379
test_set_up_account_notify (test);
380
tp_asv_set_object_path (change, "Connection", CONN2_PATH);
381
tp_asv_set_uint32 (change, "ConnectionStatus",
382
TP_CONNECTION_STATUS_CONNECTED);
383
tp_asv_set_uint32 (change, "ConnectionStatusReason",
384
TP_CONNECTION_STATUS_REASON_REQUESTED);
385
tp_svc_account_emit_account_property_changed (test->account_service, change);
386
g_hash_table_remove_all (change);
388
while (test_get_times_notified (test, "connection") < 1)
389
g_main_context_iteration (NULL, TRUE);
391
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
392
conn = tp_account_get_connection (test->account);
393
g_assert_cmpstr (tp_proxy_get_object_path (conn), ==, CONN2_PATH);
394
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
396
/* no more connection for you */
398
test_set_up_account_notify (test);
399
tp_asv_set_object_path (change, "Connection", "/");
400
tp_asv_set_uint32 (change, "ConnectionStatus",
401
TP_CONNECTION_STATUS_DISCONNECTED);
402
tp_asv_set_uint32 (change, "ConnectionStatusReason",
403
TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR);
404
tp_svc_account_emit_account_property_changed (test->account_service, change);
405
g_hash_table_remove_all (change);
407
while (test_get_times_notified (test, "connection") < 1)
408
g_main_context_iteration (NULL, TRUE);
410
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
411
conn = tp_account_get_connection (test->account);
412
g_assert (conn == NULL);
414
/* staple on a Connection (this is intended for use in e.g. observers,
415
* if they're told about a Connection that the Account hasn't told them
418
test_set_up_account_notify (test);
419
conn = tp_account_ensure_connection (test->account, CONN1_PATH);
420
g_assert_cmpstr (tp_proxy_get_object_path (conn), ==, CONN1_PATH);
421
g_assert_cmpuint (test_get_times_notified (test, "connection"), ==, 1);
423
g_hash_table_destroy (change);