| 495 |
519 |
| 496 g_test_trap_subprocess(NULL, 0, 0); |
520 g_test_trap_subprocess(NULL, 0, 0); |
| 497 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*refresh*"); |
521 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*refresh*"); |
| 498 } |
522 } |
| 499 |
523 |
| |
524 static void |
| |
525 test_purple_protocol_conversation_empty_implements_set_title(void) { |
| |
526 PurpleProtocolConversation *protocol = NULL; |
| |
527 |
| |
528 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(), |
| |
529 NULL); |
| |
530 |
| |
531 g_assert_false(purple_protocol_conversation_implements_set_title(protocol)); |
| |
532 |
| |
533 g_assert_finalize_object(protocol); |
| |
534 } |
| |
535 |
| |
536 static void |
| |
537 test_purple_protocol_conversation_empty_set_title_cb(GObject *source, |
| |
538 GAsyncResult *result, |
| |
539 G_GNUC_UNUSED gpointer data) |
| |
540 { |
| |
541 PurpleProtocolConversation *protocol = NULL; |
| |
542 GError *error = NULL; |
| |
543 gboolean set = FALSE; |
| |
544 |
| |
545 protocol = PURPLE_PROTOCOL_CONVERSATION(source); |
| |
546 set = purple_protocol_conversation_set_title_finish(protocol, result, |
| |
547 &error); |
| |
548 g_assert_error(error, PURPLE_PROTOCOL_CONVERSATION_DOMAIN, 0); |
| |
549 g_clear_error(&error); |
| |
550 g_assert_false(set); |
| |
551 } |
| |
552 |
| |
553 static void |
| |
554 test_purple_protocol_conversation_empty_set_title_async(void) { |
| |
555 PurpleAccount *account = NULL; |
| |
556 PurpleConversation *conversation = NULL; |
| |
557 PurpleProtocolConversation *protocol = NULL; |
| |
558 |
| |
559 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(), |
| |
560 NULL); |
| |
561 account = purple_account_new("test", "test"); |
| |
562 conversation = g_object_new( |
| |
563 PURPLE_TYPE_CONVERSATION, |
| |
564 "account", account, |
| |
565 "type", PURPLE_CONVERSATION_TYPE_DM, |
| |
566 NULL); |
| |
567 |
| |
568 purple_protocol_conversation_set_title_async(protocol, conversation, |
| |
569 "title", NULL, |
| |
570 test_purple_protocol_conversation_empty_set_title_cb, |
| |
571 NULL); |
| |
572 |
| |
573 g_main_context_iteration(NULL, FALSE); |
| |
574 |
| |
575 g_clear_object(&account); |
| |
576 g_assert_finalize_object(conversation); |
| |
577 g_assert_finalize_object(protocol); |
| |
578 } |
| |
579 |
| |
580 static void |
| |
581 test_purple_protocol_conversation_empty_implements_set_description(void) { |
| |
582 PurpleProtocolConversation *protocol = NULL; |
| |
583 |
| |
584 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(), |
| |
585 NULL); |
| |
586 |
| |
587 g_assert_false(purple_protocol_conversation_implements_set_description(protocol)); |
| |
588 |
| |
589 g_assert_finalize_object(protocol); |
| |
590 } |
| |
591 |
| |
592 static void |
| |
593 test_purple_protocol_conversation_empty_set_description_cb(GObject *source, |
| |
594 GAsyncResult *result, |
| |
595 G_GNUC_UNUSED gpointer data) |
| |
596 { |
| |
597 PurpleProtocolConversation *protocol = NULL; |
| |
598 GError *error = NULL; |
| |
599 gboolean set = FALSE; |
| |
600 |
| |
601 protocol = PURPLE_PROTOCOL_CONVERSATION(source); |
| |
602 set = purple_protocol_conversation_set_description_finish(protocol, result, |
| |
603 &error); |
| |
604 g_assert_error(error, PURPLE_PROTOCOL_CONVERSATION_DOMAIN, 0); |
| |
605 g_clear_error(&error); |
| |
606 g_assert_false(set); |
| |
607 } |
| |
608 |
| |
609 static void |
| |
610 test_purple_protocol_conversation_empty_set_description_async(void) { |
| |
611 PurpleAccount *account = NULL; |
| |
612 PurpleConversation *conversation = NULL; |
| |
613 PurpleProtocolConversation *protocol = NULL; |
| |
614 |
| |
615 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(), |
| |
616 NULL); |
| |
617 account = purple_account_new("test", "test"); |
| |
618 conversation = g_object_new( |
| |
619 PURPLE_TYPE_CONVERSATION, |
| |
620 "account", account, |
| |
621 "type", PURPLE_CONVERSATION_TYPE_DM, |
| |
622 NULL); |
| |
623 |
| |
624 purple_protocol_conversation_set_description_async(protocol, conversation, |
| |
625 "description", NULL, |
| |
626 test_purple_protocol_conversation_empty_set_description_cb, |
| |
627 NULL); |
| |
628 |
| |
629 g_main_context_iteration(NULL, FALSE); |
| |
630 |
| |
631 g_clear_object(&account); |
| |
632 g_assert_finalize_object(conversation); |
| |
633 g_assert_finalize_object(protocol); |
| |
634 } |
| |
635 |
| 500 /****************************************************************************** |
636 /****************************************************************************** |
| 501 * TestProtocolConversation Implementation |
637 * TestProtocolConversation Implementation |
| 502 *****************************************************************************/ |
638 *****************************************************************************/ |
| 503 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation, |
639 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation, |
| 504 test_purple_protocol_conversation, TEST_PURPLE, |
640 test_purple_protocol_conversation, TEST_PURPLE, |
| 846 |
988 |
| 847 g_assert_true(PURPLE_IS_CONVERSATION(conversation)); |
989 g_assert_true(PURPLE_IS_CONVERSATION(conversation)); |
| 848 } |
990 } |
| 849 |
991 |
| 850 static void |
992 static void |
| |
993 test_purple_protocol_conversation_set_title_async(PurpleProtocolConversation *protocol, |
| |
994 PurpleConversation *conversation, |
| |
995 G_GNUC_UNUSED const char *title, |
| |
996 GCancellable *cancellable, |
| |
997 GAsyncReadyCallback callback, |
| |
998 gpointer data) |
| |
999 { |
| |
1000 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1001 GTask *task = NULL; |
| |
1002 |
| |
1003 g_assert_true(PURPLE_IS_CONVERSATION(conversation)); |
| |
1004 |
| |
1005 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol); |
| |
1006 test_protocol->set_title_async += 1; |
| |
1007 |
| |
1008 task = g_task_new(protocol, cancellable, callback, data); |
| |
1009 if(test_protocol->should_error) { |
| |
1010 g_task_return_new_error_literal(task, |
| |
1011 TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN, |
| |
1012 0, "error"); |
| |
1013 } else { |
| |
1014 g_task_return_boolean(task, TRUE); |
| |
1015 } |
| |
1016 |
| |
1017 g_clear_object(&task); |
| |
1018 } |
| |
1019 |
| |
1020 static gboolean |
| |
1021 test_purple_protocol_conversation_set_title_finish(PurpleProtocolConversation *protocol, |
| |
1022 GAsyncResult *result, |
| |
1023 GError **error) |
| |
1024 { |
| |
1025 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1026 |
| |
1027 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol); |
| |
1028 test_protocol->set_title_finish += 1; |
| |
1029 |
| |
1030 return g_task_propagate_boolean(G_TASK(result), error); |
| |
1031 } |
| |
1032 |
| |
1033 static void |
| |
1034 test_purple_protocol_conversation_set_description_async(PurpleProtocolConversation *protocol, |
| |
1035 PurpleConversation *conversation, |
| |
1036 G_GNUC_UNUSED const char *description, |
| |
1037 GCancellable *cancellable, |
| |
1038 GAsyncReadyCallback callback, |
| |
1039 gpointer data) |
| |
1040 { |
| |
1041 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1042 GTask *task = NULL; |
| |
1043 |
| |
1044 g_assert_true(PURPLE_IS_CONVERSATION(conversation)); |
| |
1045 |
| |
1046 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol); |
| |
1047 test_protocol->set_description_async += 1; |
| |
1048 |
| |
1049 task = g_task_new(protocol, cancellable, callback, data); |
| |
1050 if(test_protocol->should_error) { |
| |
1051 g_task_return_new_error_literal(task, |
| |
1052 TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN, |
| |
1053 0, "error"); |
| |
1054 } else { |
| |
1055 g_task_return_boolean(task, TRUE); |
| |
1056 } |
| |
1057 |
| |
1058 g_clear_object(&task); |
| |
1059 } |
| |
1060 |
| |
1061 static gboolean |
| |
1062 test_purple_protocol_conversation_set_description_finish(PurpleProtocolConversation *protocol, |
| |
1063 GAsyncResult *result, |
| |
1064 GError **error) |
| |
1065 { |
| |
1066 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1067 |
| |
1068 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol); |
| |
1069 test_protocol->set_description_finish += 1; |
| |
1070 |
| |
1071 return g_task_propagate_boolean(G_TASK(result), error); |
| |
1072 } |
| |
1073 |
| |
1074 static void |
| 851 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) { |
1075 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) { |
| 852 iface->get_create_conversation_details = test_purple_protocol_conversation_get_create_conversation_details; |
1076 iface->get_create_conversation_details = test_purple_protocol_conversation_get_create_conversation_details; |
| 853 iface->create_conversation_async = test_purple_protocol_conversation_create_conversation_async; |
1077 iface->create_conversation_async = test_purple_protocol_conversation_create_conversation_async; |
| 854 iface->create_conversation_finish = test_purple_protocol_conversation_create_conversation_finish; |
1078 iface->create_conversation_finish = test_purple_protocol_conversation_create_conversation_finish; |
| 855 |
1079 |
| 869 iface->set_avatar_async = test_purple_protocol_conversation_set_avatar_async; |
1093 iface->set_avatar_async = test_purple_protocol_conversation_set_avatar_async; |
| 870 iface->set_avatar_finish = test_purple_protocol_conversation_set_avatar_finish; |
1094 iface->set_avatar_finish = test_purple_protocol_conversation_set_avatar_finish; |
| 871 |
1095 |
| 872 iface->send_typing = test_purple_protocol_conversation_send_typing; |
1096 iface->send_typing = test_purple_protocol_conversation_send_typing; |
| 873 iface->refresh = test_purple_protocol_conversation_refresh; |
1097 iface->refresh = test_purple_protocol_conversation_refresh; |
| |
1098 |
| |
1099 iface->set_title_async = test_purple_protocol_conversation_set_title_async; |
| |
1100 iface->set_title_finish = test_purple_protocol_conversation_set_title_finish; |
| |
1101 |
| |
1102 iface->set_description_async = test_purple_protocol_conversation_set_description_async; |
| |
1103 iface->set_description_finish = test_purple_protocol_conversation_set_description_finish; |
| 874 } |
1104 } |
| 875 |
1105 |
| 876 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolConversation, |
1106 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolConversation, |
| 877 test_purple_protocol_conversation, |
1107 test_purple_protocol_conversation, |
| 878 PURPLE_TYPE_PROTOCOL, |
1108 PURPLE_TYPE_PROTOCOL, |
| 1458 g_clear_object(&account); |
1694 g_clear_object(&account); |
| 1459 g_clear_object(&protocol); |
1695 g_clear_object(&protocol); |
| 1460 } |
1696 } |
| 1461 |
1697 |
| 1462 /****************************************************************************** |
1698 /****************************************************************************** |
| |
1699 * TestProtocolConversation set_title Tests |
| |
1700 *****************************************************************************/ |
| |
1701 static void |
| |
1702 test_purple_protocol_conversation_set_title_cb(GObject *obj, |
| |
1703 GAsyncResult *res, |
| |
1704 G_GNUC_UNUSED gpointer data) |
| |
1705 { |
| |
1706 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1707 PurpleProtocolConversation *protocol = NULL; |
| |
1708 GError *error = NULL; |
| |
1709 gboolean result = FALSE; |
| |
1710 |
| |
1711 protocol = PURPLE_PROTOCOL_CONVERSATION(obj); |
| |
1712 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(obj); |
| |
1713 |
| |
1714 result = purple_protocol_conversation_set_title_finish(protocol, res, |
| |
1715 &error); |
| |
1716 |
| |
1717 if(test_protocol->should_error) { |
| |
1718 g_assert_error(error, TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN, 0); |
| |
1719 g_clear_error(&error); |
| |
1720 g_assert_false(result); |
| |
1721 } else { |
| |
1722 g_assert_no_error(error); |
| |
1723 g_assert_true(result); |
| |
1724 } |
| |
1725 } |
| |
1726 |
| |
1727 static void |
| |
1728 test_purple_protocol_conversation_set_title_normal(gconstpointer data) { |
| |
1729 TestPurpleProtocolConversation *protocol = NULL; |
| |
1730 PurpleAccount *account = NULL; |
| |
1731 PurpleConversation *conversation = NULL; |
| |
1732 |
| |
1733 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1734 NULL); |
| |
1735 protocol->should_error = GPOINTER_TO_INT(data); |
| |
1736 |
| |
1737 account = purple_account_new("test", "test"); |
| |
1738 conversation = g_object_new( |
| |
1739 PURPLE_TYPE_CONVERSATION, |
| |
1740 "account", account, |
| |
1741 "type", PURPLE_CONVERSATION_TYPE_DM, |
| |
1742 NULL); |
| |
1743 |
| |
1744 purple_protocol_conversation_set_title_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| |
1745 conversation, "title", NULL, |
| |
1746 test_purple_protocol_conversation_set_title_cb, |
| |
1747 NULL); |
| |
1748 |
| |
1749 g_main_context_iteration(NULL, FALSE); |
| |
1750 |
| |
1751 g_assert_cmpuint(protocol->set_title_async, ==, 1); |
| |
1752 g_assert_cmpuint(protocol->set_title_finish, ==, 1); |
| |
1753 |
| |
1754 g_assert_finalize_object(conversation); |
| |
1755 g_assert_finalize_object(protocol); |
| |
1756 g_clear_object(&account); |
| |
1757 } |
| |
1758 |
| |
1759 /****************************************************************************** |
| |
1760 * TestProtocolConversation set_description Tests |
| |
1761 *****************************************************************************/ |
| |
1762 static void |
| |
1763 test_purple_protocol_conversation_set_description_cb(GObject *obj, |
| |
1764 GAsyncResult *res, |
| |
1765 G_GNUC_UNUSED gpointer data) |
| |
1766 { |
| |
1767 TestPurpleProtocolConversation *test_protocol = NULL; |
| |
1768 PurpleProtocolConversation *protocol = NULL; |
| |
1769 GError *error = NULL; |
| |
1770 gboolean result = FALSE; |
| |
1771 |
| |
1772 protocol = PURPLE_PROTOCOL_CONVERSATION(obj); |
| |
1773 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(obj); |
| |
1774 |
| |
1775 result = purple_protocol_conversation_set_description_finish(protocol, res, |
| |
1776 &error); |
| |
1777 |
| |
1778 if(test_protocol->should_error) { |
| |
1779 g_assert_error(error, TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN, 0); |
| |
1780 g_clear_error(&error); |
| |
1781 g_assert_false(result); |
| |
1782 } else { |
| |
1783 g_assert_no_error(error); |
| |
1784 g_assert_true(result); |
| |
1785 } |
| |
1786 } |
| |
1787 |
| |
1788 static void |
| |
1789 test_purple_protocol_conversation_set_description_normal(gconstpointer data) { |
| |
1790 TestPurpleProtocolConversation *protocol = NULL; |
| |
1791 PurpleAccount *account = NULL; |
| |
1792 PurpleConversation *conversation = NULL; |
| |
1793 |
| |
1794 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1795 NULL); |
| |
1796 protocol->should_error = GPOINTER_TO_INT(data); |
| |
1797 |
| |
1798 account = purple_account_new("test", "test"); |
| |
1799 conversation = g_object_new( |
| |
1800 PURPLE_TYPE_CONVERSATION, |
| |
1801 "account", account, |
| |
1802 "type", PURPLE_CONVERSATION_TYPE_DM, |
| |
1803 NULL); |
| |
1804 |
| |
1805 purple_protocol_conversation_set_description_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| |
1806 conversation, |
| |
1807 "description", NULL, |
| |
1808 test_purple_protocol_conversation_set_description_cb, |
| |
1809 NULL); |
| |
1810 |
| |
1811 g_main_context_iteration(NULL, FALSE); |
| |
1812 |
| |
1813 g_assert_cmpuint(protocol->set_description_async, ==, 1); |
| |
1814 g_assert_cmpuint(protocol->set_description_finish, ==, 1); |
| |
1815 |
| |
1816 g_assert_finalize_object(conversation); |
| |
1817 g_assert_finalize_object(protocol); |
| |
1818 g_clear_object(&account); |
| |
1819 } |
| |
1820 |
| |
1821 /****************************************************************************** |
| 1463 * Main |
1822 * Main |
| 1464 *****************************************************************************/ |
1823 *****************************************************************************/ |
| 1465 gint |
1824 gint |
| 1466 main(int argc, char **argv) { |
1825 main(int argc, char **argv) { |
| 1467 g_test_init(&argc, &argv, NULL); |
1826 g_test_init(&argc, &argv, NULL); |
| 1486 g_test_add_func("/protocol-conversation/empty/implements-send-message", |
1845 g_test_add_func("/protocol-conversation/empty/implements-send-message", |
| 1487 test_purple_protocol_conversation_empty_implements_send_message); |
1846 test_purple_protocol_conversation_empty_implements_send_message); |
| 1488 g_test_add_func("/protocol-conversation/empty/send-message-async", |
1847 g_test_add_func("/protocol-conversation/empty/send-message-async", |
| 1489 test_purple_protocol_conversation_empty_send_message_async); |
1848 test_purple_protocol_conversation_empty_send_message_async); |
| 1490 |
1849 |
| |
1850 g_test_add_func("/protocol-conversation/empty/implements-set-topic", |
| |
1851 test_purple_protocol_conversation_empty_implements_set_topic); |
| 1491 g_test_add_func("/protocol-conversation/empty/set-topic-async", |
1852 g_test_add_func("/protocol-conversation/empty/set-topic-async", |
| 1492 test_purple_protocol_conversation_empty_set_topic_async); |
1853 test_purple_protocol_conversation_empty_set_topic_async); |
| |
1854 |
| |
1855 g_test_add_func("/protocol-conversation/empty/implements-set-avatar", |
| |
1856 test_purple_protocol_conversation_empty_implements_set_avatar); |
| 1493 g_test_add_func("/protocol-conversation/empty/set-avatar-async", |
1857 g_test_add_func("/protocol-conversation/empty/set-avatar-async", |
| 1494 test_purple_protocol_conversation_empty_set_avatar_async); |
1858 test_purple_protocol_conversation_empty_set_avatar_async); |
| 1495 |
1859 |
| 1496 /* Empty join channel tests. */ |
1860 /* Empty join channel tests. */ |
| 1497 g_test_add_func("/protocol-conversation/empty/get-channel-join-details", |
1861 g_test_add_func("/protocol-conversation/empty/get-channel-join-details", |
| 1498 test_purple_protocol_conversation_empty_get_channel_join_details); |
1862 test_purple_protocol_conversation_empty_get_channel_join_details); |
| 1499 g_test_add_func("/protocol-conversation/empty/join_channel_async", |
1863 g_test_add_func("/protocol-conversation/empty/join_channel_async", |
| 1500 test_purple_protocol_conversation_empty_join_channel_async); |
1864 test_purple_protocol_conversation_empty_join_channel_async); |
| |
1865 |
| |
1866 g_test_add_func("/protocol-conversation/empty/implements-set-title", |
| |
1867 test_purple_protocol_conversation_empty_implements_set_title); |
| |
1868 g_test_add_func("/protocol-conversation/empty/set-title-async", |
| |
1869 test_purple_protocol_conversation_empty_set_title_async); |
| |
1870 |
| |
1871 g_test_add_func("/protocol-conversation/empty/implements-set-description", |
| |
1872 test_purple_protocol_conversation_empty_implements_set_description); |
| |
1873 g_test_add_func("/protocol-conversation/empty/set-description-async", |
| |
1874 test_purple_protocol_conversation_empty_set_description_async); |
| 1501 |
1875 |
| 1502 /* Empty send typing tests. */ |
1876 /* Empty send typing tests. */ |
| 1503 g_test_add_func("/protocol-conversation/empty/implements-send-typing", |
1877 g_test_add_func("/protocol-conversation/empty/implements-send-typing", |
| 1504 test_purple_protocol_conversation_empty_implements_send_typing); |
1878 test_purple_protocol_conversation_empty_implements_send_typing); |
| 1505 g_test_add_func("/protocol-conversation/empty/send-typing", |
1879 g_test_add_func("/protocol-conversation/empty/send-typing", |
| 1579 g_test_add_func("/protocol-conversation/normal/implements-refresh", |
1953 g_test_add_func("/protocol-conversation/normal/implements-refresh", |
| 1580 test_purple_protocol_conversation_implements_refresh); |
1954 test_purple_protocol_conversation_implements_refresh); |
| 1581 g_test_add_func("/protocol-conversation/normal/refresh", |
1955 g_test_add_func("/protocol-conversation/normal/refresh", |
| 1582 test_purple_protocol_conversation_refresh_normal); |
1956 test_purple_protocol_conversation_refresh_normal); |
| 1583 |
1957 |
| |
1958 /* Normal set title tests. */ |
| |
1959 g_test_add_data_func("/protocol-contacts/normal/set-title-normal", |
| |
1960 GINT_TO_POINTER(FALSE), |
| |
1961 test_purple_protocol_conversation_set_title_normal); |
| |
1962 g_test_add_data_func("/protocol-contacts/normal/set-title-error", |
| |
1963 GINT_TO_POINTER(TRUE), |
| |
1964 test_purple_protocol_conversation_set_title_normal); |
| |
1965 |
| |
1966 /* Normal set description tests. */ |
| |
1967 g_test_add_data_func("/protocol-contacts/normal/set-description-normal", |
| |
1968 GINT_TO_POINTER(FALSE), |
| |
1969 test_purple_protocol_conversation_set_description_normal); |
| |
1970 g_test_add_data_func("/protocol-contacts/normal/set-description-error", |
| |
1971 GINT_TO_POINTER(TRUE), |
| |
1972 test_purple_protocol_conversation_set_description_normal); |
| |
1973 |
| 1584 return g_test_run(); |
1974 return g_test_run(); |
| 1585 } |
1975 } |