libpurple/tests/test_protocol_conversation.c

changeset 42354
b5caf6b7705a
parent 42332
0de4f569ccf3
child 42368
2630a8a2d64d
equal deleted inserted replaced
42353:5381c5c9affa 42354:b5caf6b7705a
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. 20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 */ 21 */
22 22
23 #include <glib.h> 23 #include <glib.h>
24 24
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26
25 #include <purple.h> 27 #include <purple.h>
26 28
27 #include "test_ui.h" 29 #include "test_ui.h"
28 30
29 /****************************************************************************** 31 /******************************************************************************
199 201
200 g_test_trap_subprocess(NULL, 0, 0); 202 g_test_trap_subprocess(NULL, 0, 0);
201 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*set_topic_finish*"); 203 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*set_topic_finish*");
202 } 204 }
203 205
204
205 static void 206 static void
206 test_purple_protocol_conversation_empty_get_channel_join_details(void) { 207 test_purple_protocol_conversation_empty_get_channel_join_details(void) {
207 if(g_test_subprocess()) { 208 if(g_test_subprocess()) {
208 PurpleAccount *account = NULL; 209 PurpleAccount *account = NULL;
209 PurpleChannelJoinDetails *result = NULL; 210 PurpleChannelJoinDetails *result = NULL;
276 277
277 g_test_trap_subprocess(NULL, 0, 0); 278 g_test_trap_subprocess(NULL, 0, 0);
278 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*join_channel_finish*"); 279 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*join_channel_finish*");
279 } 280 }
280 281
282 static void
283 test_purple_protocol_conversation_empty_set_avatar_async(void) {
284 if(g_test_subprocess()) {
285 PurpleAccount *account = NULL;
286 PurpleConversation *conversation = NULL;
287 PurpleProtocolConversation *protocol = NULL;
288
289 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(),
290 NULL);
291 account = purple_account_new("test", "test");
292 conversation = g_object_new(
293 PURPLE_TYPE_CONVERSATION,
294 "account", account,
295 "name", "this is required at the moment",
296 "type", PurpleConversationTypeDM,
297 NULL);
298
299 purple_protocol_conversation_set_avatar_async(protocol, conversation,
300 NULL, NULL, NULL, NULL);
301
302 g_clear_object(&account);
303 g_clear_object(&conversation);
304 g_clear_object(&protocol);
305 }
306
307 g_test_trap_subprocess(NULL, 0, 0);
308 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*set_avatar_async*");
309 }
310
311 static void
312 test_purple_protocol_conversation_empty_set_avatar_finish(void) {
313 if(g_test_subprocess()) {
314 PurpleProtocolConversation *protocol = NULL;
315 GError *error = NULL;
316 GTask *task = NULL;
317 gboolean result = FALSE;
318
319 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(),
320 NULL);
321
322 task = g_task_new(protocol, NULL, NULL, NULL);
323
324 result = purple_protocol_conversation_set_avatar_finish(protocol,
325 G_ASYNC_RESULT(task),
326 &error);
327 g_assert_no_error(error);
328 g_assert_false(result);
329
330 g_clear_object(&task);
331 g_clear_object(&protocol);
332 }
333
334 g_test_trap_subprocess(NULL, 0, 0);
335 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*set_avatar_finish*");
336 }
337
281 /****************************************************************************** 338 /******************************************************************************
282 * TestProtocolConversation Implementation 339 * TestProtocolConversation Implementation
283 *****************************************************************************/ 340 *****************************************************************************/
284 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation, 341 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation,
285 test_purple_protocol_conversation, TEST_PURPLE, 342 test_purple_protocol_conversation, TEST_PURPLE,
297 guint set_topic_finish; 354 guint set_topic_finish;
298 355
299 guint get_channel_join_details; 356 guint get_channel_join_details;
300 guint join_channel_async; 357 guint join_channel_async;
301 guint join_channel_finish; 358 guint join_channel_finish;
359
360 guint set_avatar_async;
361 guint set_avatar_finish;
302 }; 362 };
303 363
304 static void 364 static void
305 test_purple_protocol_conversation_send_message_async(PurpleProtocolConversation *protocol, 365 test_purple_protocol_conversation_send_message_async(PurpleProtocolConversation *protocol,
306 PurpleConversation *conversation, 366 PurpleConversation *conversation,
440 test_protocol->set_topic_finish += 1; 500 test_protocol->set_topic_finish += 1;
441 501
442 return g_task_propagate_boolean(G_TASK(result), error); 502 return g_task_propagate_boolean(G_TASK(result), error);
443 } 503 }
444 504
505 static void
506 test_purple_protocol_conversation_set_avatar_async(PurpleProtocolConversation *protocol,
507 PurpleConversation *conversation,
508 G_GNUC_UNUSED PurpleAvatar *avatar,
509 GCancellable *cancellable,
510 GAsyncReadyCallback callback,
511 gpointer data)
512 {
513 TestPurpleProtocolConversation *test_protocol = NULL;
514 GTask *task = NULL;
515
516 g_assert_true(PURPLE_IS_CONVERSATION(conversation));
517
518 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol);
519 test_protocol->set_avatar_async += 1;
520
521 task = g_task_new(protocol, cancellable, callback, data);
522 if(test_protocol->should_error) {
523 GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN,
524 0, "error");
525 g_task_return_error(task, error);
526 } else {
527 g_task_return_boolean(task, TRUE);
528 }
529
530 g_clear_object(&task);
531 }
532
533 static gboolean
534 test_purple_protocol_conversation_set_avatar_finish(PurpleProtocolConversation *protocol,
535 GAsyncResult *result,
536 GError **error)
537 {
538 TestPurpleProtocolConversation *test_protocol = NULL;
539
540 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol);
541 test_protocol->set_avatar_finish += 1;
542
543 return g_task_propagate_boolean(G_TASK(result), error);
544 }
445 545
446 static void 546 static void
447 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) { 547 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) {
448 iface->send_message_async = test_purple_protocol_conversation_send_message_async; 548 iface->send_message_async = test_purple_protocol_conversation_send_message_async;
449 iface->send_message_finish = test_purple_protocol_conversation_send_message_finish; 549 iface->send_message_finish = test_purple_protocol_conversation_send_message_finish;
452 iface->set_topic_finish = test_purple_protocol_conversation_set_topic_finish; 552 iface->set_topic_finish = test_purple_protocol_conversation_set_topic_finish;
453 553
454 iface->get_channel_join_details = test_purple_protocol_conversation_get_channel_join_details; 554 iface->get_channel_join_details = test_purple_protocol_conversation_get_channel_join_details;
455 iface->join_channel_async = test_purple_protocol_conversation_join_channel_async; 555 iface->join_channel_async = test_purple_protocol_conversation_join_channel_async;
456 iface->join_channel_finish = test_purple_protocol_conversation_join_channel_finish; 556 iface->join_channel_finish = test_purple_protocol_conversation_join_channel_finish;
557
558 iface->set_avatar_async = test_purple_protocol_conversation_set_avatar_async;
559 iface->set_avatar_finish = test_purple_protocol_conversation_set_avatar_finish;
457 } 560 }
458 561
459 G_DEFINE_TYPE_WITH_CODE(TestPurpleProtocolConversation, test_purple_protocol_conversation, 562 G_DEFINE_TYPE_WITH_CODE(TestPurpleProtocolConversation, test_purple_protocol_conversation,
460 PURPLE_TYPE_PROTOCOL, 563 PURPLE_TYPE_PROTOCOL,
461 G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_CONVERSATION, 564 G_IMPLEMENT_INTERFACE(PURPLE_TYPE_PROTOCOL_CONVERSATION,
471 protocol->set_topic_finish = 0; 574 protocol->set_topic_finish = 0;
472 575
473 protocol->get_channel_join_details = 0; 576 protocol->get_channel_join_details = 0;
474 protocol->join_channel_async = 0; 577 protocol->join_channel_async = 0;
475 protocol->join_channel_finish = 0; 578 protocol->join_channel_finish = 0;
579
580 protocol->set_avatar_async = 0;
581 protocol->set_avatar_finish = 0;
476 } 582 }
477 583
478 static void 584 static void
479 test_purple_protocol_conversation_class_init(G_GNUC_UNUSED TestPurpleProtocolConversationClass *klass) 585 test_purple_protocol_conversation_class_init(G_GNUC_UNUSED TestPurpleProtocolConversationClass *klass)
480 { 586 {
731 837
732 g_main_loop_run(loop); 838 g_main_loop_run(loop);
733 839
734 g_assert_cmpuint(protocol->join_channel_async, ==, 1); 840 g_assert_cmpuint(protocol->join_channel_async, ==, 1);
735 g_assert_cmpuint(protocol->join_channel_finish, ==, 1); 841 g_assert_cmpuint(protocol->join_channel_finish, ==, 1);
842
843 g_clear_object(&protocol);
844 }
845
846 /******************************************************************************
847 * TestProtocolConversation SetAvatar Tests
848 *****************************************************************************/
849 static void
850 test_purple_protocol_conversation_set_avatar_cb(GObject *obj,
851 GAsyncResult *res,
852 G_GNUC_UNUSED gpointer data)
853 {
854 TestPurpleProtocolConversation *test_protocol = NULL;
855 PurpleProtocolConversation *protocol = NULL;
856 GError *error = NULL;
857 gboolean result = FALSE;
858
859 protocol = PURPLE_PROTOCOL_CONVERSATION(obj);
860 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(obj);
861
862 result = purple_protocol_conversation_set_avatar_finish(protocol, res,
863 &error);
864
865 if(test_protocol->should_error) {
866 g_assert_error(error, TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN, 0);
867 g_clear_error(&error);
868 g_assert_false(result);
869 } else {
870 g_assert_no_error(error);
871 g_assert_true(result);
872 }
873
874 g_main_loop_quit(loop);
875 }
876
877 static gboolean
878 test_purple_protocol_conversation_set_avatar_idle(gpointer data) {
879 PurpleAccount *account = NULL;
880 PurpleConversation *conversation = NULL;
881 PurpleProtocolConversation *protocol = data;
882
883 account = purple_account_new("test", "test");
884 g_object_set_data_full(G_OBJECT(protocol), "account", account,
885 g_object_unref);
886
887 conversation = g_object_new(
888 PURPLE_TYPE_CONVERSATION,
889 "account", account,
890 "name", "this is required at the moment",
891 "type", PurpleConversationTypeDM,
892 NULL);
893 g_object_set_data_full(G_OBJECT(protocol), "conversation", conversation,
894 g_object_unref);
895
896 purple_protocol_conversation_set_avatar_async(protocol, conversation,
897 NULL, NULL,
898 test_purple_protocol_conversation_set_avatar_cb,
899 NULL);
900
901 return G_SOURCE_REMOVE;
902 }
903
904 static void
905 test_purple_protocol_conversation_set_avatar_normal(gconstpointer data) {
906 TestPurpleProtocolConversation *protocol = NULL;
907
908 protocol = g_object_new(test_purple_protocol_conversation_get_type(),
909 NULL);
910 protocol->should_error = GPOINTER_TO_INT(data);
911
912 g_idle_add(test_purple_protocol_conversation_set_avatar_idle, protocol);
913 g_timeout_add_seconds(10, test_purple_protocol_conversation_timeout_cb,
914 loop);
915
916 g_main_loop_run(loop);
917
918 g_assert_cmpuint(protocol->set_avatar_async, ==, 1);
919 g_assert_cmpuint(protocol->set_avatar_finish, ==, 1);
736 920
737 g_clear_object(&protocol); 921 g_clear_object(&protocol);
738 } 922 }
739 923
740 /****************************************************************************** 924 /******************************************************************************
757 test_purple_protocol_conversation_empty_send_message_finish); 941 test_purple_protocol_conversation_empty_send_message_finish);
758 g_test_add_func("/protocol-conversation/empty/set-topic-async", 942 g_test_add_func("/protocol-conversation/empty/set-topic-async",
759 test_purple_protocol_conversation_empty_set_topic_async); 943 test_purple_protocol_conversation_empty_set_topic_async);
760 g_test_add_func("/protocol-conversation/empty/set-topic-finish", 944 g_test_add_func("/protocol-conversation/empty/set-topic-finish",
761 test_purple_protocol_conversation_empty_set_topic_finish); 945 test_purple_protocol_conversation_empty_set_topic_finish);
946 g_test_add_func("/protocol-conversation/empty/set-avatar-async",
947 test_purple_protocol_conversation_empty_set_avatar_async);
948 g_test_add_func("/protocol-conversation/empty/set-avatar-finish",
949 test_purple_protocol_conversation_empty_set_avatar_finish);
762 950
763 /* Empty join channel tests. */ 951 /* Empty join channel tests. */
764 g_test_add_func("/protocol-conversation/empty/get-channel-join-details", 952 g_test_add_func("/protocol-conversation/empty/get-channel-join-details",
765 test_purple_protocol_conversation_empty_get_channel_join_details); 953 test_purple_protocol_conversation_empty_get_channel_join_details);
766 g_test_add_func("/protocol-conversation/empty/join_channel_async", 954 g_test_add_func("/protocol-conversation/empty/join_channel_async",
773 GINT_TO_POINTER(FALSE), 961 GINT_TO_POINTER(FALSE),
774 test_purple_protocol_conversation_send_message_normal); 962 test_purple_protocol_conversation_send_message_normal);
775 g_test_add_data_func("/protocol-conversation/normal/send-message-error", 963 g_test_add_data_func("/protocol-conversation/normal/send-message-error",
776 GINT_TO_POINTER(TRUE), 964 GINT_TO_POINTER(TRUE),
777 test_purple_protocol_conversation_send_message_normal); 965 test_purple_protocol_conversation_send_message_normal);
778 g_test_add_data_func("/protocol-contacts/normal/set-topic-normal",
779 GINT_TO_POINTER(FALSE),
780 test_purple_protocol_conversation_set_topic_normal);
781 g_test_add_data_func("/protocol-contacts/normal/set-topic-error",
782 GINT_TO_POINTER(TRUE),
783 test_purple_protocol_conversation_set_topic_normal);
784 966
785 /* Normal join channel tests. */ 967 /* Normal join channel tests. */
786 g_test_add_func("/protocol-conversation/normal/get-channel-join-details", 968 g_test_add_func("/protocol-conversation/normal/get-channel-join-details",
787 test_purple_protocol_conversation_get_channel_join_details_normal); 969 test_purple_protocol_conversation_get_channel_join_details_normal);
788 g_test_add_data_func("/protocol-conversation/normal/join-channel-normal", 970 g_test_add_data_func("/protocol-conversation/normal/join-channel-normal",
790 test_purple_protocol_conversation_join_channel_normal); 972 test_purple_protocol_conversation_join_channel_normal);
791 g_test_add_data_func("/protocol-conversation/normal/join-channel-error", 973 g_test_add_data_func("/protocol-conversation/normal/join-channel-error",
792 GINT_TO_POINTER(TRUE), 974 GINT_TO_POINTER(TRUE),
793 test_purple_protocol_conversation_join_channel_normal); 975 test_purple_protocol_conversation_join_channel_normal);
794 976
977 /* Normal set topic tests. */
978 g_test_add_data_func("/protocol-contacts/normal/set-topic-normal",
979 GINT_TO_POINTER(FALSE),
980 test_purple_protocol_conversation_set_topic_normal);
981 g_test_add_data_func("/protocol-contacts/normal/set-topic-error",
982 GINT_TO_POINTER(TRUE),
983 test_purple_protocol_conversation_set_topic_normal);
984
985 /* Normal set avatar tests. */
986 g_test_add_data_func("/protocol-contacts/normal/set-avatar-normal",
987 GINT_TO_POINTER(FALSE),
988 test_purple_protocol_conversation_set_avatar_normal);
989 g_test_add_data_func("/protocol-contacts/normal/set-avatar-error",
990 GINT_TO_POINTER(TRUE),
991 test_purple_protocol_conversation_set_avatar_normal);
992
795 ret = g_test_run(); 993 ret = g_test_run();
796 994
797 g_main_loop_unref(loop); 995 g_main_loop_unref(loop);
798 996
799 test_ui_purple_uninit(); 997 test_ui_purple_uninit();

mercurial