summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-16 13:11:09 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-16 13:11:09 -0400
commit88ff81d9def5efe69cbaf91aa41906177ba7dde9 (patch)
treecb9f149e438bcd1f18d8c1eb5d8be6b0a22f58a4 /auto_tests
parentc5af8f44a9d040a0bbe0442ec074d9fc8562dd32 (diff)
Passed everything through astyle.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/crypto_test.c157
-rw-r--r--[-rwxr-xr-x]auto_tests/friends_test.c47
-rw-r--r--auto_tests/messenger_test.c71
3 files changed, 143 insertions, 132 deletions
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index 8b5397e4..6b9f6113 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -10,8 +10,8 @@
10void rand_bytes(uint8_t *b, size_t blen) 10void rand_bytes(uint8_t *b, size_t blen)
11{ 11{
12 size_t i; 12 size_t i;
13 for (i = 0; i < blen; i++) 13
14 { 14 for (i = 0; i < blen; i++) {
15 b[i] = rand(); 15 b[i] = rand();
16 } 16 }
17} 17}
@@ -19,65 +19,65 @@ void rand_bytes(uint8_t *b, size_t blen)
19// These test vectors are from libsodium's test suite 19// These test vectors are from libsodium's test suite
20 20
21unsigned char alicesk[32] = { 21unsigned char alicesk[32] = {
22 0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d, 22 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d,
23 0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45, 23 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45,
24 0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a, 24 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a,
25 0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a 25 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
26}; 26};
27 27
28unsigned char bobpk[32] = { 28unsigned char bobpk[32] = {
29 0xde,0x9e,0xdb,0x7d,0x7b,0x7d,0xc1,0xb4, 29 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4,
30 0xd3,0x5b,0x61,0xc2,0xec,0xe4,0x35,0x37, 30 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37,
31 0x3f,0x83,0x43,0xc8,0x5b,0x78,0x67,0x4d, 31 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d,
32 0xad,0xfc,0x7e,0x14,0x6f,0x88,0x2b,0x4f 32 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
33}; 33};
34 34
35unsigned char nonce[24] = { 35unsigned char nonce[24] = {
36 0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73, 36 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
37 0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6, 37 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
38 0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37 38 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
39}; 39};
40 40
41unsigned char test_m[131] = { 41unsigned char test_m[131] = {
42 0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5, 42 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5,
43 0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b, 43 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
44 0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4, 44 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
45 0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc, 45 0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc,
46 0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a, 46 0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a,
47 0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29, 47 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29,
48 0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4, 48 0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4,
49 0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31, 49 0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31,
50 0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d, 50 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d,
51 0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57, 51 0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57,
52 0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a, 52 0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a,
53 0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde, 53 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde,
54 0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd, 54 0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd,
55 0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52, 55 0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52,
56 0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40, 56 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40,
57 0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64, 57 0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64,
58 0x5e,0x07,0x05 58 0x5e, 0x07, 0x05
59}; 59};
60 60
61unsigned char test_c[147] = { 61unsigned char test_c[147] = {
62 0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5, 62 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
63 0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9, 63 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9,
64 0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73, 64 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73,
65 0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce, 65 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce,
66 0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4, 66 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4,
67 0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a, 67 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a,
68 0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b, 68 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b,
69 0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72, 69 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72,
70 0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2, 70 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2,
71 0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38, 71 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,
72 0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a, 72 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a,
73 0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae, 73 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae,
74 0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea, 74 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea,
75 0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda, 75 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda,
76 0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde, 76 0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde,
77 0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3, 77 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3,
78 0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6, 78 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6,
79 0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74, 79 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74,
80 0xe3,0x55,0xa5 80 0xe3, 0x55, 0xa5
81}; 81};
82 82
83START_TEST(test_known) 83START_TEST(test_known)
@@ -86,19 +86,20 @@ START_TEST(test_known)
86 unsigned char m[131]; 86 unsigned char m[131];
87 int clen, mlen; 87 int clen, mlen;
88 88
89 ck_assert_msg(sizeof(c) == sizeof(m) + ENCRYPTION_PADDING * sizeof(unsigned char), "cyphertext should be ENCRYPTION_PADDING bytes longer than plaintext"); 89 ck_assert_msg(sizeof(c) == sizeof(m) + ENCRYPTION_PADDING * sizeof(unsigned char),
90 "cyphertext should be ENCRYPTION_PADDING bytes longer than plaintext");
90 ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); 91 ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
91 ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); 92 ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
92 93
93 clen = encrypt_data(bobpk, alicesk, nonce, test_m, sizeof(test_m)/sizeof(unsigned char), c); 94 clen = encrypt_data(bobpk, alicesk, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
94 95
95 ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); 96 ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
96 ck_assert_msg(clen == sizeof(c)/sizeof(unsigned char), "wrong ciphertext length"); 97 ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
97 98
98 mlen = decrypt_data(bobpk, alicesk, nonce, test_c, sizeof(test_c)/sizeof(unsigned char), m); 99 mlen = decrypt_data(bobpk, alicesk, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
99 100
100 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); 101 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
101 ck_assert_msg(mlen == sizeof(m)/sizeof(unsigned char), "wrong plaintext length"); 102 ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
102} 103}
103END_TEST 104END_TEST
104 105
@@ -111,20 +112,21 @@ START_TEST(test_fast_known)
111 112
112 encrypt_precompute(bobpk, alicesk, k); 113 encrypt_precompute(bobpk, alicesk, k);
113 114
114 ck_assert_msg(sizeof(c) == sizeof(m) + ENCRYPTION_PADDING * sizeof(unsigned char), "cyphertext should be ENCRYPTION_PADDING bytes longer than plaintext"); 115 ck_assert_msg(sizeof(c) == sizeof(m) + ENCRYPTION_PADDING * sizeof(unsigned char),
116 "cyphertext should be ENCRYPTION_PADDING bytes longer than plaintext");
115 ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); 117 ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
116 ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); 118 ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
117 119
118 clen = encrypt_data_fast(k, nonce, test_m, sizeof(test_m)/sizeof(unsigned char), c); 120 clen = encrypt_data_fast(k, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
119 121
120 ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); 122 ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
121 ck_assert_msg(clen == sizeof(c)/sizeof(unsigned char), "wrong ciphertext length"); 123 ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
122 124
123 mlen = decrypt_data_fast(k, nonce, test_c, sizeof(test_c)/sizeof(unsigned char), m); 125 mlen = decrypt_data_fast(k, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
124 126
125 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); 127 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
126 ck_assert_msg(mlen == sizeof(m)/sizeof(unsigned char), "wrong plaintext length"); 128 ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
127 129
128} 130}
129END_TEST 131END_TEST
130 132
@@ -156,23 +158,22 @@ START_TEST(test_endtoend)
156 int testno; 158 int testno;
157 159
158 // Test 100 random messages and keypairs 160 // Test 100 random messages and keypairs
159 for (testno = 0; testno < 100; testno++) 161 for (testno = 0; testno < 100; testno++) {
160 {
161 //Generate random message (random length from 100 to 500) 162 //Generate random message (random length from 100 to 500)
162 mlen = (rand() % 400) + 100; 163 mlen = (rand() % 400) + 100;
163 rand_bytes(m, mlen); 164 rand_bytes(m, mlen);
164 rand_bytes(n, crypto_box_NONCEBYTES); 165 rand_bytes(n, crypto_box_NONCEBYTES);
165 166
166 //Generate keypairs 167 //Generate keypairs
167 crypto_box_keypair(pk1,sk1); 168 crypto_box_keypair(pk1, sk1);
168 crypto_box_keypair(pk2,sk2); 169 crypto_box_keypair(pk2, sk2);
169 170
170 //Precompute shared keys 171 //Precompute shared keys
171 encrypt_precompute(pk2, sk1, k1); 172 encrypt_precompute(pk2, sk1, k1);
172 encrypt_precompute(pk1, sk2, k2); 173 encrypt_precompute(pk1, sk2, k2);
173 174
174 ck_assert_msg(memcmp(k1, k2, crypto_box_BEFORENMBYTES) == 0, "encrypt_precompute: bad"); 175 ck_assert_msg(memcmp(k1, k2, crypto_box_BEFORENMBYTES) == 0, "encrypt_precompute: bad");
175 176
176 //Encrypt all four ways 177 //Encrypt all four ways
177 c1len = encrypt_data(pk2, sk1, n, m, mlen, c1); 178 c1len = encrypt_data(pk2, sk1, n, m, mlen, c1);
178 c2len = encrypt_data(pk1, sk2, n, m, mlen, c2); 179 c2len = encrypt_data(pk1, sk2, n, m, mlen, c2);
@@ -181,7 +182,8 @@ START_TEST(test_endtoend)
181 182
182 ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); 183 ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ");
183 ck_assert_msg(c1len == mlen + ENCRYPTION_PADDING, "wrong cyphertext length"); 184 ck_assert_msg(c1len == mlen + ENCRYPTION_PADDING, "wrong cyphertext length");
184 ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); 185 ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0
186 && memcmp(c1, c4, c1len) == 0, "crypertexts differ");
185 187
186 //Decrypt all four ways 188 //Decrypt all four ways
187 m1len = decrypt_data(pk2, sk1, n, c1, c1len, m1); 189 m1len = decrypt_data(pk2, sk1, n, c1, c1len, m1);
@@ -191,7 +193,8 @@ START_TEST(test_endtoend)
191 193
192 ck_assert_msg(m1len == m2len && m1len == m3len && m1len == m4len, "decrypted text lengths differ"); 194 ck_assert_msg(m1len == m2len && m1len == m3len && m1len == m4len, "decrypted text lengths differ");
193 ck_assert_msg(m1len == mlen, "wrong decrypted text length"); 195 ck_assert_msg(m1len == mlen, "wrong decrypted text length");
194 ck_assert_msg(memcmp(m1, m2, mlen) == 0 && memcmp(m1, m3, mlen) == 0 && memcmp(m1, m4, mlen) == 0, "decrypted texts differ"); 196 ck_assert_msg(memcmp(m1, m2, mlen) == 0 && memcmp(m1, m3, mlen) == 0
197 && memcmp(m1, m4, mlen) == 0, "decrypted texts differ");
195 ck_assert_msg(memcmp(m1, m, mlen) == 0, "wrong decrypted text"); 198 ck_assert_msg(memcmp(m1, m, mlen) == 0, "wrong decrypted text");
196 } 199 }
197} 200}
@@ -217,18 +220,18 @@ START_TEST(test_large_data)
217 rand_bytes(m1, sizeof(m1)); 220 rand_bytes(m1, sizeof(m1));
218 rand_bytes(m2, sizeof(m2)); 221 rand_bytes(m2, sizeof(m2));
219 rand_bytes(n, crypto_box_NONCEBYTES); 222 rand_bytes(n, crypto_box_NONCEBYTES);
220 223
221 //Generate key 224 //Generate key
222 rand_bytes(k, crypto_box_BEFORENMBYTES); 225 rand_bytes(k, crypto_box_BEFORENMBYTES);
223 226
224 c1len = encrypt_data_fast(k, n, m1, sizeof(m1), c1); 227 c1len = encrypt_data_fast(k, n, m1, sizeof(m1), c1);
225 c2len = encrypt_data_fast(k, n, m2, sizeof(m2), c2); 228 c2len = encrypt_data_fast(k, n, m2, sizeof(m2), c2);
226 229
227 ck_assert_msg(c1len == sizeof(m1) + ENCRYPTION_PADDING, "Could not encrypt max size"); 230 ck_assert_msg(c1len == sizeof(m1) + ENCRYPTION_PADDING, "Could not encrypt max size");
228 ck_assert_msg(c2len == -1, "incorrectly succeeded encrypting massive size"); 231 ck_assert_msg(c2len == -1, "incorrectly succeeded encrypting massive size");
229 232
230 m1plen = decrypt_data_fast(k, n, c1, c1len, m1prime); 233 m1plen = decrypt_data_fast(k, n, c1, c1len, m1prime);
231 234
232 ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ"); 235 ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
233 ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ"); 236 ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
234} 237}
@@ -239,7 +242,7 @@ END_TEST
239 tcase_add_test(NAME, test_##NAME); \ 242 tcase_add_test(NAME, test_##NAME); \
240 suite_add_tcase(s, NAME); 243 suite_add_tcase(s, NAME);
241 244
242Suite* crypto_suite(void) 245Suite *crypto_suite(void)
243{ 246{
244 Suite *s = suite_create("Crypto"); 247 Suite *s = suite_create("Crypto");
245 248
@@ -251,7 +254,7 @@ Suite* crypto_suite(void)
251 return s; 254 return s;
252} 255}
253 256
254int main(int argc, char* argv[]) 257int main(int argc, char *argv[])
255{ 258{
256 srand((unsigned int) time(NULL)); 259 srand((unsigned int) time(NULL));
257 260
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c
index 3c15b35b..dd2db3e3 100755..100644
--- a/auto_tests/friends_test.c
+++ b/auto_tests/friends_test.c
@@ -56,22 +56,22 @@ void do_tox(void)
56{ 56{
57 static int dht_on = 0; 57 static int dht_on = 0;
58 58
59 if(!dht_on && DHT_isconnected()) { 59 if (!dht_on && DHT_isconnected()) {
60 dht_on = 1; 60 dht_on = 1;
61 } else if(dht_on && !DHT_isconnected()) { 61 } else if (dht_on && !DHT_isconnected()) {
62 dht_on = 0; 62 dht_on = 0;
63 } 63 }
64 64
65 doMessenger(m); 65 doMessenger(m);
66} 66}
67 67
68void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata) 68void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
69{ 69{
70 puts("OK"); 70 puts("OK");
71 request_flags |= SECOND_FLAG; 71 request_flags |= SECOND_FLAG;
72} 72}
73 73
74void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata) 74void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
75{ 75{
76 puts("OK"); 76 puts("OK");
77 request_flags |= FIRST_FLAG; 77 request_flags |= FIRST_FLAG;
@@ -89,16 +89,18 @@ int parent_friend_request(void)
89 m_addfriend(m, child_id, (uint8_t *)message, len); 89 m_addfriend(m, child_id, (uint8_t *)message, len);
90 90
91 /* wait on the status change */ 91 /* wait on the status change */
92 for(i = 0; i < WAIT_COUNT; i++) { 92 for (i = 0; i < WAIT_COUNT; i++) {
93 do_tox(); 93 do_tox();
94 if(request_flags & FIRST_FLAG) 94
95 if (request_flags & FIRST_FLAG)
95 break; 96 break;
97
96 fputs(".", stdout); 98 fputs(".", stdout);
97 fflush(stdout); 99 fflush(stdout);
98 c_sleep(WAIT_TIME); 100 c_sleep(WAIT_TIME);
99 } 101 }
100 102
101 if(!(request_flags & FIRST_FLAG)) { 103 if (!(request_flags & FIRST_FLAG)) {
102 fputs("\nfriends_test: The child took to long to respond!\n" 104 fputs("\nfriends_test: The child took to long to respond!\n"
103 "Friend requests may be broken, failing build!\n", stderr); 105 "Friend requests may be broken, failing build!\n", stderr);
104 kill(child_pid, SIGKILL); 106 kill(child_pid, SIGKILL);
@@ -108,7 +110,7 @@ int parent_friend_request(void)
108 return 0; 110 return 0;
109} 111}
110 112
111void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata) 113void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
112{ 114{
113 fputs("OK\nsending status to parent", stdout); 115 fputs("OK\nsending status to parent", stdout);
114 fflush(stdout); 116 fflush(stdout);
@@ -116,7 +118,7 @@ void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void
116 request_flags |= FIRST_FLAG; 118 request_flags |= FIRST_FLAG;
117} 119}
118 120
119void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void* userdata) 121void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void *userdata)
120{ 122{
121 request_flags |= SECOND_FLAG; 123 request_flags |= SECOND_FLAG;
122} 124}
@@ -128,16 +130,18 @@ int parent_wait_for_message(void)
128 fputs("Parent waiting for message.", stdout); 130 fputs("Parent waiting for message.", stdout);
129 fflush(stdout); 131 fflush(stdout);
130 132
131 for(i = 0; i < WAIT_COUNT; i++) { 133 for (i = 0; i < WAIT_COUNT; i++) {
132 do_tox(); 134 do_tox();
133 if(request_flags & SECOND_FLAG) 135
136 if (request_flags & SECOND_FLAG)
134 break; 137 break;
138
135 fputs(".", stdout); 139 fputs(".", stdout);
136 fflush(stdout); 140 fflush(stdout);
137 c_sleep(WAIT_TIME); 141 c_sleep(WAIT_TIME);
138 } 142 }
139 143
140 if(!(request_flags & SECOND_FLAG)) { 144 if (!(request_flags & SECOND_FLAG)) {
141 fputs("\nParent hasn't received the message yet!\n" 145 fputs("\nParent hasn't received the message yet!\n"
142 "Messaging may be broken, failing the build!\n", stderr); 146 "Messaging may be broken, failing the build!\n", stderr);
143 kill(child_pid, SIGKILL); 147 kill(child_pid, SIGKILL);
@@ -160,12 +164,13 @@ int main(int argc, char *argv[])
160 164
161 /* set up the global memory */ 165 /* set up the global memory */
162 parent_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE, 166 parent_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
163 MAP_SHARED | MAP_ANONYMOUS, -1, 0); 167 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
164 child_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE, 168 child_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
165 MAP_SHARED | MAP_ANONYMOUS, -1, 0); 169 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
166 170
167 fputs("friends_test: Starting test...\n", stdout); 171 fputs("friends_test: Starting test...\n", stdout);
168 if((child_pid = fork()) == 0) { 172
173 if ((child_pid = fork()) == 0) {
169 /* child */ 174 /* child */
170 int i = 0; 175 int i = 0;
171 char *message = "Y-yes Mr. Watson?"; 176 char *message = "Y-yes Mr. Watson?";
@@ -179,14 +184,14 @@ int main(int argc, char *argv[])
179 m_callback_statusmessage(m, child_got_statuschange, NULL); 184 m_callback_statusmessage(m, child_got_statuschange, NULL);
180 185
181 /* wait on the friend request */ 186 /* wait on the friend request */
182 while(!(request_flags & FIRST_FLAG)) 187 while (!(request_flags & FIRST_FLAG))
183 do_tox(); 188 do_tox();
184 189
185 /* wait for the status change */ 190 /* wait for the status change */
186 while(!(request_flags & SECOND_FLAG)) 191 while (!(request_flags & SECOND_FLAG))
187 do_tox(); 192 do_tox();
188 193
189 for(i = 0; i < 6; i++) { 194 for (i = 0; i < 6; i++) {
190 /* send the message six times, just to be sure */ 195 /* send the message six times, just to be sure */
191 m_sendmessage(m, 0, (uint8_t *)message, strlen(message)); 196 m_sendmessage(m, 0, (uint8_t *)message, strlen(message));
192 do_tox(); 197 do_tox();
@@ -198,7 +203,7 @@ int main(int argc, char *argv[])
198 } 203 }
199 204
200 /* parent */ 205 /* parent */
201 if(atexit(cleanup) != 0) { 206 if (atexit(cleanup) != 0) {
202 fputs("friends_test: atexit() failed!\nFailing build...\n", stderr); 207 fputs("friends_test: atexit() failed!\nFailing build...\n", stderr);
203 kill(child_pid, SIGKILL); 208 kill(child_pid, SIGKILL);
204 return -1; 209 return -1;
@@ -215,10 +220,10 @@ int main(int argc, char *argv[])
215 220
216 Messenger_save(m, parent_id); 221 Messenger_save(m, parent_id);
217 222
218 if(parent_friend_request() == -1) 223 if (parent_friend_request() == -1)
219 return -1; 224 return -1;
220 225
221 if(parent_wait_for_message() == -1) 226 if (parent_wait_for_message() == -1)
222 return -1; 227 return -1;
223 228
224 wait(NULL); 229 wait(NULL);
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index f04d3f10..374bc5a6 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -36,14 +36,16 @@ int friend_id_num = 0;
36 36
37Messenger *m; 37Messenger *m;
38 38
39unsigned char * hex_string_to_bin(char hex_string[]) 39unsigned char *hex_string_to_bin(char hex_string[])
40{ 40{
41 size_t len = strlen(hex_string); 41 size_t len = strlen(hex_string);
42 unsigned char *val = calloc(1, len); 42 unsigned char *val = calloc(1, len);
43 char *pos = hex_string; 43 char *pos = hex_string;
44 int i = 0; 44 int i = 0;
45 for(i = 0; i < len; ++i, pos+=2) 45
46 sscanf(pos,"%2hhx",&val[i]); 46 for (i = 0; i < len; ++i, pos += 2)
47 sscanf(pos, "%2hhx", &val[i]);
48
47 return val; 49 return val;
48} 50}
49 51
@@ -65,17 +67,17 @@ START_TEST(test_m_get_userstatus_size)
65{ 67{
66 int rc = 0; 68 int rc = 0;
67 ck_assert_msg((m_get_statusmessage_size(m, -1) == -1), 69 ck_assert_msg((m_get_statusmessage_size(m, -1) == -1),
68 "m_get_statusmessage_size did NOT catch an argument of -1"); 70 "m_get_statusmessage_size did NOT catch an argument of -1");
69 ck_assert_msg((m_get_statusmessage_size(m, REALLY_BIG_NUMBER) == -1), 71 ck_assert_msg((m_get_statusmessage_size(m, REALLY_BIG_NUMBER) == -1),
70 "m_get_statusmessage_size did NOT catch the following argument: %d\n", 72 "m_get_statusmessage_size did NOT catch the following argument: %d\n",
71 REALLY_BIG_NUMBER); 73 REALLY_BIG_NUMBER);
72 rc = m_get_statusmessage_size(m, friend_id_num); 74 rc = m_get_statusmessage_size(m, friend_id_num);
73 75
74 /* this WILL error if the original m_addfriend_norequest() failed */ 76 /* this WILL error if the original m_addfriend_norequest() failed */
75 ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH), 77 ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
76 "m_get_statusmessage_size is returning out of range values!\n" 78 "m_get_statusmessage_size is returning out of range values!\n"
77 "(this can be caused by the error of m_addfriend_norequest" 79 "(this can be caused by the error of m_addfriend_norequest"
78 " in the beginning of the suite)\n"); 80 " in the beginning of the suite)\n");
79} 81}
80END_TEST 82END_TEST
81 83
@@ -85,11 +87,11 @@ START_TEST(test_m_set_userstatus)
85 uint16_t good_length = strlen(status); 87 uint16_t good_length = strlen(status);
86 uint16_t bad_length = REALLY_BIG_NUMBER; 88 uint16_t bad_length = REALLY_BIG_NUMBER;
87 89
88 if(m_set_statusmessage(m, (uint8_t *)status, bad_length) != -1) 90 if (m_set_statusmessage(m, (uint8_t *)status, bad_length) != -1)
89 ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n", 91 ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n",
90 REALLY_BIG_NUMBER); 92 REALLY_BIG_NUMBER);
91 93
92 if((m_set_statusmessage(m, (uint8_t *)status, good_length)) != 0) 94 if ((m_set_statusmessage(m, (uint8_t *)status, good_length)) != 0)
93 ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n" 95 ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n"
94 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); 96 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
95} 97}
@@ -98,20 +100,20 @@ END_TEST
98START_TEST(test_m_friendstatus) 100START_TEST(test_m_friendstatus)
99{ 101{
100 ck_assert_msg((m_friendstatus(m, -1) == NOFRIEND), 102 ck_assert_msg((m_friendstatus(m, -1) == NOFRIEND),
101 "m_friendstatus did NOT catch an argument of -1.\n"); 103 "m_friendstatus did NOT catch an argument of -1.\n");
102 ck_assert_msg((m_friendstatus(m, REALLY_BIG_NUMBER) == NOFRIEND), 104 ck_assert_msg((m_friendstatus(m, REALLY_BIG_NUMBER) == NOFRIEND),
103 "m_friendstatus did NOT catch an argument of %d.\n", 105 "m_friendstatus did NOT catch an argument of %d.\n",
104 REALLY_BIG_NUMBER); 106 REALLY_BIG_NUMBER);
105} 107}
106END_TEST 108END_TEST
107 109
108START_TEST(test_m_delfriend) 110START_TEST(test_m_delfriend)
109{ 111{
110 ck_assert_msg((m_delfriend(m, -1) == -1), 112 ck_assert_msg((m_delfriend(m, -1) == -1),
111 "m_delfriend did NOT catch an argument of -1\n"); 113 "m_delfriend did NOT catch an argument of -1\n");
112 ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1), 114 ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1),
113 "m_delfriend did NOT catch the following number: %d\n", 115 "m_delfriend did NOT catch the following number: %d\n",
114 REALLY_BIG_NUMBER); 116 REALLY_BIG_NUMBER);
115} 117}
116END_TEST 118END_TEST
117/* 119/*
@@ -124,12 +126,12 @@ START_TEST(test_m_addfriend)
124 int bad_len = strlen(bad_data); 126 int bad_len = strlen(bad_data);
125 int really_bad_len = (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES 127 int really_bad_len = (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
126 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES 128 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
127 + crypto_box_ZEROBYTES + 100); */ 129 + crypto_box_ZEROBYTES + 100); */
128/* TODO: Update this properly to latest master 130/* TODO: Update this properly to latest master
129 if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) 131 if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG)
130 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len); 132 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
131*/ 133*/
132 /* this will error if the original m_addfriend_norequest() failed */ 134/* this will error if the original m_addfriend_norequest() failed */
133/* if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) 135/* if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT)
134 ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n" 136 ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
135 "(this can be caused by the error of m_addfriend_norequest in" 137 "(this can be caused by the error of m_addfriend_norequest in"
@@ -138,13 +140,13 @@ START_TEST(test_m_addfriend)
138 if(m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) 140 if(m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE)
139 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len); 141 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
140*/ 142*/
141 /* this should REALLY error */ 143/* this should REALLY error */
142 /* 144/*
143 * TODO: validate client_id in m_addfriend? 145 * TODO: validate client_id in m_addfriend?
144 if(m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0) 146if(m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0)
145 ck_abort_msg("The following ID passed through " 147 ck_abort_msg("The following ID passed through "
146 "m_addfriend without an error:\n'%s'\n", bad_id_str); 148 "m_addfriend without an error:\n'%s'\n", bad_id_str);
147 149
148} 150}
149END_TEST */ 151END_TEST */
150 152
@@ -154,10 +156,11 @@ START_TEST(test_setname)
154 int good_length = strlen(good_name); 156 int good_length = strlen(good_name);
155 int bad_length = REALLY_BIG_NUMBER; 157 int bad_length = REALLY_BIG_NUMBER;
156 158
157 if(setname(m, (uint8_t *)good_name, bad_length) != -1) 159 if (setname(m, (uint8_t *)good_name, bad_length) != -1)
158 ck_abort_msg("setname() did NOT error on %d as a length argument!\n", 160 ck_abort_msg("setname() did NOT error on %d as a length argument!\n",
159 bad_length); 161 bad_length);
160 if(setname(m, (uint8_t *)good_name, good_length) != 0) 162
163 if (setname(m, (uint8_t *)good_name, good_length) != 0)
161 ck_abort_msg("setname() did NOT return 0 on good arguments!\n"); 164 ck_abort_msg("setname() did NOT return 0 on good arguments!\n");
162} 165}
163END_TEST 166END_TEST
@@ -172,8 +175,8 @@ START_TEST(test_getself_name)
172 getself_name(m, (uint8_t *)nick_check, len); 175 getself_name(m, (uint8_t *)nick_check, len);
173 176
174 ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)), 177 ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)),
175 "getself_name failed to return the known name!\n" 178 "getself_name failed to return the known name!\n"
176 "known name: %s\nreturned: %s\n", nickname, nick_check); 179 "known name: %s\nreturned: %s\n", nickname, nick_check);
177} 180}
178END_TEST 181END_TEST
179 182
@@ -261,12 +264,12 @@ int main(int argc, char *argv[])
261 m = initMessenger(); 264 m = initMessenger();
262 265
263 /* setup a default friend and friendnum */ 266 /* setup a default friend and friendnum */
264 if(m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) 267 if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
265 fputs("m_addfriend_norequest() failed on a valid ID!\n" 268 fputs("m_addfriend_norequest() failed on a valid ID!\n"
266 "this was CRITICAL to the test, and the build WILL fail.\n" 269 "this was CRITICAL to the test, and the build WILL fail.\n"
267 "the tests will continue now...\n\n", stderr); 270 "the tests will continue now...\n\n", stderr);
268 271
269 if((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0) 272 if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0)
270 fputs("getfriend_id() failed on a valid ID!\n" 273 fputs("getfriend_id() failed on a valid ID!\n"
271 "this was CRITICAL to the test, and the build WILL fail.\n" 274 "this was CRITICAL to the test, and the build WILL fail.\n"
272 "the tests will continue now...\n\n", stderr); 275 "the tests will continue now...\n\n", stderr);