Changeset 5ebff60 for tests/check_util.c
- Timestamp:
- 2015-02-20T22:50:54Z (9 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/check_util.c
raf359b4 r5ebff60 9 9 #include "url.h" 10 10 11 START_TEST(test_strip_linefeed) 12 { 11 START_TEST(test_strip_linefeed){ 13 12 int i; 14 13 const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; … … 19 18 strcpy(copy, get[i]); 20 19 strip_linefeed(copy); 21 fail_unless (strcmp(copy, expected[i]) == 0,22 "(%d) strip_linefeed broken: %s -> %s (expected: %s)",23 20 fail_unless(strcmp(copy, expected[i]) == 0, 21 "(%d) strip_linefeed broken: %s -> %s (expected: %s)", 22 i, get[i], copy, expected[i]); 24 23 } 25 24 } … … 36 35 strcpy(copy, get[i]); 37 36 ret = strip_newlines(copy); 38 fail_unless (strcmp(copy, expected[i]) == 0,39 "(%d) strip_newlines broken: %s -> %s (expected: %s)",40 41 fail_unless (copy == ret, "Original string not returned");37 fail_unless(strcmp(copy, expected[i]) == 0, 38 "(%d) strip_newlines broken: %s -> %s (expected: %s)", 39 i, get[i], copy, expected[i]); 40 fail_unless(copy == ret, "Original string not returned"); 42 41 } 43 42 } … … 45 44 46 45 START_TEST(test_set_url_http) 47 48 49 fail_if(0 == url_set(&url, "http://host/"));50 fail_unless(!strcmp(url.host, "host"));51 fail_unless(!strcmp(url.file, "/"));52 fail_unless(!strcmp(url.user, ""));53 fail_unless(!strcmp(url.pass, ""));54 fail_unless(url.proto == PROTO_HTTP);55 fail_unless(url.port == 80);46 url_t url; 47 48 fail_if(0 == url_set(&url, "http://host/")); 49 fail_unless(!strcmp(url.host, "host")); 50 fail_unless(!strcmp(url.file, "/")); 51 fail_unless(!strcmp(url.user, "")); 52 fail_unless(!strcmp(url.pass, "")); 53 fail_unless(url.proto == PROTO_HTTP); 54 fail_unless(url.port == 80); 56 55 END_TEST 57 56 58 57 START_TEST(test_set_url_https) 59 60 61 fail_if(0 == url_set(&url, "https://ahost/AimeeMann"));62 fail_unless(!strcmp(url.host, "ahost"));63 fail_unless(!strcmp(url.file, "/AimeeMann"));64 fail_unless(!strcmp(url.user, ""));65 fail_unless(!strcmp(url.pass, ""));66 fail_unless(url.proto == PROTO_HTTPS);67 fail_unless(url.port == 443);58 url_t url; 59 60 fail_if(0 == url_set(&url, "https://ahost/AimeeMann")); 61 fail_unless(!strcmp(url.host, "ahost")); 62 fail_unless(!strcmp(url.file, "/AimeeMann")); 63 fail_unless(!strcmp(url.user, "")); 64 fail_unless(!strcmp(url.pass, "")); 65 fail_unless(url.proto == PROTO_HTTPS); 66 fail_unless(url.port == 443); 68 67 END_TEST 69 68 70 69 START_TEST(test_set_url_port) 71 72 73 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space"));74 fail_unless(!strcmp(url.host, "ahost"));75 fail_unless(!strcmp(url.file, "/Lost/In/Space"));76 fail_unless(!strcmp(url.user, ""));77 fail_unless(!strcmp(url.pass, ""));78 fail_unless(url.proto == PROTO_HTTPS);79 fail_unless(url.port == 200);70 url_t url; 71 72 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space")); 73 fail_unless(!strcmp(url.host, "ahost")); 74 fail_unless(!strcmp(url.file, "/Lost/In/Space")); 75 fail_unless(!strcmp(url.user, "")); 76 fail_unless(!strcmp(url.pass, "")); 77 fail_unless(url.proto == PROTO_HTTPS); 78 fail_unless(url.port == 200); 80 79 END_TEST 81 80 82 81 START_TEST(test_set_url_username) 83 84 85 fail_if(0 == url_set(&url, "socks4://user@ahost/Space"));86 fail_unless(!strcmp(url.host, "ahost"));87 fail_unless(!strcmp(url.file, "/Space"));88 fail_unless(!strcmp(url.user, "user"));89 fail_unless(!strcmp(url.pass, ""));90 fail_unless(url.proto == PROTO_SOCKS4);91 fail_unless(url.port == 1080);82 url_t url; 83 84 fail_if(0 == url_set(&url, "socks4://user@ahost/Space")); 85 fail_unless(!strcmp(url.host, "ahost")); 86 fail_unless(!strcmp(url.file, "/Space")); 87 fail_unless(!strcmp(url.user, "user")); 88 fail_unless(!strcmp(url.pass, "")); 89 fail_unless(url.proto == PROTO_SOCKS4); 90 fail_unless(url.port == 1080); 92 91 END_TEST 93 92 94 93 START_TEST(test_set_url_username_pwd) 95 url_t url; 96 97 fail_if (0 == url_set(&url, "socks5://user:pass@ahost/")); 98 fail_unless (!strcmp(url.host, "ahost")); 99 fail_unless (!strcmp(url.file, "/")); 100 fail_unless (!strcmp(url.user, "user")); 101 fail_unless (!strcmp(url.pass, "pass")); 102 fail_unless (url.proto == PROTO_SOCKS5); 103 fail_unless (url.port == 1080); 104 END_TEST 105 106 struct 107 { 94 url_t url; 95 96 fail_if(0 == url_set(&url, "socks5://user:pass@ahost/")); 97 fail_unless(!strcmp(url.host, "ahost")); 98 fail_unless(!strcmp(url.file, "/")); 99 fail_unless(!strcmp(url.user, "user")); 100 fail_unless(!strcmp(url.pass, "pass")); 101 fail_unless(url.proto == PROTO_SOCKS5); 102 fail_unless(url.port == 1080); 103 END_TEST 104 105 struct { 108 106 char *orig; 109 107 int line_len; … … 146 144 147 145 START_TEST(test_word_wrap) 148 int i; 149 150 for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ ) 151 { 152 char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len ); 153 154 fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0, 155 "%s (line_len = %d) should wrap to `%s', not to `%s'", 156 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 157 word_wrap_tests[i].wrapped, wrapped ); 158 159 g_free( wrapped ); 160 } 146 int i; 147 148 for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) { 149 char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len); 150 151 fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0, 152 "%s (line_len = %d) should wrap to `%s', not to `%s'", 153 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 154 word_wrap_tests[i].wrapped, wrapped); 155 156 g_free(wrapped); 157 } 161 158 END_TEST 162 159 163 160 START_TEST(test_http_encode) 164 165 166 strcpy( s, "ee\xc3""\xab""ee!!...");167 http_encode( s);168 fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0);161 char s[80]; 162 163 strcpy(s, "ee\xc3" "\xab" "ee!!..."); 164 http_encode(s); 165 fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0); 169 166 END_TEST 170 167 … … 172 169 int limit; 173 170 char *command; 174 char *expected[IRC_MAX_ARGS +1];171 char *expected[IRC_MAX_ARGS + 1]; 175 172 } split_tests[] = { 176 173 { 177 174 0, "account add etc \"user name with spaces\" 'pass\\ word'", 178 { "account", "add", "etc", "user name with spaces", "pass\\ word", NULL},175 { "account", "add", "etc", "user name with spaces", "pass\\ word", NULL }, 179 176 }, 180 177 { 181 178 0, "channel set group Close\\ friends", 182 { "channel", "set", "group", "Close friends", NULL},179 { "channel", "set", "group", "Close friends", NULL }, 183 180 }, 184 181 { 185 182 2, "reply wilmer \"testing in C is a PITA\", you said.", 186 { "reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL},183 { "reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL }, 187 184 }, 188 185 { 189 186 4, "one space two spaces limit limit", 190 { "one", "space", "two", "spaces", "limit limit", NULL},187 { "one", "space", "two", "spaces", "limit limit", NULL }, 191 188 }, 192 189 { 193 190 0, NULL, 194 { NULL}191 { NULL } 195 192 }, 196 193 }; 197 194 198 195 START_TEST(test_split_command_parts) 199 200 201 202 203 204 205 206 207 fail_unless(strcmp(split[j], expected[j]) == 0,208 209 210 211 212 213 END_TEST 214 215 Suite *util_suite 196 int i; 197 for (i = 0; split_tests[i].command; i++) { 198 char *cmd = g_strdup(split_tests[i].command); 199 char **split = split_command_parts(cmd, split_tests[i].limit); 200 char **expected = split_tests[i].expected; 201 202 int j; 203 for (j = 0; split[j] && expected[j]; j++) { 204 fail_unless(strcmp(split[j], expected[j]) == 0, 205 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", 206 i, split_tests[i].command, j, split[j], expected[j]); 207 } 208 g_free(cmd); 209 } 210 END_TEST 211 212 Suite *util_suite(void) 216 213 { 217 214 Suite *s = suite_create("Util"); 218 215 TCase *tc_core = tcase_create("Core"); 219 suite_add_tcase (s, tc_core); 220 tcase_add_test (tc_core, test_strip_linefeed); 221 tcase_add_test (tc_core, test_strip_newlines); 222 tcase_add_test (tc_core, test_set_url_http); 223 tcase_add_test (tc_core, test_set_url_https); 224 tcase_add_test (tc_core, test_set_url_port); 225 tcase_add_test (tc_core, test_set_url_username); 226 tcase_add_test (tc_core, test_set_url_username_pwd); 227 tcase_add_test (tc_core, test_word_wrap); 228 tcase_add_test (tc_core, test_http_encode); 229 tcase_add_test (tc_core, test_split_command_parts); 216 217 suite_add_tcase(s, tc_core); 218 tcase_add_test(tc_core, test_strip_linefeed); 219 tcase_add_test(tc_core, test_strip_newlines); 220 tcase_add_test(tc_core, test_set_url_http); 221 tcase_add_test(tc_core, test_set_url_https); 222 tcase_add_test(tc_core, test_set_url_port); 223 tcase_add_test(tc_core, test_set_url_username); 224 tcase_add_test(tc_core, test_set_url_username_pwd); 225 tcase_add_test(tc_core, test_word_wrap); 226 tcase_add_test(tc_core, test_http_encode); 227 tcase_add_test(tc_core, test_split_command_parts); 230 228 return s; 231 229 }
Note: See TracChangeset
for help on using the changeset viewer.