summaryrefslogtreecommitdiff
path: root/auto_tests/tox_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests/tox_test.c')
-rw-r--r--auto_tests/tox_test.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 2c157b1c..7e375db0 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -21,18 +21,18 @@
21#define c_sleep(x) usleep(1000*x) 21#define c_sleep(x) usleep(1000*x)
22#endif 22#endif
23 23
24void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) 24void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
25{ 25{
26 if (*((uint32_t *)userdata) != 974536) 26 if (*((uint32_t *)userdata) != 974536)
27 return; 27 return;
28 28
29 if (length == 7 && memcmp("Gentoo", data, 7) == 0) { 29 if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
30 tox_add_friend_norequest(m, public_key); 30 tox_friend_add_norequest(m, public_key, 0);
31 } 31 }
32} 32}
33uint32_t messages_received; 33uint32_t messages_received;
34 34
35void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata) 35void print_message(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
36{ 36{
37 if (*((uint32_t *)userdata) != 974536) 37 if (*((uint32_t *)userdata) != 974536)
38 return; 38 return;
@@ -46,7 +46,7 @@ void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t len
46 46
47uint32_t name_changes; 47uint32_t name_changes;
48 48
49void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata) 49void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
50{ 50{
51 if (*((uint32_t *)userdata) != 974536) 51 if (*((uint32_t *)userdata) != 974536)
52 return; 52 return;
@@ -57,7 +57,7 @@ void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t
57 57
58uint32_t typing_changes; 58uint32_t typing_changes;
59 59
60void print_typingchange(Tox *m, int friendnumber, uint8_t typing, void *userdata) 60void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata)
61{ 61{
62 if (*((uint32_t *)userdata) != 974536) 62 if (*((uint32_t *)userdata) != 974536)
63 return; 63 return;
@@ -144,27 +144,35 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *dat
144 144
145START_TEST(test_one) 145START_TEST(test_one)
146{ 146{
147 Tox *tox1 = tox_new(0); 147 Tox *tox1 = tox_new(0, 0, 0, 0);
148 Tox *tox2 = tox_new(0); 148 Tox *tox2 = tox_new(0, 0, 0, 0);
149 149
150 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 150 uint8_t address[TOX_ADDRESS_SIZE];
151 tox_get_address(tox1, address); 151 tox_self_get_address(tox1, address);
152 ck_assert_msg(tox_add_friend(tox1, address, (uint8_t *)"m", 1) == TOX_FAERR_OWNKEY, "Adding own address worked."); 152 TOX_ERR_FRIEND_ADD error;
153 153 uint32_t ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error);
154 tox_get_address(tox2, address); 154 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked.");
155 uint8_t message[TOX_MAX_FRIENDREQUEST_LENGTH + 1]; 155
156 ck_assert_msg(tox_add_friend(tox1, address, NULL, 0) == TOX_FAERR_NOMESSAGE, "Sending request with no message worked."); 156 tox_self_get_address(tox2, address);
157 ck_assert_msg(tox_add_friend(tox1, address, message, sizeof(message)) == TOX_FAERR_TOOLONG, 157 uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH + 1];
158 "TOX_MAX_FRIENDREQUEST_LENGTH is too big."); 158 ret = tox_friend_add(tox1, address, NULL, 0, &error);
159 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NULL, "Sending request with no message worked.");
160 ret = tox_friend_add(tox1, address, message, 0, &error);
161 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NO_MESSAGE, "Sending request with no message worked.");
162 ret = tox_friend_add(tox1, address, message, sizeof(message), &error);
163 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_TOO_LONG,
164 "TOX_MAX_FRIEND_REQUEST_LENGTH is too big.");
159 165
160 address[0]++; 166 address[0]++;
161 ck_assert_msg(tox_add_friend(tox1, address, (uint8_t *)"m", 1) == TOX_FAERR_BADCHECKSUM, 167 ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error);
168 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_BAD_CHECKSUM,
162 "Adding address with bad checksum worked."); 169 "Adding address with bad checksum worked.");
163 170
164 tox_get_address(tox2, address); 171 tox_self_get_address(tox2, address);
165 ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == 0, "Failed to add friend."); 172 ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
166 ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == TOX_FAERR_ALREADYSENT, 173 ck_assert_msg(ret == 0 && error == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend.");
167 "Adding friend twice worked."); 174 ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
175 ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_ALREADY_SENT, "Adding friend twice worked.");
168 176
169 uint8_t name[TOX_MAX_NAME_LENGTH]; 177 uint8_t name[TOX_MAX_NAME_LENGTH];
170 int i; 178 int i;
@@ -173,22 +181,23 @@ START_TEST(test_one)
173 name[i] = rand(); 181 name[i] = rand();
174 } 182 }
175 183
176 tox_set_name(tox1, name, sizeof(name)); 184 tox_self_set_name(tox1, name, sizeof(name), 0);
177 ck_assert_msg(tox_get_self_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); 185 ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
178 186
179 size_t save_size = tox_size(tox1); 187 size_t save_size = tox_save_size(tox1);
180 uint8_t data[save_size]; 188 uint8_t data[save_size];
181 tox_save(tox1, data); 189 tox_save(tox1, data);
182 190
183 tox_kill(tox2); 191 tox_kill(tox2);
184 tox2 = tox_new(0); 192 TOX_ERR_NEW err_n;
185 ck_assert_msg(tox_load(tox2, data, save_size) == 0, "Load failed"); 193
194 tox2 = tox_new(0, data, save_size, &err_n);
195 ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed");
186 196
187 size_t length = tox_get_self_name_size(tox2); 197 ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size.");
188 ck_assert_msg(tox_get_self_name_size(tox2) == sizeof name, "Wrong name size.");
189 198
190 uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; 199 uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 };
191 ck_assert_msg(tox_get_self_name(tox2, new_name) == TOX_MAX_NAME_LENGTH, "Wrong name length"); 200 tox_self_get_name(tox2, new_name);
192 ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); 201 ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name");
193 202
194 tox_kill(tox1); 203 tox_kill(tox1);