| 24 |
24 |
| 25 #include <gdk-pixbuf/gdk-pixbuf.h> |
25 #include <gdk-pixbuf/gdk-pixbuf.h> |
| 26 |
26 |
| 27 #include <purple.h> |
27 #include <purple.h> |
| 28 |
28 |
| 29 #include "test_ui.h" |
|
| 30 |
|
| 31 /****************************************************************************** |
29 /****************************************************************************** |
| 32 * Globals |
30 * Globals |
| 33 *****************************************************************************/ |
31 *****************************************************************************/ |
| 34 |
32 |
| 35 /* Since we're using GTask to test asynchronous functions, we need to use a |
|
| 36 * main loop. |
|
| 37 */ |
|
| 38 static GMainLoop *loop = NULL; |
|
| 39 |
|
| 40 #define TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN (g_quark_from_static_string("test-protocol-conversation")) |
33 #define TEST_PURPLE_PROTOCOL_CONVERSATION_DOMAIN (g_quark_from_static_string("test-protocol-conversation")) |
| 41 |
|
| 42 /****************************************************************************** |
|
| 43 * Helpers |
|
| 44 *****************************************************************************/ |
|
| 45 static gboolean |
|
| 46 test_purple_protocol_conversation_timeout_cb(gpointer data) { |
|
| 47 g_main_loop_quit(data); |
|
| 48 |
|
| 49 g_warning("timed out waiting for the callback function to be called"); |
|
| 50 |
|
| 51 return G_SOURCE_REMOVE; |
|
| 52 } |
|
| 53 |
34 |
| 54 /****************************************************************************** |
35 /****************************************************************************** |
| 55 * TestProtocolConversationEmpty implementation |
36 * TestProtocolConversationEmpty implementation |
| 56 *****************************************************************************/ |
37 *****************************************************************************/ |
| 57 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversationEmpty, |
38 G_DECLARE_FINAL_TYPE(TestPurpleProtocolConversationEmpty, |
| 1094 g_assert_false(result); |
1075 g_assert_false(result); |
| 1095 } else { |
1076 } else { |
| 1096 g_assert_no_error(error); |
1077 g_assert_no_error(error); |
| 1097 g_assert_true(result); |
1078 g_assert_true(result); |
| 1098 } |
1079 } |
| 1099 |
1080 } |
| 1100 g_main_loop_quit(loop); |
1081 |
| 1101 } |
1082 static void |
| 1102 |
1083 test_purple_protocol_conversation_send_message_normal(gconstpointer data) { |
| 1103 static gboolean |
1084 TestPurpleProtocolConversation *protocol = NULL; |
| 1104 test_purple_protocol_conversation_send_message_idle(gpointer data) { |
|
| 1105 PurpleAccount *account = NULL; |
1085 PurpleAccount *account = NULL; |
| 1106 PurpleConversation *conversation = NULL; |
1086 PurpleConversation *conversation = NULL; |
| 1107 PurpleMessage *message = NULL; |
1087 PurpleMessage *message = NULL; |
| 1108 PurpleProtocolConversation *protocol = data; |
1088 |
| |
1089 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1090 NULL); |
| |
1091 protocol->should_error = GPOINTER_TO_INT(data); |
| 1109 |
1092 |
| 1110 account = purple_account_new("test", "test"); |
1093 account = purple_account_new("test", "test"); |
| 1111 g_object_set_data_full(G_OBJECT(protocol), "account", account, g_object_unref); |
|
| 1112 |
|
| 1113 conversation = g_object_new( |
1094 conversation = g_object_new( |
| 1114 PURPLE_TYPE_CONVERSATION, |
1095 PURPLE_TYPE_CONVERSATION, |
| 1115 "account", account, |
1096 "account", account, |
| 1116 "name", "this is required at the moment", |
1097 "name", "this is required at the moment", |
| 1117 "type", PURPLE_CONVERSATION_TYPE_DM, |
1098 "type", PURPLE_CONVERSATION_TYPE_DM, |
| 1118 NULL); |
1099 NULL); |
| 1119 g_object_set_data_full(G_OBJECT(protocol), "conversation", conversation, |
|
| 1120 g_object_unref); |
|
| 1121 |
1100 |
| 1122 message = g_object_new(PURPLE_TYPE_MESSAGE, NULL); |
1101 message = g_object_new(PURPLE_TYPE_MESSAGE, NULL); |
| 1123 g_object_set_data_full(G_OBJECT(protocol), "message", message, |
1102 purple_protocol_conversation_send_message_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| 1124 g_object_unref); |
1103 conversation, message, NULL, |
| 1125 |
|
| 1126 purple_protocol_conversation_send_message_async(protocol, conversation, |
|
| 1127 message, NULL, |
|
| 1128 test_purple_protocol_conversation_send_message_cb, |
1104 test_purple_protocol_conversation_send_message_cb, |
| 1129 NULL); |
1105 NULL); |
| 1130 |
1106 |
| 1131 return G_SOURCE_REMOVE; |
1107 g_main_context_iteration(NULL, FALSE); |
| 1132 } |
|
| 1133 |
|
| 1134 static void |
|
| 1135 test_purple_protocol_conversation_send_message_normal(gconstpointer data) { |
|
| 1136 TestPurpleProtocolConversation *protocol = NULL; |
|
| 1137 |
|
| 1138 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
|
| 1139 NULL); |
|
| 1140 protocol->should_error = GPOINTER_TO_INT(data); |
|
| 1141 |
|
| 1142 g_idle_add(test_purple_protocol_conversation_send_message_idle, protocol); |
|
| 1143 g_timeout_add_seconds(10, test_purple_protocol_conversation_timeout_cb, |
|
| 1144 loop); |
|
| 1145 |
|
| 1146 g_main_loop_run(loop); |
|
| 1147 |
1108 |
| 1148 g_assert_cmpuint(protocol->send_message_async, ==, 1); |
1109 g_assert_cmpuint(protocol->send_message_async, ==, 1); |
| 1149 g_assert_cmpuint(protocol->send_message_finish, ==, 1); |
1110 g_assert_cmpuint(protocol->send_message_finish, ==, 1); |
| 1150 |
1111 |
| 1151 g_clear_object(&protocol); |
1112 g_assert_finalize_object(message); |
| |
1113 g_assert_finalize_object(conversation); |
| |
1114 g_assert_finalize_object(protocol); |
| |
1115 g_clear_object(&account); |
| 1152 } |
1116 } |
| 1153 |
1117 |
| 1154 /****************************************************************************** |
1118 /****************************************************************************** |
| 1155 * TestProtocolConversation SetTopic Tests |
1119 * TestProtocolConversation SetTopic Tests |
| 1156 *****************************************************************************/ |
1120 *****************************************************************************/ |
| 1176 g_assert_false(result); |
1140 g_assert_false(result); |
| 1177 } else { |
1141 } else { |
| 1178 g_assert_no_error(error); |
1142 g_assert_no_error(error); |
| 1179 g_assert_true(result); |
1143 g_assert_true(result); |
| 1180 } |
1144 } |
| 1181 |
1145 } |
| 1182 g_main_loop_quit(loop); |
1146 |
| 1183 } |
1147 static void |
| 1184 |
1148 test_purple_protocol_conversation_set_topic_normal(gconstpointer data) { |
| 1185 static gboolean |
1149 TestPurpleProtocolConversation *protocol = NULL; |
| 1186 test_purple_protocol_conversation_set_topic_idle(gpointer data) { |
|
| 1187 PurpleAccount *account = NULL; |
1150 PurpleAccount *account = NULL; |
| 1188 PurpleConversation *conversation = NULL; |
1151 PurpleConversation *conversation = NULL; |
| 1189 PurpleProtocolConversation *protocol = data; |
1152 |
| |
1153 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1154 NULL); |
| |
1155 protocol->should_error = GPOINTER_TO_INT(data); |
| 1190 |
1156 |
| 1191 account = purple_account_new("test", "test"); |
1157 account = purple_account_new("test", "test"); |
| 1192 g_object_set_data_full(G_OBJECT(protocol), "account", account, g_object_unref); |
|
| 1193 |
|
| 1194 conversation = g_object_new( |
1158 conversation = g_object_new( |
| 1195 PURPLE_TYPE_CONVERSATION, |
1159 PURPLE_TYPE_CONVERSATION, |
| 1196 "account", account, |
1160 "account", account, |
| 1197 "name", "this is required at the moment", |
1161 "name", "this is required at the moment", |
| 1198 "type", PURPLE_CONVERSATION_TYPE_DM, |
1162 "type", PURPLE_CONVERSATION_TYPE_DM, |
| 1199 NULL); |
1163 NULL); |
| 1200 g_object_set_data_full(G_OBJECT(protocol), "conversation", conversation, |
1164 |
| 1201 g_object_unref); |
1165 purple_protocol_conversation_set_topic_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| 1202 |
1166 conversation, "woo hoo", NULL, |
| 1203 purple_protocol_conversation_set_topic_async(protocol, conversation, |
|
| 1204 "woo hoo", NULL, |
|
| 1205 test_purple_protocol_conversation_set_topic_cb, |
1167 test_purple_protocol_conversation_set_topic_cb, |
| 1206 NULL); |
1168 NULL); |
| 1207 |
1169 |
| 1208 return G_SOURCE_REMOVE; |
1170 g_main_context_iteration(NULL, FALSE); |
| 1209 } |
|
| 1210 |
|
| 1211 static void |
|
| 1212 test_purple_protocol_conversation_set_topic_normal(gconstpointer data) { |
|
| 1213 TestPurpleProtocolConversation *protocol = NULL; |
|
| 1214 |
|
| 1215 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
|
| 1216 NULL); |
|
| 1217 protocol->should_error = GPOINTER_TO_INT(data); |
|
| 1218 |
|
| 1219 g_idle_add(test_purple_protocol_conversation_set_topic_idle, protocol); |
|
| 1220 g_timeout_add_seconds(10, test_purple_protocol_conversation_timeout_cb, |
|
| 1221 loop); |
|
| 1222 |
|
| 1223 g_main_loop_run(loop); |
|
| 1224 |
1171 |
| 1225 g_assert_cmpuint(protocol->set_topic_async, ==, 1); |
1172 g_assert_cmpuint(protocol->set_topic_async, ==, 1); |
| 1226 g_assert_cmpuint(protocol->set_topic_finish, ==, 1); |
1173 g_assert_cmpuint(protocol->set_topic_finish, ==, 1); |
| 1227 |
1174 |
| 1228 g_clear_object(&protocol); |
1175 g_assert_finalize_object(conversation); |
| |
1176 g_assert_finalize_object(protocol); |
| |
1177 g_clear_object(&account); |
| 1229 } |
1178 } |
| 1230 |
1179 |
| 1231 /****************************************************************************** |
1180 /****************************************************************************** |
| 1232 * TestProtocolConversation Channel Join Tests |
1181 * TestProtocolConversation Channel Join Tests |
| 1233 ****************************************************************************/ |
1182 ****************************************************************************/ |
| 1278 g_assert_false(result); |
1227 g_assert_false(result); |
| 1279 } else { |
1228 } else { |
| 1280 g_assert_no_error(error); |
1229 g_assert_no_error(error); |
| 1281 g_assert_true(result); |
1230 g_assert_true(result); |
| 1282 } |
1231 } |
| 1283 |
1232 } |
| 1284 g_main_loop_quit(loop); |
1233 |
| 1285 } |
1234 static void |
| 1286 |
1235 test_purple_protocol_conversation_join_channel_normal(gconstpointer data) { |
| 1287 static gboolean |
1236 TestPurpleProtocolConversation *protocol = NULL; |
| 1288 test_purple_protocol_conversation_join_channel_idle(gpointer data) { |
|
| 1289 PurpleAccount *account = NULL; |
1237 PurpleAccount *account = NULL; |
| 1290 PurpleChannelJoinDetails *details = NULL; |
1238 PurpleChannelJoinDetails *details = NULL; |
| 1291 PurpleProtocolConversation *protocol = data; |
1239 |
| |
1240 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1241 NULL); |
| |
1242 protocol->should_error = GPOINTER_TO_INT(data); |
| 1292 |
1243 |
| 1293 account = purple_account_new("test", "test"); |
1244 account = purple_account_new("test", "test"); |
| 1294 g_object_set_data_full(G_OBJECT(protocol), "account", account, |
|
| 1295 g_object_unref); |
|
| 1296 |
|
| 1297 details = purple_channel_join_details_new(0, FALSE, 0, FALSE, 0); |
1245 details = purple_channel_join_details_new(0, FALSE, 0, FALSE, 0); |
| 1298 g_object_set_data_full(G_OBJECT(protocol), "details", details, |
1246 |
| 1299 g_object_unref); |
1247 purple_protocol_conversation_join_channel_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| 1300 |
1248 account, details, NULL, |
| 1301 purple_protocol_conversation_join_channel_async(protocol, account, details, |
|
| 1302 NULL, |
|
| 1303 test_purple_protocol_conversation_join_channel_cb, |
1249 test_purple_protocol_conversation_join_channel_cb, |
| 1304 NULL); |
1250 NULL); |
| 1305 |
1251 |
| 1306 return G_SOURCE_REMOVE; |
1252 g_main_context_iteration(NULL, FALSE); |
| 1307 } |
|
| 1308 |
|
| 1309 static void |
|
| 1310 test_purple_protocol_conversation_join_channel_normal(gconstpointer data) { |
|
| 1311 TestPurpleProtocolConversation *protocol = NULL; |
|
| 1312 |
|
| 1313 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
|
| 1314 NULL); |
|
| 1315 protocol->should_error = GPOINTER_TO_INT(data); |
|
| 1316 |
|
| 1317 g_idle_add(test_purple_protocol_conversation_join_channel_idle, protocol); |
|
| 1318 g_timeout_add_seconds(10, test_purple_protocol_conversation_timeout_cb, |
|
| 1319 loop); |
|
| 1320 |
|
| 1321 g_main_loop_run(loop); |
|
| 1322 |
1253 |
| 1323 g_assert_cmpuint(protocol->join_channel_async, ==, 1); |
1254 g_assert_cmpuint(protocol->join_channel_async, ==, 1); |
| 1324 g_assert_cmpuint(protocol->join_channel_finish, ==, 1); |
1255 g_assert_cmpuint(protocol->join_channel_finish, ==, 1); |
| 1325 |
1256 |
| 1326 g_clear_object(&protocol); |
1257 g_assert_finalize_object(protocol); |
| |
1258 g_assert_finalize_object(details); |
| |
1259 g_clear_object(&account); |
| 1327 } |
1260 } |
| 1328 |
1261 |
| 1329 /****************************************************************************** |
1262 /****************************************************************************** |
| 1330 * TestProtocolConversation SetAvatar Tests |
1263 * TestProtocolConversation SetAvatar Tests |
| 1331 *****************************************************************************/ |
1264 *****************************************************************************/ |
| 1351 g_assert_false(result); |
1284 g_assert_false(result); |
| 1352 } else { |
1285 } else { |
| 1353 g_assert_no_error(error); |
1286 g_assert_no_error(error); |
| 1354 g_assert_true(result); |
1287 g_assert_true(result); |
| 1355 } |
1288 } |
| 1356 |
1289 } |
| 1357 g_main_loop_quit(loop); |
1290 |
| 1358 } |
1291 static void |
| 1359 |
1292 test_purple_protocol_conversation_set_avatar_normal(gconstpointer data) { |
| 1360 static gboolean |
1293 TestPurpleProtocolConversation *protocol = NULL; |
| 1361 test_purple_protocol_conversation_set_avatar_idle(gpointer data) { |
|
| 1362 PurpleAccount *account = NULL; |
1294 PurpleAccount *account = NULL; |
| 1363 PurpleConversation *conversation = NULL; |
1295 PurpleConversation *conversation = NULL; |
| 1364 PurpleProtocolConversation *protocol = data; |
1296 |
| |
1297 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
| |
1298 NULL); |
| |
1299 protocol->should_error = GPOINTER_TO_INT(data); |
| 1365 |
1300 |
| 1366 account = purple_account_new("test", "test"); |
1301 account = purple_account_new("test", "test"); |
| 1367 g_object_set_data_full(G_OBJECT(protocol), "account", account, |
|
| 1368 g_object_unref); |
|
| 1369 |
|
| 1370 conversation = g_object_new( |
1302 conversation = g_object_new( |
| 1371 PURPLE_TYPE_CONVERSATION, |
1303 PURPLE_TYPE_CONVERSATION, |
| 1372 "account", account, |
1304 "account", account, |
| 1373 "name", "this is required at the moment", |
1305 "name", "this is required at the moment", |
| 1374 "type", PURPLE_CONVERSATION_TYPE_DM, |
1306 "type", PURPLE_CONVERSATION_TYPE_DM, |
| 1375 NULL); |
1307 NULL); |
| 1376 g_object_set_data_full(G_OBJECT(protocol), "conversation", conversation, |
1308 |
| 1377 g_object_unref); |
1309 purple_protocol_conversation_set_avatar_async(PURPLE_PROTOCOL_CONVERSATION(protocol), |
| 1378 |
1310 conversation, NULL, NULL, |
| 1379 purple_protocol_conversation_set_avatar_async(protocol, conversation, |
|
| 1380 NULL, NULL, |
|
| 1381 test_purple_protocol_conversation_set_avatar_cb, |
1311 test_purple_protocol_conversation_set_avatar_cb, |
| 1382 NULL); |
1312 NULL); |
| 1383 |
1313 |
| 1384 return G_SOURCE_REMOVE; |
1314 g_main_context_iteration(NULL, FALSE); |
| 1385 } |
|
| 1386 |
|
| 1387 static void |
|
| 1388 test_purple_protocol_conversation_set_avatar_normal(gconstpointer data) { |
|
| 1389 TestPurpleProtocolConversation *protocol = NULL; |
|
| 1390 |
|
| 1391 protocol = g_object_new(test_purple_protocol_conversation_get_type(), |
|
| 1392 NULL); |
|
| 1393 protocol->should_error = GPOINTER_TO_INT(data); |
|
| 1394 |
|
| 1395 g_idle_add(test_purple_protocol_conversation_set_avatar_idle, protocol); |
|
| 1396 g_timeout_add_seconds(10, test_purple_protocol_conversation_timeout_cb, |
|
| 1397 loop); |
|
| 1398 |
|
| 1399 g_main_loop_run(loop); |
|
| 1400 |
1315 |
| 1401 g_assert_cmpuint(protocol->set_avatar_async, ==, 1); |
1316 g_assert_cmpuint(protocol->set_avatar_async, ==, 1); |
| 1402 g_assert_cmpuint(protocol->set_avatar_finish, ==, 1); |
1317 g_assert_cmpuint(protocol->set_avatar_finish, ==, 1); |
| 1403 |
1318 |
| 1404 g_clear_object(&protocol); |
1319 g_assert_finalize_object(conversation); |
| |
1320 g_assert_finalize_object(protocol); |
| |
1321 g_clear_object(&account); |
| 1405 } |
1322 } |
| 1406 |
1323 |
| 1407 /****************************************************************************** |
1324 /****************************************************************************** |
| 1408 * TestProtocolConversation Send Typing Tests |
1325 * TestProtocolConversation Send Typing Tests |
| 1409 ****************************************************************************/ |
1326 ****************************************************************************/ |
| 1452 /****************************************************************************** |
1369 /****************************************************************************** |
| 1453 * Main |
1370 * Main |
| 1454 *****************************************************************************/ |
1371 *****************************************************************************/ |
| 1455 gint |
1372 gint |
| 1456 main(int argc, char **argv) { |
1373 main(int argc, char **argv) { |
| 1457 int ret = 0; |
|
| 1458 |
|
| 1459 g_test_init(&argc, &argv, NULL); |
1374 g_test_init(&argc, &argv, NULL); |
| 1460 |
1375 |
| 1461 g_test_set_nonfatal_assertions(); |
1376 g_test_set_nonfatal_assertions(); |
| 1462 |
|
| 1463 test_ui_purple_init(); |
|
| 1464 |
|
| 1465 loop = g_main_loop_new(NULL, FALSE); |
|
| 1466 |
1377 |
| 1467 /* Empty create conversation tests. */ |
1378 /* Empty create conversation tests. */ |
| 1468 g_test_add_func("/protocol-conversation/empty/implements-create-conversation", |
1379 g_test_add_func("/protocol-conversation/empty/implements-create-conversation", |
| 1469 test_purple_protocol_conversation_empty_implements_create_conversation); |
1380 test_purple_protocol_conversation_empty_implements_create_conversation); |
| 1470 g_test_add_func("/protocol-conversation/empty/get-create-conversation-details", |
1381 g_test_add_func("/protocol-conversation/empty/get-create-conversation-details", |