From e61b38b9a3480b5110c7df418027260557fcc156 Mon Sep 17 00:00:00 2001 From: frekky Date: Mon, 12 Oct 2015 18:39:24 +0800 Subject: [PATCH] Updated user and window tests --- tests/user.c | 16 +++++++--------- tests/window.c | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/user.c b/tests/user.c index b1607ee..d8118fe 100644 --- a/tests/user.c +++ b/tests/user.c @@ -28,6 +28,8 @@ #include "user.h" #include "test.h" +int debug = 0; + START_TEST(test_init_users) { in_addr_t ip; @@ -39,9 +41,9 @@ START_TEST(test_init_users) count = init_users(ip, 27); for (i = 0; i < count; i++) { fail_unless(users[i].id == i); - fail_unless(users[i].q.id == 0); snprintf(givenip, sizeof(givenip), "127.0.0.%d", i + 2); fail_unless(users[i].tun_ip == inet_addr(givenip)); + fail_if(user_active(i), "user_active true for new users"); } } END_TEST @@ -78,28 +80,24 @@ START_TEST(test_find_user_by_ip) } END_TEST -extern unsigned usercount; START_TEST(test_all_users_waiting_to_send) { in_addr_t ip; ip = inet_addr("127.0.0.1"); init_users(ip, 27); - for (int i = 0; i < usercount; i++) users[i].outgoing = window_buffer_init(10, 1, 10, WINDOW_SENDING); - fail_if(all_users_waiting_to_send() == 1); + fail_unless(all_users_waiting_to_send() == 0, "empty user list all waiting to send"); users[0].conn = CONN_DNS_NULL; users[0].active = 1; - fail_if(all_users_waiting_to_send() == 1); + fail_unless(all_users_waiting_to_send() == 0, "single user with empty buffer waiting to send"); users[0].last_pkt = time(NULL); - fail_unless(all_users_waiting_to_send() == 0); + fail_unless(all_users_waiting_to_send() == 0, "single active user with empty buffer waiting to send"); - - fail_unless(all_users_waiting_to_send() == 1); } END_TEST @@ -171,7 +169,7 @@ test_user_create_tests() tc = tcase_create("User"); tcase_add_test(tc, test_init_users); tcase_add_test(tc, test_find_user_by_ip); -// tcase_add_test(tc, test_all_users_waiting_to_send); + tcase_add_test(tc, test_all_users_waiting_to_send); tcase_add_test(tc, test_find_available_user); tcase_add_test(tc, test_find_available_user_small_net); diff --git a/tests/window.c b/tests/window.c index 6b3975e..393814e 100644 --- a/tests/window.c +++ b/tests/window.c @@ -50,12 +50,12 @@ START_TEST(test_window_everything) // warnx("Nothing to send."); continue; } - fail_if(!window_process_incoming_fragment(in, f), "Incoming fragment failed!"); + fail_if((a = window_process_incoming_fragment(in, f)) != f->seqID, "Did not ACK last seqId!"); // warnx("Received fragment with seqid %u, remaining space %lu.", f->seqID, window_buffer_available(in)); - int a = window_get_next_ack(in); window_tick(in); window_ack(out, a); window_tick(out); + fail_if(out->start_seq_id != in->start_seq_id, "in/out windows have different start IDs!"); } // warnx("Added %lu fragments, reassembling into data.", in->numitems); uint8_t data[100]; @@ -72,7 +72,7 @@ START_TEST(test_window_everything) // printf("%c", data[i]); // } // printf("'\n"); - strncat((char *)newdata, data, len); + strncat((char *)newdata, (char *)data, len); if (in->numitems <= 0) break; } // printf("New data: '%s' (%lu)\n", newdata, strlen((char *)newdata));