diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-04-16 22:12:53 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-04-17 12:38:14 +0200 |
commit | ded205c7dd94ee87c03e5fc55e7955a6c2b570d9 (patch) | |
tree | cf1095f670e0ad879f568be86ece642ab4f4e5fa | |
parent | bb1105761f7a42179a670485d3d910ba033e2ca9 (diff) |
Add unit test for tp_capabilities_supports_audio(_video)_call()
-rw-r--r-- | tests/capabilities.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/tests/capabilities.c b/tests/capabilities.c index f05964c25..7b82195d8 100644 --- a/tests/capabilities.c +++ b/tests/capabilities.c @@ -754,6 +754,172 @@ test_supports_sms (Test *test, g_object_unref (caps); } +static void +add_call_class (GPtrArray *classes, + TpHandleType handle_type, + gboolean initial_audio, + gboolean initial_video, + gboolean use_allowed, + gboolean add_extra_fixed) +{ + GHashTable *fixed; + GPtrArray *allowed; + GValueArray *arr; + + fixed = tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_CALL, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, + handle_type, + NULL); + + allowed = g_ptr_array_new (); + + if (initial_audio) + { + if (use_allowed) + { + g_ptr_array_add (allowed, TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO); + } + else + { + tp_asv_set_boolean (fixed, TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, + TRUE); + } + } + + if (initial_video) + { + if (use_allowed) + { + g_ptr_array_add (allowed, TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO); + } + else + { + tp_asv_set_boolean (fixed, TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, + TRUE); + } + } + + g_ptr_array_add (allowed, NULL); + + if (add_extra_fixed) + tp_asv_set_boolean (fixed, "ExtraBadgersRequired", TRUE); + + arr = tp_value_array_build (2, + TP_HASH_TYPE_STRING_VARIANT_MAP, fixed, + G_TYPE_STRV, allowed->pdata, + G_TYPE_INVALID); + + g_hash_table_unref (fixed); + g_ptr_array_unref (allowed); + + g_ptr_array_add (classes, arr); +} + +static void +test_supports_call (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + TpCapabilities *caps; + GPtrArray *classes; + + /* A class with no audio/video can't do anything */ + classes = g_ptr_array_sized_new (1); + add_call_class (classes, TP_HANDLE_TYPE_CONTACT, FALSE, FALSE, FALSE, FALSE); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (!tp_capabilities_supports_audio_call (caps, + TP_HANDLE_TYPE_CONTACT)); + g_assert (!tp_capabilities_supports_audio_video_call (caps, + TP_HANDLE_TYPE_CONTACT)); + + g_object_unref (caps); + + /* A class with only audio can't do audio_video */ + classes = g_ptr_array_sized_new (1); + add_call_class (classes, TP_HANDLE_TYPE_CONTACT, TRUE, FALSE, FALSE, FALSE); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (tp_capabilities_supports_audio_call (caps, + TP_HANDLE_TYPE_CONTACT)); + g_assert (!tp_capabilities_supports_audio_video_call (caps, + TP_HANDLE_TYPE_CONTACT)); + + g_object_unref (caps); + + /* A class with audio and video in fixed can't do audio only */ + classes = g_ptr_array_sized_new (1); + add_call_class (classes, TP_HANDLE_TYPE_CONTACT, TRUE, TRUE, FALSE, FALSE); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (!tp_capabilities_supports_audio_call (caps, + TP_HANDLE_TYPE_CONTACT)); + g_assert (tp_capabilities_supports_audio_video_call (caps, + TP_HANDLE_TYPE_CONTACT)); + + g_object_unref (caps); + + /* A class with audio and video in allowed can do audio only */ + classes = g_ptr_array_sized_new (1); + add_call_class (classes, TP_HANDLE_TYPE_CONTACT, TRUE, TRUE, TRUE, FALSE); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (tp_capabilities_supports_audio_call (caps, + TP_HANDLE_TYPE_CONTACT)); + g_assert (tp_capabilities_supports_audio_video_call (caps, + TP_HANDLE_TYPE_CONTACT)); + + g_object_unref (caps); + + /* A class with unknown extra fixed can't do anything */ + classes = g_ptr_array_sized_new (1); + add_call_class (classes, TP_HANDLE_TYPE_CONTACT, TRUE, TRUE, TRUE, TRUE); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (!tp_capabilities_supports_audio_call (caps, + TP_HANDLE_TYPE_CONTACT)); + g_assert (!tp_capabilities_supports_audio_video_call (caps, + TP_HANDLE_TYPE_CONTACT)); + + g_object_unref (caps); +} + int main (int argc, char **argv) @@ -773,6 +939,8 @@ main (int argc, test_supports_room_list, NULL); g_test_add (TEST_PREFIX "supports/sms", Test, NULL, setup, test_supports_sms, NULL); + g_test_add (TEST_PREFIX "supports/call", Test, NULL, setup, + test_supports_call, NULL); return g_test_run (); } |