libpurple/tests/test_protocol_conversation.c

changeset 43104
f87ae4effec7
parent 43095
be478d840409
child 43136
36eba703e2b9
equal deleted inserted replaced
43103:fac24c225f6e 43104:f87ae4effec7
456 456
457 g_test_trap_subprocess(NULL, 0, 0); 457 g_test_trap_subprocess(NULL, 0, 0);
458 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*send_typing*"); 458 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*send_typing*");
459 } 459 }
460 460
461 static void
462 test_purple_protocol_conversation_empty_implements_refresh(void) {
463 PurpleProtocolConversation *protocol = NULL;
464
465 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(),
466 NULL);
467
468 g_assert_false(purple_protocol_conversation_implements_refresh(protocol));
469
470 g_assert_finalize_object(protocol);
471 }
472
473 static void
474 test_purple_protocol_conversation_empty_refresh(void) {
475 if(g_test_subprocess()) {
476 PurpleAccount *account = NULL;
477 PurpleConversation *conversation = NULL;
478 PurpleProtocolConversation *protocol = NULL;
479
480 protocol = g_object_new(test_purple_protocol_conversation_empty_get_type(),
481 NULL);
482 account = purple_account_new("test", "test");
483 conversation = g_object_new(
484 PURPLE_TYPE_CONVERSATION,
485 "account", account,
486 "type", PURPLE_CONVERSATION_TYPE_DM,
487 NULL);
488
489 purple_protocol_conversation_refresh(protocol, conversation);
490
491 g_clear_object(&account);
492 g_clear_object(&conversation);
493 g_clear_object(&protocol);
494 }
495
496 g_test_trap_subprocess(NULL, 0, 0);
497 g_test_trap_assert_stderr("*Purple-WARNING*TestPurpleProtocolConversationEmpty*refresh*");
498 }
499
461 /****************************************************************************** 500 /******************************************************************************
462 * TestProtocolConversation Implementation 501 * TestProtocolConversation Implementation
463 *****************************************************************************/ 502 *****************************************************************************/
464 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation, 503 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversation,
465 test_purple_protocol_conversation, TEST_PURPLE, 504 test_purple_protocol_conversation, TEST_PURPLE,
489 528
490 guint set_avatar_async; 529 guint set_avatar_async;
491 guint set_avatar_finish; 530 guint set_avatar_finish;
492 531
493 guint send_typing; 532 guint send_typing;
533 guint refresh;
494 }; 534 };
495 535
496 static PurpleCreateConversationDetails * 536 static PurpleCreateConversationDetails *
497 test_purple_protocol_conversation_get_create_conversation_details(PurpleProtocolConversation *protocol, 537 test_purple_protocol_conversation_get_create_conversation_details(PurpleProtocolConversation *protocol,
498 PurpleAccount *account) 538 PurpleAccount *account)
794 g_assert_true(PURPLE_IS_CONVERSATION(conversation)); 834 g_assert_true(PURPLE_IS_CONVERSATION(conversation));
795 g_assert_true(state == PURPLE_TYPING_STATE_TYPING); 835 g_assert_true(state == PURPLE_TYPING_STATE_TYPING);
796 } 836 }
797 837
798 static void 838 static void
839 test_purple_protocol_conversation_refresh(PurpleProtocolConversation *protocol,
840 PurpleConversation *conversation)
841 {
842 TestPurpleProtocolConversation *test_protocol = NULL;
843
844 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol);
845 test_protocol->refresh += 1;
846
847 g_assert_true(PURPLE_IS_CONVERSATION(conversation));
848 }
849
850 static void
799 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) { 851 test_purple_protocol_conversation_iface_init(PurpleProtocolConversationInterface *iface) {
800 iface->get_create_conversation_details = test_purple_protocol_conversation_get_create_conversation_details; 852 iface->get_create_conversation_details = test_purple_protocol_conversation_get_create_conversation_details;
801 iface->create_conversation_async = test_purple_protocol_conversation_create_conversation_async; 853 iface->create_conversation_async = test_purple_protocol_conversation_create_conversation_async;
802 iface->create_conversation_finish = test_purple_protocol_conversation_create_conversation_finish; 854 iface->create_conversation_finish = test_purple_protocol_conversation_create_conversation_finish;
803 855
816 868
817 iface->set_avatar_async = test_purple_protocol_conversation_set_avatar_async; 869 iface->set_avatar_async = test_purple_protocol_conversation_set_avatar_async;
818 iface->set_avatar_finish = test_purple_protocol_conversation_set_avatar_finish; 870 iface->set_avatar_finish = test_purple_protocol_conversation_set_avatar_finish;
819 871
820 iface->send_typing = test_purple_protocol_conversation_send_typing; 872 iface->send_typing = test_purple_protocol_conversation_send_typing;
873 iface->refresh = test_purple_protocol_conversation_refresh;
821 } 874 }
822 875
823 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolConversation, 876 G_DEFINE_FINAL_TYPE_WITH_CODE(TestPurpleProtocolConversation,
824 test_purple_protocol_conversation, 877 test_purple_protocol_conversation,
825 PURPLE_TYPE_PROTOCOL, 878 PURPLE_TYPE_PROTOCOL,
848 901
849 protocol->set_avatar_async = 0; 902 protocol->set_avatar_async = 0;
850 protocol->set_avatar_finish = 0; 903 protocol->set_avatar_finish = 0;
851 904
852 protocol->send_typing = 0; 905 protocol->send_typing = 0;
906 protocol->refresh = 0;
853 } 907 }
854 908
855 static void 909 static void
856 test_purple_protocol_conversation_class_init(G_GNUC_UNUSED TestPurpleProtocolConversationClass *klass) 910 test_purple_protocol_conversation_class_init(G_GNUC_UNUSED TestPurpleProtocolConversationClass *klass)
857 { 911 {
1092 1146
1093 account = purple_account_new("test", "test"); 1147 account = purple_account_new("test", "test");
1094 conversation = g_object_new( 1148 conversation = g_object_new(
1095 PURPLE_TYPE_CONVERSATION, 1149 PURPLE_TYPE_CONVERSATION,
1096 "account", account, 1150 "account", account,
1097 "name", "this is required at the moment",
1098 "type", PURPLE_CONVERSATION_TYPE_DM, 1151 "type", PURPLE_CONVERSATION_TYPE_DM,
1099 NULL); 1152 NULL);
1100 1153
1101 message = g_object_new(PURPLE_TYPE_MESSAGE, NULL); 1154 message = g_object_new(PURPLE_TYPE_MESSAGE, NULL);
1102 purple_protocol_conversation_send_message_async(PURPLE_PROTOCOL_CONVERSATION(protocol), 1155 purple_protocol_conversation_send_message_async(PURPLE_PROTOCOL_CONVERSATION(protocol),
1156 1209
1157 account = purple_account_new("test", "test"); 1210 account = purple_account_new("test", "test");
1158 conversation = g_object_new( 1211 conversation = g_object_new(
1159 PURPLE_TYPE_CONVERSATION, 1212 PURPLE_TYPE_CONVERSATION,
1160 "account", account, 1213 "account", account,
1161 "name", "this is required at the moment",
1162 "type", PURPLE_CONVERSATION_TYPE_DM, 1214 "type", PURPLE_CONVERSATION_TYPE_DM,
1163 NULL); 1215 NULL);
1164 1216
1165 purple_protocol_conversation_set_topic_async(PURPLE_PROTOCOL_CONVERSATION(protocol), 1217 purple_protocol_conversation_set_topic_async(PURPLE_PROTOCOL_CONVERSATION(protocol),
1166 conversation, "woo hoo", NULL, 1218 conversation, "woo hoo", NULL,
1300 1352
1301 account = purple_account_new("test", "test"); 1353 account = purple_account_new("test", "test");
1302 conversation = g_object_new( 1354 conversation = g_object_new(
1303 PURPLE_TYPE_CONVERSATION, 1355 PURPLE_TYPE_CONVERSATION,
1304 "account", account, 1356 "account", account,
1305 "name", "this is required at the moment",
1306 "type", PURPLE_CONVERSATION_TYPE_DM, 1357 "type", PURPLE_CONVERSATION_TYPE_DM,
1307 NULL); 1358 NULL);
1308 1359
1309 purple_protocol_conversation_set_avatar_async(PURPLE_PROTOCOL_CONVERSATION(protocol), 1360 purple_protocol_conversation_set_avatar_async(PURPLE_PROTOCOL_CONVERSATION(protocol),
1310 conversation, NULL, NULL, 1361 conversation, NULL, NULL,
1350 account = purple_account_new("test", "test"); 1401 account = purple_account_new("test", "test");
1351 1402
1352 conversation = g_object_new( 1403 conversation = g_object_new(
1353 PURPLE_TYPE_CONVERSATION, 1404 PURPLE_TYPE_CONVERSATION,
1354 "account", account, 1405 "account", account,
1355 "name", "this is required at the moment",
1356 "type", PURPLE_CONVERSATION_TYPE_DM, 1406 "type", PURPLE_CONVERSATION_TYPE_DM,
1357 NULL); 1407 NULL);
1358 1408
1359 test_purple_protocol_conversation_send_typing(protocol, conversation, 1409 test_purple_protocol_conversation_send_typing(protocol, conversation,
1360 PURPLE_TYPING_STATE_TYPING); 1410 PURPLE_TYPING_STATE_TYPING);
1361 1411
1362 g_assert_cmpuint(test_protocol->send_typing, ==, 1); 1412 g_assert_cmpuint(test_protocol->send_typing, ==, 1);
1413
1414 g_clear_object(&conversation);
1415 g_clear_object(&account);
1416 g_clear_object(&protocol);
1417 }
1418
1419 /******************************************************************************
1420 * TestProtocolConversation Refresh Tests
1421 ****************************************************************************/
1422 static void
1423 test_purple_protocol_conversation_implements_refresh(void) {
1424 PurpleProtocolConversation *protocol = NULL;
1425
1426 protocol = g_object_new(test_purple_protocol_conversation_get_type(),
1427 NULL);
1428
1429 g_assert_true(purple_protocol_conversation_implements_refresh(protocol));
1430
1431 g_assert_finalize_object(protocol);
1432 }
1433
1434 static void
1435 test_purple_protocol_conversation_refresh_normal(void) {
1436 TestPurpleProtocolConversation *test_protocol = NULL;
1437 PurpleAccount *account = NULL;
1438 PurpleConversation *conversation = NULL;
1439 PurpleProtocolConversation *protocol = NULL;
1440
1441 protocol = g_object_new(test_purple_protocol_conversation_get_type(),
1442 NULL);
1443 test_protocol = TEST_PURPLE_PROTOCOL_CONVERSATION(protocol);
1444
1445 account = purple_account_new("test", "test");
1446
1447 conversation = g_object_new(
1448 PURPLE_TYPE_CONVERSATION,
1449 "account", account,
1450 "type", PURPLE_CONVERSATION_TYPE_DM,
1451 NULL);
1452
1453 test_purple_protocol_conversation_refresh(protocol, conversation);
1454
1455 g_assert_cmpuint(test_protocol->refresh, ==, 1);
1363 1456
1364 g_clear_object(&conversation); 1457 g_clear_object(&conversation);
1365 g_clear_object(&account); 1458 g_clear_object(&account);
1366 g_clear_object(&protocol); 1459 g_clear_object(&protocol);
1367 } 1460 }
1409 /* Empty send typing tests. */ 1502 /* Empty send typing tests. */
1410 g_test_add_func("/protocol-conversation/empty/implements-send-typing", 1503 g_test_add_func("/protocol-conversation/empty/implements-send-typing",
1411 test_purple_protocol_conversation_empty_implements_send_typing); 1504 test_purple_protocol_conversation_empty_implements_send_typing);
1412 g_test_add_func("/protocol-conversation/empty/send-typing", 1505 g_test_add_func("/protocol-conversation/empty/send-typing",
1413 test_purple_protocol_conversation_empty_send_typing); 1506 test_purple_protocol_conversation_empty_send_typing);
1507
1508 /* Empty refresh tests. */
1509 g_test_add_func("/protocol-conversation/empty/implements-refresh",
1510 test_purple_protocol_conversation_empty_implements_refresh);
1511 g_test_add_func("/protocol-conversation/empty/refresh",
1512 test_purple_protocol_conversation_empty_refresh);
1414 1513
1415 /* Normal create conversation tests. */ 1514 /* Normal create conversation tests. */
1416 g_test_add_func("/protocol-conversation/normal/implements-create-conversation", 1515 g_test_add_func("/protocol-conversation/normal/implements-create-conversation",
1417 test_purple_protocol_conversation_implements_create_conversation); 1516 test_purple_protocol_conversation_implements_create_conversation);
1418 g_test_add_func("/protocol-conversation/normal/get-create-conversation-details-normal", 1517 g_test_add_func("/protocol-conversation/normal/get-create-conversation-details-normal",
1474 g_test_add_func("/protocol-conversation/normal/implements-send-typing", 1573 g_test_add_func("/protocol-conversation/normal/implements-send-typing",
1475 test_purple_protocol_conversation_implements_send_typing); 1574 test_purple_protocol_conversation_implements_send_typing);
1476 g_test_add_func("/protocol-conversation/normal/send-typing", 1575 g_test_add_func("/protocol-conversation/normal/send-typing",
1477 test_purple_protocol_conversation_send_typing_normal); 1576 test_purple_protocol_conversation_send_typing_normal);
1478 1577
1578 /* Normal refresh tests. */
1579 g_test_add_func("/protocol-conversation/normal/implements-refresh",
1580 test_purple_protocol_conversation_implements_refresh);
1581 g_test_add_func("/protocol-conversation/normal/refresh",
1582 test_purple_protocol_conversation_refresh_normal);
1583
1479 return g_test_run(); 1584 return g_test_run();
1480 } 1585 }

mercurial