summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-12-15 17:35:54 +0000
committeriphydf <iphydf@users.noreply.github.com>2016-12-22 10:53:39 +0000
commitdb71602731da030c999f2821b2b4a64611b90b99 (patch)
treed90d14a7b1a467111d75984137e9ca41fc02abe7 /auto_tests
parent2328cb74abccd563f0cd8d14d30e5314822d321e (diff)
Use `tox_options_set_*` instead of direct member access.
Also added a `tox_options_copy` function for cloning an options object. This can be useful when creating several Tox instances with slightly varying options.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/encryptsave_test.c21
-rw-r--r--auto_tests/helpers.h2
-rw-r--r--auto_tests/save_friend_test.c17
-rw-r--r--auto_tests/tox_many_tcp_test.c22
-rw-r--r--auto_tests/tox_one_test.c30
-rw-r--r--auto_tests/tox_test.c11
6 files changed, 44 insertions, 59 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index ec98797c..22c585ed 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -77,14 +77,12 @@ START_TEST(test_save_friend)
77 ck_assert_msg(ret, "failed to encrypted save: %u", error1); 77 ck_assert_msg(ret, "failed to encrypted save: %u", error1);
78 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); 78 ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing");
79 79
80 struct Tox_Options options; 80 struct Tox_Options *options = tox_options_new(NULL);
81 tox_options_default(&options); 81 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
82 options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; 82 tox_options_set_savedata_data(options, enc_data, size2);
83 options.savedata_data = enc_data;
84 options.savedata_length = size2;
85 83
86 TOX_ERR_NEW err2; 84 TOX_ERR_NEW err2;
87 Tox *tox3 = tox_new_log(&options, &err2, 0); 85 Tox *tox3 = tox_new_log(options, &err2, 0);
88 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, 86 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2,
89 TOX_ERR_NEW_LOAD_ENCRYPTED); 87 TOX_ERR_NEW_LOAD_ENCRYPTED);
90 ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL"); 88 ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL");
@@ -92,9 +90,8 @@ START_TEST(test_save_friend)
92 TOX_ERR_DECRYPTION err3; 90 TOX_ERR_DECRYPTION err3;
93 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); 91 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3);
94 ck_assert_msg(ret, "failed to decrypt save: %u", err3); 92 ck_assert_msg(ret, "failed to decrypt save: %u", err3);
95 options.savedata_data = dec_data; 93 tox_options_set_savedata_data(options, dec_data, size);
96 options.savedata_length = size; 94 tox3 = tox_new_log(options, &err2, 0);
97 tox3 = tox_new_log(&options, &err2, 0);
98 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); 95 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2);
99 uint8_t address2[TOX_PUBLIC_KEY_SIZE]; 96 uint8_t address2[TOX_PUBLIC_KEY_SIZE];
100 ret = tox_friend_get_public_key(tox3, 0, address2, 0); 97 ret = tox_friend_get_public_key(tox3, 0, address2, 0);
@@ -123,9 +120,8 @@ START_TEST(test_save_friend)
123 120
124 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste 121 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste
125 // to remove the manual check now that it's there) 122 // to remove the manual check now that it's there)
126 options.savedata_data = out1; 123 tox_options_set_savedata_data(options, out1, size);
127 options.savedata_length = size; 124 Tox *tox4 = tox_new_log(options, &err2, 0);
128 Tox *tox4 = tox_new_log(&options, &err2, 0);
129 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); 125 ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third");
130 uint8_t address5[TOX_PUBLIC_KEY_SIZE]; 126 uint8_t address5[TOX_PUBLIC_KEY_SIZE];
131 ret = tox_friend_get_public_key(tox4, 0, address5, 0); 127 ret = tox_friend_get_public_key(tox4, 0, address5, 0);
@@ -133,6 +129,7 @@ START_TEST(test_save_friend)
133 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the third"); 129 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the third");
134 130
135 tox_pass_key_free(key); 131 tox_pass_key_free(key);
132 tox_options_free(options);
136 133
137 tox_kill(tox1); 134 tox_kill(tox1);
138 tox_kill(tox2); 135 tox_kill(tox2);
diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h
index 99930e90..c3b87caa 100644
--- a/auto_tests/helpers.h
+++ b/auto_tests/helpers.h
@@ -53,7 +53,7 @@ Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_d
53 struct Tox_Options *my_options = tox_options_new(NULL); 53 struct Tox_Options *my_options = tox_options_new(NULL);
54 54
55 if (options != NULL) { 55 if (options != NULL) {
56 *my_options = *options; 56 tox_options_copy(my_options, options);
57 } 57 }
58 58
59 tox_options_set_log_callback(my_options, &print_debug_log); 59 tox_options_set_log_callback(my_options, &print_debug_log);
diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c
index db59a24a..9d36ff2d 100644
--- a/auto_tests/save_friend_test.c
+++ b/auto_tests/save_friend_test.c
@@ -1,7 +1,7 @@
1/* Auto Tests: Save and load friends. 1/* Auto Tests: Save and load friends.
2 */ 2 */
3 3
4#include "../toxcore/tox.h" 4#include "helpers.h"
5 5
6#include <assert.h> 6#include <assert.h>
7#include <stdio.h> 7#include <stdio.h>
@@ -51,8 +51,8 @@ void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *mess
51 51
52int main(int argc, char *argv[]) 52int main(int argc, char *argv[])
53{ 53{
54 Tox *tox1 = tox_new(tox_options_new(NULL), 0); 54 Tox *tox1 = tox_new_log(0, 0, 0);
55 Tox *tox2 = tox_new(tox_options_new(NULL), 0); 55 Tox *tox2 = tox_new_log(0, 0, 0);
56 56
57 struct test_data to_compare = { { 0 } }; 57 struct test_data to_compare = { { 0 } };
58 58
@@ -106,13 +106,11 @@ int main(int argc, char *argv[])
106 uint8_t savedata[save_size]; 106 uint8_t savedata[save_size];
107 tox_get_savedata(tox1, savedata); 107 tox_get_savedata(tox1, savedata);
108 108
109 struct Tox_Options options; 109 struct Tox_Options *options = tox_options_new(NULL);
110 tox_options_default(&options); 110 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
111 options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; 111 tox_options_set_savedata_data(options, savedata, save_size);
112 options.savedata_data = savedata;
113 options.savedata_length = save_size;
114 112
115 Tox *tox_to_compare = tox_new(&options, 0); 113 Tox *tox_to_compare = tox_new(options, 0);
116 114
117 tox_friend_get_name(tox_to_compare, 0, to_compare.name, 0); 115 tox_friend_get_name(tox_to_compare, 0, to_compare.name, 0);
118 tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, 0); 116 tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, 0);
@@ -120,6 +118,7 @@ int main(int argc, char *argv[])
120 assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0); 118 assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0);
121 assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0); 119 assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0);
122 120
121 tox_options_free(options);
123 tox_kill(tox1); 122 tox_kill(tox1);
124 tox_kill(tox2); 123 tox_kill(tox2);
125 tox_kill(tox_to_compare); 124 tox_kill(tox_to_compare);
diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c
index f802bf57..197c6e47 100644
--- a/auto_tests/tox_many_tcp_test.c
+++ b/auto_tests/tox_many_tcp_test.c
@@ -55,17 +55,16 @@ START_TEST(test_many_clients_tcp)
55 uint32_t to_comp = 974536; 55 uint32_t to_comp = 974536;
56 56
57 for (i = 0; i < NUM_TOXES_TCP; ++i) { 57 for (i = 0; i < NUM_TOXES_TCP; ++i) {
58 struct Tox_Options opts; 58 struct Tox_Options *opts = tox_options_new(NULL);
59 tox_options_default(&opts);
60 59
61 if (i == 0) { 60 if (i == 0) {
62 opts.tcp_port = TCP_RELAY_PORT; 61 tox_options_set_tcp_port(opts, TCP_RELAY_PORT);
63 } else { 62 } else {
64 opts.udp_enabled = 0; 63 tox_options_set_udp_enabled(opts, 0);
65 } 64 }
66 65
67 index[i] = i + 1; 66 index[i] = i + 1;
68 toxes[i] = tox_new_log(&opts, 0, &index[i]); 67 toxes[i] = tox_new_log(opts, 0, &index[i]);
69 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 68 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
70 tox_callback_friend_request(toxes[i], accept_friend_request); 69 tox_callback_friend_request(toxes[i], accept_friend_request);
71 uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; 70 uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
@@ -74,6 +73,8 @@ START_TEST(test_many_clients_tcp)
74 ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i, %i", i, 73 ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i, %i", i,
75 error); 74 error);
76 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error"); 75 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error");
76
77 tox_options_free(opts);
77 } 78 }
78 79
79 { 80 {
@@ -156,17 +157,16 @@ START_TEST(test_many_clients_tcp_b)
156 uint32_t to_comp = 974536; 157 uint32_t to_comp = 974536;
157 158
158 for (i = 0; i < NUM_TOXES_TCP; ++i) { 159 for (i = 0; i < NUM_TOXES_TCP; ++i) {
159 struct Tox_Options opts; 160 struct Tox_Options *opts = tox_options_new(NULL);
160 tox_options_default(&opts);
161 161
162 if (i < NUM_TCP_RELAYS) { 162 if (i < NUM_TCP_RELAYS) {
163 opts.tcp_port = TCP_RELAY_PORT + i; 163 tox_options_set_tcp_port(opts, TCP_RELAY_PORT + i);
164 } else { 164 } else {
165 opts.udp_enabled = 0; 165 tox_options_set_udp_enabled(opts, 0);
166 } 166 }
167 167
168 index[i] = i + 1; 168 index[i] = i + 1;
169 toxes[i] = tox_new_log(&opts, 0, &index[i]); 169 toxes[i] = tox_new_log(opts, 0, &index[i]);
170 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 170 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
171 tox_callback_friend_request(toxes[i], accept_friend_request); 171 tox_callback_friend_request(toxes[i], accept_friend_request);
172 uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; 172 uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
@@ -175,6 +175,8 @@ START_TEST(test_many_clients_tcp_b)
175 "add relay error"); 175 "add relay error");
176 tox_self_get_dht_id(toxes[0], dpk); 176 tox_self_get_dht_id(toxes[0], dpk);
177 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error"); 177 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error");
178
179 tox_options_free(opts);
178 } 180 }
179 181
180 { 182 {
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c
index ca5fde01..8726d5c5 100644
--- a/auto_tests/tox_one_test.c
+++ b/auto_tests/tox_one_test.c
@@ -29,16 +29,6 @@ static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t
29 29
30START_TEST(test_one) 30START_TEST(test_one)
31{ 31{
32 {
33 TOX_ERR_OPTIONS_NEW o_err;
34 struct Tox_Options *o1 = tox_options_new(&o_err);
35 struct Tox_Options o2;
36 tox_options_default(&o2);
37 ck_assert_msg(o_err == TOX_ERR_OPTIONS_NEW_OK, "tox_options_new wrong error");
38 ck_assert_msg(memcmp(o1, &o2, sizeof(struct Tox_Options)) == 0, "tox_options_new error");
39 tox_options_free(o1);
40 }
41
42 uint8_t name[TOX_MAX_NAME_LENGTH]; 32 uint8_t name[TOX_MAX_NAME_LENGTH];
43 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH]; 33 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
44 34
@@ -93,12 +83,10 @@ START_TEST(test_one)
93 tox_kill(tox2); 83 tox_kill(tox2);
94 TOX_ERR_NEW err_n; 84 TOX_ERR_NEW err_n;
95 85
96 struct Tox_Options options; 86 struct Tox_Options *options = tox_options_new(NULL);
97 tox_options_default(&options); 87 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
98 options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; 88 tox_options_set_savedata_data(options, data, save_size);
99 options.savedata_data = data; 89 tox2 = tox_new_log(options, &err_n, &index[1]);
100 options.savedata_length = save_size;
101 tox2 = tox_new_log(&options, &err_n, &index[1]);
102 ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); 90 ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed");
103 91
104 ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); 92 ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size.");
@@ -123,11 +111,10 @@ START_TEST(test_one)
123 tox_self_get_secret_key(tox2, sk); 111 tox_self_get_secret_key(tox2, sk);
124 tox_kill(tox2); 112 tox_kill(tox2);
125 113
126 tox_options_default(&options); 114 tox_options_default(options);
127 options.savedata_type = TOX_SAVEDATA_TYPE_SECRET_KEY; 115 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_SECRET_KEY);
128 options.savedata_data = sk; 116 tox_options_set_savedata_data(options, sk, sizeof(sk));
129 options.savedata_length = sizeof(sk); 117 tox2 = tox_new_log(options, &err_n, &index[1]);
130 tox2 = tox_new_log(&options, &err_n, &index[1]);
131 ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); 118 ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed");
132 uint8_t address3[TOX_ADDRESS_SIZE]; 119 uint8_t address3[TOX_ADDRESS_SIZE];
133 tox_self_get_address(tox2, address3); 120 tox_self_get_address(tox2, address3);
@@ -142,6 +129,7 @@ START_TEST(test_one)
142 ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); 129 ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
143 } 130 }
144 131
132 tox_options_free(options);
145 tox_kill(tox1); 133 tox_kill(tox1);
146 tox_kill(tox2); 134 tox_kill(tox2);
147} 135}
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 2faa8cad..dfd1d80a 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -418,12 +418,10 @@ START_TEST(test_few_clients)
418 tox_get_savedata(tox2, save1); 418 tox_get_savedata(tox2, save1);
419 tox_kill(tox2); 419 tox_kill(tox2);
420 420
421 struct Tox_Options options; 421 struct Tox_Options *options = tox_options_new(NULL);
422 tox_options_default(&options); 422 tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
423 options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; 423 tox_options_set_savedata_data(options, save1, save_size1);
424 options.savedata_data = save1; 424 tox2 = tox_new_log(options, NULL, &index[1]);
425 options.savedata_length = save_size1;
426 tox2 = tox_new_log(&options, NULL, &index[1]);
427 cur_time = time(NULL); 425 cur_time = time(NULL);
428 off = 1; 426 off = 1;
429 427
@@ -727,6 +725,7 @@ START_TEST(test_few_clients)
727 725
728 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); 726 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
729 727
728 tox_options_free(options);
730 tox_kill(tox1); 729 tox_kill(tox1);
731 tox_kill(tox2); 730 tox_kill(tox2);
732 tox_kill(tox3); 731 tox_kill(tox3);