1 | #include <stdlib.h> |
---|
2 | #include <glib.h> |
---|
3 | #include <gmodule.h> |
---|
4 | #include <check.h> |
---|
5 | #include <string.h> |
---|
6 | #include "irc.h" |
---|
7 | #include "set.h" |
---|
8 | #include "misc.h" |
---|
9 | #include "url.h" |
---|
10 | |
---|
11 | START_TEST(test_strip_linefeed) |
---|
12 | { |
---|
13 | int i; |
---|
14 | const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; |
---|
15 | const char *expected[] = { "Test", "Test", "TestX", NULL }; |
---|
16 | |
---|
17 | for (i = 0; get[i]; i++) { |
---|
18 | char copy[20]; |
---|
19 | strcpy(copy, get[i]); |
---|
20 | strip_linefeed(copy); |
---|
21 | fail_unless (strcmp(copy, expected[i]) == 0, |
---|
22 | "(%d) strip_linefeed broken: %s -> %s (expected: %s)", |
---|
23 | i, get[i], copy, expected[i]); |
---|
24 | } |
---|
25 | } |
---|
26 | END_TEST |
---|
27 | |
---|
28 | START_TEST(test_strip_newlines) |
---|
29 | { |
---|
30 | int i; |
---|
31 | const char *get[] = { "Test", "Test\r\n", "Test\nX\n", NULL }; |
---|
32 | const char *expected[] = { "Test", "Test ", "Test X ", NULL }; |
---|
33 | |
---|
34 | for (i = 0; get[i]; i++) { |
---|
35 | char copy[20], *ret; |
---|
36 | strcpy(copy, get[i]); |
---|
37 | ret = strip_newlines(copy); |
---|
38 | fail_unless (strcmp(copy, expected[i]) == 0, |
---|
39 | "(%d) strip_newlines broken: %s -> %s (expected: %s)", |
---|
40 | i, get[i], copy, expected[i]); |
---|
41 | fail_unless (copy == ret, "Original string not returned"); |
---|
42 | } |
---|
43 | } |
---|
44 | END_TEST |
---|
45 | |
---|
46 | START_TEST(test_set_url_http) |
---|
47 | url_t url; |
---|
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); |
---|
56 | END_TEST |
---|
57 | |
---|
58 | START_TEST(test_set_url_https) |
---|
59 | url_t url; |
---|
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); |
---|
68 | END_TEST |
---|
69 | |
---|
70 | START_TEST(test_set_url_port) |
---|
71 | url_t url; |
---|
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); |
---|
80 | END_TEST |
---|
81 | |
---|
82 | START_TEST(test_set_url_username) |
---|
83 | url_t url; |
---|
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); |
---|
92 | END_TEST |
---|
93 | |
---|
94 | 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 | Suite *util_suite (void) |
---|
107 | { |
---|
108 | Suite *s = suite_create("Util"); |
---|
109 | TCase *tc_core = tcase_create("Core"); |
---|
110 | suite_add_tcase (s, tc_core); |
---|
111 | tcase_add_test (tc_core, test_strip_linefeed); |
---|
112 | tcase_add_test (tc_core, test_strip_newlines); |
---|
113 | tcase_add_test (tc_core, test_set_url_http); |
---|
114 | tcase_add_test (tc_core, test_set_url_https); |
---|
115 | tcase_add_test (tc_core, test_set_url_port); |
---|
116 | tcase_add_test (tc_core, test_set_url_username); |
---|
117 | tcase_add_test (tc_core, test_set_url_username_pwd); |
---|
118 | return s; |
---|
119 | } |
---|