1 /*
2 * nghttp2 - HTTP/2 C Library
3 *
4 * Copyright (c) 2013 Tatsuhiro Tsujikawa
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif // HAVE_CONFIG_H
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <CUnit/Basic.h>
32 // include test cases' include files here
33 #include "shrpx_tls_test.h"
34 #include "shrpx_downstream_test.h"
35 #include "shrpx_config_test.h"
36 #include "shrpx_worker_test.h"
37 #include "http2_test.h"
38 #include "util_test.h"
39 #include "nghttp2_gzip_test.h"
40 #include "buffer_test.h"
41 #include "memchunk_test.h"
42 #include "template_test.h"
43 #include "shrpx_http_test.h"
44 #include "base64_test.h"
45 #include "shrpx_config.h"
46 #include "tls.h"
47 #include "shrpx_router_test.h"
48 #include "shrpx_log.h"
49
init_suite1(void)50 static int init_suite1(void) { return 0; }
51
clean_suite1(void)52 static int clean_suite1(void) { return 0; }
53
main(int argc,char * argv[])54 int main(int argc, char *argv[]) {
55 CU_pSuite pSuite = nullptr;
56 unsigned int num_tests_failed;
57
58 nghttp2::tls::libssl_init();
59
60 shrpx::create_config();
61
62 // initialize the CUnit test registry
63 if (CUE_SUCCESS != CU_initialize_registry())
64 return CU_get_error();
65
66 // add a suite to the registry
67 pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1);
68 if (nullptr == pSuite) {
69 CU_cleanup_registry();
70 return CU_get_error();
71 }
72
73 // add the tests to the suite
74 if (!CU_add_test(pSuite, "tls_create_lookup_tree",
75 shrpx::test_shrpx_tls_create_lookup_tree) ||
76 !CU_add_test(pSuite, "tls_cert_lookup_tree_add_ssl_ctx",
77 shrpx::test_shrpx_tls_cert_lookup_tree_add_ssl_ctx) ||
78 !CU_add_test(pSuite, "tls_tls_hostname_match",
79 shrpx::test_shrpx_tls_tls_hostname_match) ||
80 !CU_add_test(pSuite, "tls_tls_verify_numeric_hostname",
81 shrpx::test_shrpx_tls_verify_numeric_hostname) ||
82 !CU_add_test(pSuite, "tls_tls_verify_dns_hostname",
83 shrpx::test_shrpx_tls_verify_dns_hostname) ||
84 !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) ||
85 !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) ||
86 !CU_add_test(pSuite, "http2_copy_headers_to_nva",
87 shrpx::test_http2_copy_headers_to_nva) ||
88 !CU_add_test(pSuite, "http2_build_http1_headers_from_headers",
89 shrpx::test_http2_build_http1_headers_from_headers) ||
90 !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) ||
91 !CU_add_test(pSuite, "http2_rewrite_location_uri",
92 shrpx::test_http2_rewrite_location_uri) ||
93 !CU_add_test(pSuite, "http2_parse_http_status_code",
94 shrpx::test_http2_parse_http_status_code) ||
95 !CU_add_test(pSuite, "http2_index_header",
96 shrpx::test_http2_index_header) ||
97 !CU_add_test(pSuite, "http2_lookup_token",
98 shrpx::test_http2_lookup_token) ||
99 !CU_add_test(pSuite, "http2_parse_link_header",
100 shrpx::test_http2_parse_link_header) ||
101 !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) ||
102 !CU_add_test(pSuite, "http2_normalize_path",
103 shrpx::test_http2_normalize_path) ||
104 !CU_add_test(pSuite, "http2_rewrite_clean_path",
105 shrpx::test_http2_rewrite_clean_path) ||
106 !CU_add_test(pSuite, "http2_get_pure_path_component",
107 shrpx::test_http2_get_pure_path_component) ||
108 !CU_add_test(pSuite, "http2_construct_push_component",
109 shrpx::test_http2_construct_push_component) ||
110 !CU_add_test(pSuite, "http2_contains_trailers",
111 shrpx::test_http2_contains_trailers) ||
112 !CU_add_test(pSuite, "http2_check_transfer_encoding",
113 shrpx::test_http2_check_transfer_encoding) ||
114 !CU_add_test(pSuite, "downstream_field_store_append_last_header",
115 shrpx::test_downstream_field_store_append_last_header) ||
116 !CU_add_test(pSuite, "downstream_field_store_header",
117 shrpx::test_downstream_field_store_header) ||
118 !CU_add_test(pSuite, "downstream_crumble_request_cookie",
119 shrpx::test_downstream_crumble_request_cookie) ||
120 !CU_add_test(pSuite, "downstream_assemble_request_cookie",
121 shrpx::test_downstream_assemble_request_cookie) ||
122 !CU_add_test(pSuite, "downstream_rewrite_location_response_header",
123 shrpx::test_downstream_rewrite_location_response_header) ||
124 !CU_add_test(pSuite, "downstream_supports_non_final_response",
125 shrpx::test_downstream_supports_non_final_response) ||
126 !CU_add_test(pSuite, "downstream_find_affinity_cookie",
127 shrpx::test_downstream_find_affinity_cookie) ||
128 !CU_add_test(pSuite, "config_parse_header",
129 shrpx::test_shrpx_config_parse_header) ||
130 !CU_add_test(pSuite, "config_parse_log_format",
131 shrpx::test_shrpx_config_parse_log_format) ||
132 !CU_add_test(pSuite, "config_read_tls_ticket_key_file",
133 shrpx::test_shrpx_config_read_tls_ticket_key_file) ||
134 !CU_add_test(pSuite, "config_read_tls_ticket_key_file_aes_256",
135 shrpx::test_shrpx_config_read_tls_ticket_key_file_aes_256) ||
136 !CU_add_test(pSuite, "worker_match_downstream_addr_group",
137 shrpx::test_shrpx_worker_match_downstream_addr_group) ||
138 !CU_add_test(pSuite, "http_create_forwarded",
139 shrpx::test_shrpx_http_create_forwarded) ||
140 !CU_add_test(pSuite, "http_create_via_header_value",
141 shrpx::test_shrpx_http_create_via_header_value) ||
142 !CU_add_test(pSuite, "http_create_affinity_cookie",
143 shrpx::test_shrpx_http_create_affinity_cookie) ||
144 !CU_add_test(pSuite, "http_create_atlsvc_header_field_value",
145 shrpx::test_shrpx_http_create_altsvc_header_value) ||
146 !CU_add_test(pSuite, "http_check_http_scheme",
147 shrpx::test_shrpx_http_check_http_scheme) ||
148 !CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) ||
149 !CU_add_test(pSuite, "router_match_wildcard",
150 shrpx::test_shrpx_router_match_wildcard) ||
151 !CU_add_test(pSuite, "router_match_prefix",
152 shrpx::test_shrpx_router_match_prefix) ||
153 !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) ||
154 !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) ||
155 !CU_add_test(pSuite, "util_inp_strlower",
156 shrpx::test_util_inp_strlower) ||
157 !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) ||
158 !CU_add_test(pSuite, "util_to_token68", shrpx::test_util_to_token68) ||
159 !CU_add_test(pSuite, "util_percent_encode_token",
160 shrpx::test_util_percent_encode_token) ||
161 !CU_add_test(pSuite, "util_percent_decode",
162 shrpx::test_util_percent_decode) ||
163 !CU_add_test(pSuite, "util_quote_string",
164 shrpx::test_util_quote_string) ||
165 !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) ||
166 !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) ||
167 !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) ||
168 !CU_add_test(pSuite, "util_ipv6_numeric_addr",
169 shrpx::test_util_ipv6_numeric_addr) ||
170 !CU_add_test(pSuite, "util_utos", shrpx::test_util_utos) ||
171 !CU_add_test(pSuite, "util_make_string_ref_uint",
172 shrpx::test_util_make_string_ref_uint) ||
173 !CU_add_test(pSuite, "util_utos_unit", shrpx::test_util_utos_unit) ||
174 !CU_add_test(pSuite, "util_utos_funit", shrpx::test_util_utos_funit) ||
175 !CU_add_test(pSuite, "util_parse_uint_with_unit",
176 shrpx::test_util_parse_uint_with_unit) ||
177 !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) ||
178 !CU_add_test(pSuite, "util_parse_duration_with_unit",
179 shrpx::test_util_parse_duration_with_unit) ||
180 !CU_add_test(pSuite, "util_duration_str",
181 shrpx::test_util_duration_str) ||
182 !CU_add_test(pSuite, "util_format_duration",
183 shrpx::test_util_format_duration) ||
184 !CU_add_test(pSuite, "util_starts_with", shrpx::test_util_starts_with) ||
185 !CU_add_test(pSuite, "util_ends_with", shrpx::test_util_ends_with) ||
186 !CU_add_test(pSuite, "util_parse_http_date",
187 shrpx::test_util_parse_http_date) ||
188 !CU_add_test(pSuite, "util_localtime_date",
189 shrpx::test_util_localtime_date) ||
190 !CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) ||
191 !CU_add_test(pSuite, "util_parse_config_str_list",
192 shrpx::test_util_parse_config_str_list) ||
193 !CU_add_test(pSuite, "util_make_http_hostport",
194 shrpx::test_util_make_http_hostport) ||
195 !CU_add_test(pSuite, "util_make_hostport",
196 shrpx::test_util_make_hostport) ||
197 !CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) ||
198 !CU_add_test(pSuite, "util_random_alpha_digit",
199 shrpx::test_util_random_alpha_digit) ||
200 !CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) ||
201 !CU_add_test(pSuite, "util_is_hex_string",
202 shrpx::test_util_is_hex_string) ||
203 !CU_add_test(pSuite, "util_decode_hex", shrpx::test_util_decode_hex) ||
204 !CU_add_test(pSuite, "util_extract_host",
205 shrpx::test_util_extract_host) ||
206 !CU_add_test(pSuite, "util_split_hostport",
207 shrpx::test_util_split_hostport) ||
208 !CU_add_test(pSuite, "util_split_str", shrpx::test_util_split_str) ||
209 !CU_add_test(pSuite, "util_rstrip", shrpx::test_util_rstrip) ||
210 !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
211 !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
212 !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
213 !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) ||
214 !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) ||
215 !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) ||
216 !CU_add_test(pSuite, "memchunk_recycle",
217 nghttp2::test_memchunks_recycle) ||
218 !CU_add_test(pSuite, "memchunk_reset", nghttp2::test_memchunks_reset) ||
219 !CU_add_test(pSuite, "peek_memchunk_append",
220 nghttp2::test_peek_memchunks_append) ||
221 !CU_add_test(pSuite, "peek_memchunk_disable_peek_drain",
222 nghttp2::test_peek_memchunks_disable_peek_drain) ||
223 !CU_add_test(pSuite, "peek_memchunk_disable_peek_no_drain",
224 nghttp2::test_peek_memchunks_disable_peek_no_drain) ||
225 !CU_add_test(pSuite, "peek_memchunk_reset",
226 nghttp2::test_peek_memchunks_reset) ||
227 !CU_add_test(pSuite, "template_immutable_string",
228 nghttp2::test_template_immutable_string) ||
229 !CU_add_test(pSuite, "template_string_ref",
230 nghttp2::test_template_string_ref) ||
231 !CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) ||
232 !CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) {
233 CU_cleanup_registry();
234 return CU_get_error();
235 }
236
237 // Run all tests using the CUnit Basic interface
238 CU_basic_set_mode(CU_BRM_VERBOSE);
239 CU_basic_run_tests();
240 num_tests_failed = CU_get_number_of_tests_failed();
241 CU_cleanup_registry();
242 if (CU_get_error() == CUE_SUCCESS) {
243 return num_tests_failed;
244 } else {
245 printf("CUnit Error: %s\n", CU_get_error_msg());
246 return CU_get_error();
247 }
248 }
249