summaryrefslogtreecommitdiff
path: root/auto_tests/messenger_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-05 16:10:48 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-06 11:54:37 +0100
commitad2656051697899e960694bb68ac104fcc5e92f1 (patch)
tree7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /auto_tests/messenger_test.c
parent4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff)
Improve static and const correctness.
- Any non-externally-visible declarations should be `static`. - Casting away the `const` qualifier from pointers-to-const is dangerous. All but one instance of this are now correct. The one instance where we can't keep `const` is one where toxav code actually writes to a chunk of memory marked as `const`. This code also assumes 4 byte alignment of data packets. I don't know whether that is a valid assumption, but it's likely unportable, and *not* obviously correct. - Replaced empty parameter lists with `(void)` to avoid passing parameters to it. Empty parameter lists are old style declarations for unknown number and type of arguments. - Commented out (as `#if DHT_HARDENING` block) the hardening code that was never executed. - Minor style fix: don't use `default` in enum-switches unless the number of enumerators in the default case is very large. In this case, it was 2, so we want to list them both explicitly to be warned about missing one if we add one in the future. - Removed the only two function declarations from nTox.h and put them into nTox.c. They are not used outside and nTox is not a library.
Diffstat (limited to 'auto_tests/messenger_test.c')
-rw-r--r--auto_tests/messenger_test.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index 2407574e..f7dc92d5 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -26,34 +26,34 @@
26#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) 26#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
27#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) 27#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0)
28 28
29char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; 29static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db";
30 30
31/* in case we need more than one ID for a test */ 31/* in case we need more than one ID for a test */
32char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; 32static const char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441";
33char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; 33static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";
34 34
35char *bad_id_str = "9B569D14ff637e69f2"; 35static const char *bad_id_str = "9B569D14ff637e69f2";
36 36
37unsigned char *friend_id = NULL; 37static unsigned char *friend_id = NULL;
38unsigned char *good_id_a = NULL; 38static unsigned char *good_id_a = NULL;
39unsigned char *good_id_b = NULL; 39static unsigned char *good_id_b = NULL;
40unsigned char *bad_id = NULL; 40static unsigned char *bad_id = NULL;
41 41
42int friend_id_num = 0; 42static int friend_id_num = 0;
43 43
44Messenger *m; 44static Messenger *m;
45 45
46START_TEST(test_m_sendmesage) 46START_TEST(test_m_sendmesage)
47{ 47{
48 char *message = "h-hi :3"; 48 const char *message = "h-hi :3";
49 int good_len = strlen(message); 49 int good_len = strlen(message);
50 int bad_len = MAX_CRYPTO_PACKET_SIZE; 50 int bad_len = MAX_CRYPTO_PACKET_SIZE;
51 51
52 52
53 ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); 53 ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
54 ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); 54 ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
55 ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); 55 ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
56 ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (uint8_t *)message, bad_len, 0) == -2); 56 ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (const uint8_t *)message, bad_len, 0) == -2);
57} 57}
58END_TEST 58END_TEST
59 59
@@ -77,15 +77,15 @@ END_TEST
77 77
78START_TEST(test_m_set_userstatus) 78START_TEST(test_m_set_userstatus)
79{ 79{
80 char *status = "online!"; 80 const char *status = "online!";
81 uint16_t good_length = strlen(status); 81 uint16_t good_length = strlen(status);
82 uint16_t bad_length = REALLY_BIG_NUMBER; 82 uint16_t bad_length = REALLY_BIG_NUMBER;
83 83
84 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1), 84 ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, bad_length) == -1),
85 "m_set_userstatus did NOT catch the following length: %d\n", 85 "m_set_userstatus did NOT catch the following length: %d\n",
86 REALLY_BIG_NUMBER); 86 REALLY_BIG_NUMBER);
87 87
88 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0), 88 ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, good_length) == 0),
89 "m_set_userstatus did NOT return 0 on the following length: %d\n" 89 "m_set_userstatus did NOT return 0 on the following length: %d\n"
90 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); 90 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
91} 91}
@@ -156,25 +156,25 @@ END_TEST */
156 156
157START_TEST(test_setname) 157START_TEST(test_setname)
158{ 158{
159 char *good_name = "consensualCorn"; 159 const char *good_name = "consensualCorn";
160 int good_length = strlen(good_name); 160 int good_length = strlen(good_name);
161 int bad_length = REALLY_BIG_NUMBER; 161 int bad_length = REALLY_BIG_NUMBER;
162 162
163 ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1), 163 ck_assert_msg((setname(m, (const uint8_t *)good_name, bad_length) == -1),
164 "setname() did NOT error on %d as a length argument!\n", bad_length); 164 "setname() did NOT error on %d as a length argument!\n", bad_length);
165 165
166 ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0), 166 ck_assert_msg((setname(m, (const uint8_t *)good_name, good_length) == 0),
167 "setname() did NOT return 0 on good arguments!\n"); 167 "setname() did NOT return 0 on good arguments!\n");
168} 168}
169END_TEST 169END_TEST
170 170
171START_TEST(test_getself_name) 171START_TEST(test_getself_name)
172{ 172{
173 char *nickname = "testGallop"; 173 const char *nickname = "testGallop";
174 int len = strlen(nickname); 174 int len = strlen(nickname);
175 char nick_check[len]; 175 char nick_check[len];
176 176
177 setname(m, (uint8_t *)nickname, len); 177 setname(m, (const uint8_t *)nickname, len);
178 getself_name(m, (uint8_t *)nick_check); 178 getself_name(m, (uint8_t *)nick_check);
179 179
180 ck_assert_msg((memcmp(nickname, nick_check, len) == 0), 180 ck_assert_msg((memcmp(nickname, nick_check, len) == 0),
@@ -300,7 +300,7 @@ START_TEST(test_messenger_state_saveloadsave)
300} 300}
301END_TEST 301END_TEST
302 302
303Suite *messenger_suite(void) 303static Suite *messenger_suite(void)
304{ 304{
305 Suite *s = suite_create("Messenger"); 305 Suite *s = suite_create("Messenger");
306 306