diff options
author | Jfreegman <jfreegman@gmail.com> | 2016-09-17 17:32:25 -0400 |
---|---|---|
committer | Jfreegman <jfreegman@gmail.com> | 2016-09-17 19:11:28 -0400 |
commit | 8e43ca834cc0a5b2f904ce2589154c2f17bd12ce (patch) | |
tree | e88701e5dfe6a623c7fe7f60ba2ddb304ffadc07 /auto_tests | |
parent | c0397a0a4614671679d409c428b47549a01fdf7f (diff) |
Complete old groupchat conversion to new API
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/tox_test.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 14510ea4..79197d7f 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <sys/param.h> | 22 | #include <sys/param.h> |
23 | #include <sys/types.h> | 23 | #include <sys/types.h> |
24 | #include <time.h> | 24 | #include <time.h> |
25 | #include <inttypes.h> | ||
25 | 26 | ||
26 | #include "../toxcore/tox.h" | 27 | #include "../toxcore/tox.h" |
27 | #include "../toxcore/util.h" | 28 | #include "../toxcore/util.h" |
@@ -1184,9 +1185,9 @@ static void print_group_invite_callback(Tox *tox, uint32_t friendnumber, TOX_CON | |||
1184 | return; | 1185 | return; |
1185 | } | 1186 | } |
1186 | 1187 | ||
1187 | int g_num; | 1188 | uint32_t g_num; |
1188 | 1189 | ||
1189 | if ((g_num = tox_conference_join(tox, friendnumber, data, length, NULL)) == -1) { | 1190 | if ((g_num = tox_conference_join(tox, friendnumber, data, length, NULL)) == UINT32_MAX) { |
1190 | return; | 1191 | return; |
1191 | } | 1192 | } |
1192 | 1193 | ||
@@ -1215,13 +1216,16 @@ static void print_group_message(Tox *tox, uint32_t groupnumber, uint32_t peernum | |||
1215 | 1216 | ||
1216 | START_TEST(test_many_group) | 1217 | START_TEST(test_many_group) |
1217 | { | 1218 | { |
1218 | long long unsigned int cur_time = time(NULL); | 1219 | long long unsigned int test_start_time = time(NULL); |
1220 | |||
1221 | group_test_restart: | ||
1222 | ; | ||
1223 | |||
1219 | Tox *toxes[NUM_GROUP_TOX]; | 1224 | Tox *toxes[NUM_GROUP_TOX]; |
1220 | unsigned int i, j, k; | 1225 | unsigned int i, j, k; |
1221 | uint32_t to_comp = 234212; | 1226 | uint32_t to_comp = 234212; |
1222 | int test_run = 0; | 1227 | int test_run = 0; |
1223 | 1228 | long long unsigned int cur_time = time(NULL); | |
1224 | group_test_restart: | ||
1225 | 1229 | ||
1226 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1230 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1227 | toxes[i] = tox_new(0, 0); | 1231 | toxes[i] = tox_new(0, 0); |
@@ -1265,9 +1269,9 @@ group_test_restart: | |||
1265 | 1269 | ||
1266 | printf("friends connected, took %llu seconds\n", time(NULL) - cur_time); | 1270 | printf("friends connected, took %llu seconds\n", time(NULL) - cur_time); |
1267 | 1271 | ||
1268 | ck_assert_msg(tox_conference_new(toxes[0], NULL) != -1, "Failed to create group"); | 1272 | ck_assert_msg(tox_conference_new(toxes[0], NULL) != UINT32_MAX, "Failed to create group"); |
1269 | ck_assert_msg(tox_conference_invite(toxes[0], 0, 0, NULL) == 0, "Failed to invite friend"); | 1273 | ck_assert_msg(tox_conference_invite(toxes[0], 0, 0, NULL) != 0, "Failed to invite friend"); |
1270 | ck_assert_msg(tox_conference_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1, NULL) == 0, | 1274 | ck_assert_msg(tox_conference_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1, NULL) != 0, |
1271 | "Failed to set group title"); | 1275 | "Failed to set group title"); |
1272 | invite_counter = ~0; | 1276 | invite_counter = ~0; |
1273 | 1277 | ||
@@ -1280,7 +1284,7 @@ group_test_restart: | |||
1280 | } | 1284 | } |
1281 | 1285 | ||
1282 | if (!invite_counter) { | 1286 | if (!invite_counter) { |
1283 | ck_assert_msg(tox_conference_invite(invite_tox, 0, 0, NULL) == 0, "Failed to invite friend"); | 1287 | ck_assert_msg(tox_conference_invite(invite_tox, 0, 0, NULL) != 0, "Failed to invite friend"); |
1284 | } | 1288 | } |
1285 | 1289 | ||
1286 | if (done == invite_counter) { | 1290 | if (done == invite_counter) { |
@@ -1292,15 +1296,16 @@ group_test_restart: | |||
1292 | } | 1296 | } |
1293 | 1297 | ||
1294 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1298 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1295 | int num_peers = tox_conference_peer_count(toxes[i], 0, NULL); | 1299 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL); |
1296 | 1300 | ||
1297 | /** | 1301 | /** |
1298 | * Group chats fail unpredictably, currently they'll rerun as many times | 1302 | * Group chats fail unpredictably, currently they'll rerun as many times |
1299 | * as they need to until they pass the test, or the time out is reached | 1303 | * as they need to until they pass the test, or the time out is reached |
1300 | * Either way in this case it's fine */ | 1304 | * Either way in this case it's fine */ |
1301 | if (num_peers != NUM_GROUP_TOX) { | 1305 | if (peer_count != NUM_GROUP_TOX) { |
1302 | ++test_run; | 1306 | ++test_run; |
1303 | printf("\tError starting up the first group, going to restart this test. This is attempt %i\n", test_run); | 1307 | printf("\tError starting up the first group (peer_count %"PRIu32" != %d, test_run = %d)\n", peer_count, NUM_GROUP_TOX, |
1308 | test_run); | ||
1304 | 1309 | ||
1305 | for (j = 0; j < NUM_GROUP_TOX; ++j) { | 1310 | for (j = 0; j < NUM_GROUP_TOX; ++j) { |
1306 | tox_kill(toxes[j]); | 1311 | tox_kill(toxes[j]); |
@@ -1317,14 +1322,14 @@ group_test_restart: | |||
1317 | * restart this test once, in which case this check will become | 1322 | * restart this test once, in which case this check will become |
1318 | * important again. | 1323 | * important again. |
1319 | */ | 1324 | */ |
1320 | ck_assert_msg(num_peers == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." | 1325 | ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." |
1321 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %i\n\n", | 1326 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n", |
1322 | NUM_GROUP_TOX, i, num_peers); | 1327 | NUM_GROUP_TOX, i, peer_count); |
1323 | 1328 | ||
1324 | uint8_t title[2048]; | 1329 | uint8_t title[2048]; |
1325 | int ret = tox_conference_get_title_size(toxes[i], 0, NULL); | 1330 | size_t ret = tox_conference_get_title_size(toxes[i], 0, NULL); |
1326 | tox_conference_get_title(toxes[i], 0, title, NULL); | ||
1327 | ck_assert_msg(ret == sizeof("Gentoo") - 1, "Wrong title length"); | 1331 | ck_assert_msg(ret == sizeof("Gentoo") - 1, "Wrong title length"); |
1332 | tox_conference_get_title(toxes[i], 0, title, NULL); | ||
1328 | ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title"); | 1333 | ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title"); |
1329 | } | 1334 | } |
1330 | 1335 | ||
@@ -1337,7 +1342,7 @@ group_test_restart: | |||
1337 | ck_assert_msg( | 1342 | ck_assert_msg( |
1338 | tox_conference_send_message( | 1343 | tox_conference_send_message( |
1339 | toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo", | 1344 | toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo", |
1340 | sizeof("Install Gentoo") - 1, NULL) == 0, "Failed to send group message."); | 1345 | sizeof("Install Gentoo") - 1, NULL) != 0, "Failed to send group message."); |
1341 | num_recv = 0; | 1346 | num_recv = 0; |
1342 | 1347 | ||
1343 | for (j = 0; j < 20; ++j) { | 1348 | for (j = 0; j < 20; ++j) { |
@@ -1363,10 +1368,10 @@ group_test_restart: | |||
1363 | } | 1368 | } |
1364 | 1369 | ||
1365 | for (i = 0; i < (k - 1); ++i) { | 1370 | for (i = 0; i < (k - 1); ++i) { |
1366 | int num_peers = tox_conference_peer_count(toxes[i], 0, NULL); | 1371 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL); |
1367 | ck_assert_msg(num_peers == (k - 1), "\n\tBad number of group peers (post check)." | 1372 | ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." |
1368 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %i\n\n", | 1373 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n", |
1369 | (k - 1), i, num_peers); | 1374 | (k - 1), i, peer_count); |
1370 | } | 1375 | } |
1371 | } | 1376 | } |
1372 | 1377 | ||
@@ -1374,7 +1379,7 @@ group_test_restart: | |||
1374 | tox_kill(toxes[i]); | 1379 | tox_kill(toxes[i]); |
1375 | } | 1380 | } |
1376 | 1381 | ||
1377 | printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - cur_time); | 1382 | printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - test_start_time); |
1378 | } | 1383 | } |
1379 | END_TEST | 1384 | END_TEST |
1380 | 1385 | ||