Changeset 6ff651b for tests/check_util.c
- Timestamp:
- 2019-11-19T12:51:39Z (4 years ago)
- Branches:
- master
- Children:
- b504415
- Parents:
- bcd8f52
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/check_util.c
rbcd8f52 r6ff651b 9 9 #include "url.h" 10 10 11 START_TEST(test_strip_linefeed){ 11 START_TEST(test_strip_linefeed) 12 { 12 13 int i; 13 14 const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; … … 44 45 45 46 START_TEST(test_set_url_http) 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); 47 { 48 url_t url; 49 50 fail_if(0 == url_set(&url, "http://host/")); 51 fail_unless(!strcmp(url.host, "host")); 52 fail_unless(!strcmp(url.file, "/")); 53 fail_unless(!strcmp(url.user, "")); 54 fail_unless(!strcmp(url.pass, "")); 55 fail_unless(url.proto == PROTO_HTTP); 56 fail_unless(url.port == 80); 57 } 55 58 END_TEST 56 59 57 60 START_TEST(test_set_url_https) 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); 61 { 62 url_t url; 63 64 fail_if(0 == url_set(&url, "https://ahost/AimeeMann")); 65 fail_unless(!strcmp(url.host, "ahost")); 66 fail_unless(!strcmp(url.file, "/AimeeMann")); 67 fail_unless(!strcmp(url.user, "")); 68 fail_unless(!strcmp(url.pass, "")); 69 fail_unless(url.proto == PROTO_HTTPS); 70 fail_unless(url.port == 443); 71 } 67 72 END_TEST 68 73 69 74 START_TEST(test_set_url_port) 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); 75 { 76 url_t url; 77 78 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space")); 79 fail_unless(!strcmp(url.host, "ahost")); 80 fail_unless(!strcmp(url.file, "/Lost/In/Space")); 81 fail_unless(!strcmp(url.user, "")); 82 fail_unless(!strcmp(url.pass, "")); 83 fail_unless(url.proto == PROTO_HTTPS); 84 fail_unless(url.port == 200); 85 } 79 86 END_TEST 80 87 81 88 START_TEST(test_set_url_username) 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); 89 { 90 url_t url; 91 92 fail_if(0 == url_set(&url, "socks4://user@ahost/Space")); 93 fail_unless(!strcmp(url.host, "ahost")); 94 fail_unless(!strcmp(url.file, "/Space")); 95 fail_unless(!strcmp(url.user, "user")); 96 fail_unless(!strcmp(url.pass, "")); 97 fail_unless(url.proto == PROTO_SOCKS4); 98 fail_unless(url.port == 1080); 99 } 91 100 END_TEST 92 101 93 102 START_TEST(test_set_url_username_pwd) 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 { 104 url_t url; 105 106 fail_if(0 == url_set(&url, "socks5://user:pass@ahost/")); 107 fail_unless(!strcmp(url.host, "ahost")); 108 fail_unless(!strcmp(url.file, "/")); 109 fail_unless(!strcmp(url.user, "user")); 110 fail_unless(!strcmp(url.pass, "pass")); 111 fail_unless(url.proto == PROTO_SOCKS5); 112 fail_unless(url.port == 1080); 113 } 103 114 END_TEST 104 115 … … 149 160 150 161 START_TEST(test_word_wrap) 151 int i; 152 153 for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) { 154 char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len); 155 156 fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0, 157 "%s (line_len = %d) should wrap to `%s', not to `%s'", 158 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 159 word_wrap_tests[i].wrapped, wrapped); 160 161 g_free(wrapped); 162 { 163 int i; 164 165 for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) { 166 char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len); 167 168 fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0, 169 "%s (line_len = %d) should wrap to `%s', not to `%s'", 170 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 171 word_wrap_tests[i].wrapped, wrapped); 172 173 g_free(wrapped); 174 } 162 175 } 163 176 END_TEST 164 177 165 178 START_TEST(test_http_encode) 166 char s[80]; 167 168 strcpy(s, "ee\xc3" "\xab" "ee!!..."); 169 http_encode(s); 170 fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0); 179 { 180 char s[80]; 181 182 strcpy(s, "ee\xc3" "\xab" "ee!!..."); 183 http_encode(s); 184 fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0); 185 } 171 186 END_TEST 172 187 … … 199 214 200 215 START_TEST(test_split_command_parts) 201 int i; 202 for (i = 0; split_tests[i].command; i++) { 203 char *cmd = g_strdup(split_tests[i].command); 204 char **split = split_command_parts(cmd, split_tests[i].limit); 205 char **expected = split_tests[i].expected; 206 207 int j; 208 for (j = 0; split[j] && expected[j]; j++) { 209 fail_unless(strcmp(split[j], expected[j]) == 0, 210 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", 211 i, split_tests[i].command, j, split[j], expected[j]); 212 } 213 g_free(cmd); 216 { 217 int i; 218 for (i = 0; split_tests[i].command; i++) { 219 char *cmd = g_strdup(split_tests[i].command); 220 char **split = split_command_parts(cmd, split_tests[i].limit); 221 char **expected = split_tests[i].expected; 222 223 int j; 224 for (j = 0; split[j] && expected[j]; j++) { 225 fail_unless(strcmp(split[j], expected[j]) == 0, 226 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", 227 i, split_tests[i].command, j, split[j], expected[j]); 228 } 229 g_free(cmd); 230 } 214 231 } 215 232 END_TEST
Note: See TracChangeset
for help on using the changeset viewer.