summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-07 10:18:55 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-07 10:35:35 +0000
commit3c1025d2dc07b41fd5c0b621e68be3a7c85611d8 (patch)
treeefc54759165e9e9613c488a0a2df94e00c880122 /auto_tests
parent9d5c55b4b39da2a99ef00449fd4f9701ddcd5b2a (diff)
Factor out the actual test code from conference_test.
Also, renamed simple_conference_test to conference_simple_test so it's sorted together with the other conference tests. Next step is to use run_auto_test.h for the conference test.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/conference_simple_test.c (renamed from auto_tests/simple_conference_test.c)0
-rw-r--r--auto_tests/conference_test.c106
-rw-r--r--auto_tests/monolith_test.cc8
3 files changed, 62 insertions, 52 deletions
diff --git a/auto_tests/simple_conference_test.c b/auto_tests/conference_simple_test.c
index 3e2f0f94..3e2f0f94 100644
--- a/auto_tests/simple_conference_test.c
+++ b/auto_tests/conference_simple_test.c
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index 9f8352a3..caa00356 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -24,7 +24,8 @@
24#define NUM_GROUP_TOX 5 24#define NUM_GROUP_TOX 5
25#define GROUP_MESSAGE "Install Gentoo" 25#define GROUP_MESSAGE "Install Gentoo"
26 26
27static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) 27static void handle_self_connection_status(
28 Tox *tox, TOX_CONNECTION connection_status, void *user_data)
28{ 29{
29 const int id = *(int *)user_data; 30 const int id = *(int *)user_data;
30 31
@@ -35,8 +36,8 @@ static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_st
35 } 36 }
36} 37}
37 38
38static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, 39static void handle_friend_connection_status(
39 void *user_data) 40 Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *user_data)
40{ 41{
41 const int id = *(int *)user_data; 42 const int id = *(int *)user_data;
42 43
@@ -47,8 +48,9 @@ static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX
47 } 48 }
48} 49}
49 50
50static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data, 51static void handle_conference_invite(
51 size_t length, void *user_data) 52 Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type,
53 const uint8_t *data, size_t length, void *user_data)
52{ 54{
53 const int id = *(int *)user_data; 55 const int id = *(int *)user_data;
54 ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type); 56 ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);
@@ -74,14 +76,61 @@ static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFER
74 76
75static unsigned int num_recv; 77static unsigned int num_recv;
76 78
77static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, 79static void handle_conference_message(
78 const uint8_t *message, size_t length, void *user_data) 80 Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
81 const uint8_t *message, size_t length, void *user_data)
79{ 82{
80 if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) { 83 if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
81 ++num_recv; 84 ++num_recv;
82 } 85 }
83} 86}
84 87
88static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
89{
90 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
91 tox_callback_conference_message(toxes[i], &handle_conference_message);
92 }
93
94 TOX_ERR_CONFERENCE_SEND_MESSAGE err;
95 ck_assert_msg(
96 tox_conference_send_message(
97 toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
98 sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
99 ck_assert_msg(
100 err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
101 num_recv = 0;
102
103 for (unsigned j = 0; j < 20; ++j) {
104 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
105 tox_iterate(toxes[i], &tox_index[i]);
106 }
107
108 c_sleep(25);
109 }
110
111 c_sleep(25);
112 ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
113
114 for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
115 tox_conference_delete(toxes[k - 1], 0, nullptr);
116
117 for (unsigned j = 0; j < 10; ++j) {
118 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
119 tox_iterate(toxes[i], &tox_index[i]);
120 }
121
122 c_sleep(50);
123 }
124
125 for (unsigned i = 0; i < k - 1; ++i) {
126 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
127 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
128 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
129 (k - 1), i, peer_count);
130 }
131 }
132}
133
85static void test_many_group(void) 134static void test_many_group(void)
86{ 135{
87 const time_t test_start_time = time(nullptr); 136 const time_t test_start_time = time(nullptr);
@@ -203,48 +252,9 @@ static void test_many_group(void)
203 252
204 printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time)); 253 printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time));
205 254
206 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { 255 run_conference_tests(toxes, tox_index);
207 tox_callback_conference_message(toxes[i], &handle_conference_message);
208 }
209
210 TOX_ERR_CONFERENCE_SEND_MESSAGE err;
211 ck_assert_msg(
212 tox_conference_send_message(
213 toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
214 sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
215 ck_assert_msg(
216 err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
217 num_recv = 0;
218
219 for (unsigned j = 0; j < 20; ++j) {
220 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
221 tox_iterate(toxes[i], &tox_index[i]);
222 }
223
224 c_sleep(25);
225 }
226 256
227 c_sleep(25); 257 printf("tearing down toxes\n");
228 ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
229
230 for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
231 tox_conference_delete(toxes[k - 1], 0, nullptr);
232
233 for (unsigned j = 0; j < 10; ++j) {
234 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
235 tox_iterate(toxes[i], &tox_index[i]);
236 }
237
238 c_sleep(50);
239 }
240
241 for (unsigned i = 0; i < k - 1; ++i) {
242 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
243 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
244 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
245 (k - 1), i, peer_count);
246 }
247 }
248 258
249 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { 259 for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
250 tox_kill(toxes[i]); 260 tox_kill(toxes[i]);
diff --git a/auto_tests/monolith_test.cc b/auto_tests/monolith_test.cc
index d89c7625..45d55958 100644
--- a/auto_tests/monolith_test.cc
+++ b/auto_tests/monolith_test.cc
@@ -33,6 +33,10 @@ namespace bootstrap_test {
33int main(void); 33int main(void);
34#include "bootstrap_test.c" 34#include "bootstrap_test.c"
35} // namespace bootstrap_test 35} // namespace bootstrap_test
36namespace conference_simple_test {
37int main(void);
38#include "conference_simple_test.c"
39} // namespace conference_simple_test
36namespace conference_test { 40namespace conference_test {
37int main(void); 41int main(void);
38#include "conference_test.c" 42#include "conference_test.c"
@@ -101,10 +105,6 @@ namespace set_status_message_test {
101int main(void); 105int main(void);
102#include "set_status_message_test.c" 106#include "set_status_message_test.c"
103} // namespace set_status_message_test 107} // namespace set_status_message_test
104namespace simple_conference_test {
105int main(void);
106#include "simple_conference_test.c"
107} // namespace simple_conference_test
108namespace skeleton_test { 108namespace skeleton_test {
109int main(void); 109int main(void);
110#include "skeleton_test.c" 110#include "skeleton_test.c"