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 = NULL;
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 (NULL == 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, "http2_add_header", shrpx::test_http2_add_header) ||
81 !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) ||
82 !CU_add_test(pSuite, "http2_copy_headers_to_nva",
83 shrpx::test_http2_copy_headers_to_nva) ||
84 !CU_add_test(pSuite, "http2_build_http1_headers_from_headers",
85 shrpx::test_http2_build_http1_headers_from_headers) ||
86 !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) ||
87 !CU_add_test(pSuite, "http2_rewrite_location_uri",
88 shrpx::test_http2_rewrite_location_uri) ||
89 !CU_add_test(pSuite, "http2_parse_http_status_code",
90 shrpx::test_http2_parse_http_status_code) ||
91 !CU_add_test(pSuite, "http2_index_header",
92 shrpx::test_http2_index_header) ||
93 !CU_add_test(pSuite, "http2_lookup_token",
94 shrpx::test_http2_lookup_token) ||
95 !CU_add_test(pSuite, "http2_parse_link_header",
96 shrpx::test_http2_parse_link_header) ||
97 !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) ||
98 !CU_add_test(pSuite, "http2_normalize_path",
99 shrpx::test_http2_normalize_path) ||
100 !CU_add_test(pSuite, "http2_rewrite_clean_path",
101 shrpx::test_http2_rewrite_clean_path) ||
102 !CU_add_test(pSuite, "http2_get_pure_path_component",
103 shrpx::test_http2_get_pure_path_component) ||
104 !CU_add_test(pSuite, "http2_construct_push_component",
105 shrpx::test_http2_construct_push_component) ||
106 !CU_add_test(pSuite, "http2_contains_trailers",
107 shrpx::test_http2_contains_trailers) ||
108 !CU_add_test(pSuite, "downstream_field_store_append_last_header",
109 shrpx::test_downstream_field_store_append_last_header) ||
110 !CU_add_test(pSuite, "downstream_field_store_header",
111 shrpx::test_downstream_field_store_header) ||
112 !CU_add_test(pSuite, "downstream_crumble_request_cookie",
113 shrpx::test_downstream_crumble_request_cookie) ||
114 !CU_add_test(pSuite, "downstream_assemble_request_cookie",
115 shrpx::test_downstream_assemble_request_cookie) ||
116 !CU_add_test(pSuite, "downstream_rewrite_location_response_header",
117 shrpx::test_downstream_rewrite_location_response_header) ||
118 !CU_add_test(pSuite, "downstream_supports_non_final_response",
119 shrpx::test_downstream_supports_non_final_response) ||
120 !CU_add_test(pSuite, "downstream_find_affinity_cookie",
121 shrpx::test_downstream_find_affinity_cookie) ||
122 !CU_add_test(pSuite, "config_parse_header",
123 shrpx::test_shrpx_config_parse_header) ||
124 !CU_add_test(pSuite, "config_parse_log_format",
125 shrpx::test_shrpx_config_parse_log_format) ||
126 !CU_add_test(pSuite, "config_read_tls_ticket_key_file",
127 shrpx::test_shrpx_config_read_tls_ticket_key_file) ||
128 !CU_add_test(pSuite, "config_read_tls_ticket_key_file_aes_256",
129 shrpx::test_shrpx_config_read_tls_ticket_key_file_aes_256) ||
130 !CU_add_test(pSuite, "worker_match_downstream_addr_group",
131 shrpx::test_shrpx_worker_match_downstream_addr_group) ||
132 !CU_add_test(pSuite, "http_create_forwarded",
133 shrpx::test_shrpx_http_create_forwarded) ||
134 !CU_add_test(pSuite, "http_create_via_header_value",
135 shrpx::test_shrpx_http_create_via_header_value) ||
136 !CU_add_test(pSuite, "http_create_affinity_cookie",
137 shrpx::test_shrpx_http_create_affinity_cookie) ||
138 !CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) ||
139 !CU_add_test(pSuite, "router_match_wildcard",
140 shrpx::test_shrpx_router_match_wildcard) ||
141 !CU_add_test(pSuite, "router_match_prefix",
142 shrpx::test_shrpx_router_match_prefix) ||
143 !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) ||
144 !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) ||
145 !CU_add_test(pSuite, "util_inp_strlower",
146 shrpx::test_util_inp_strlower) ||
147 !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) ||
148 !CU_add_test(pSuite, "util_to_token68", shrpx::test_util_to_token68) ||
149 !CU_add_test(pSuite, "util_percent_encode_token",
150 shrpx::test_util_percent_encode_token) ||
151 !CU_add_test(pSuite, "util_percent_encode_path",
152 shrpx::test_util_percent_encode_path) ||
153 !CU_add_test(pSuite, "util_percent_decode",
154 shrpx::test_util_percent_decode) ||
155 !CU_add_test(pSuite, "util_quote_string",
156 shrpx::test_util_quote_string) ||
157 !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) ||
158 !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) ||
159 !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) ||
160 !CU_add_test(pSuite, "util_ipv6_numeric_addr",
161 shrpx::test_util_ipv6_numeric_addr) ||
162 !CU_add_test(pSuite, "util_utos", shrpx::test_util_utos) ||
163 !CU_add_test(pSuite, "util_make_string_ref_uint",
164 shrpx::test_util_make_string_ref_uint) ||
165 !CU_add_test(pSuite, "util_utos_unit", shrpx::test_util_utos_unit) ||
166 !CU_add_test(pSuite, "util_utos_funit", shrpx::test_util_utos_funit) ||
167 !CU_add_test(pSuite, "util_parse_uint_with_unit",
168 shrpx::test_util_parse_uint_with_unit) ||
169 !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) ||
170 !CU_add_test(pSuite, "util_parse_duration_with_unit",
171 shrpx::test_util_parse_duration_with_unit) ||
172 !CU_add_test(pSuite, "util_duration_str",
173 shrpx::test_util_duration_str) ||
174 !CU_add_test(pSuite, "util_format_duration",
175 shrpx::test_util_format_duration) ||
176 !CU_add_test(pSuite, "util_starts_with", shrpx::test_util_starts_with) ||
177 !CU_add_test(pSuite, "util_ends_with", shrpx::test_util_ends_with) ||
178 !CU_add_test(pSuite, "util_parse_http_date",
179 shrpx::test_util_parse_http_date) ||
180 !CU_add_test(pSuite, "util_localtime_date",
181 shrpx::test_util_localtime_date) ||
182 !CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) ||
183 !CU_add_test(pSuite, "util_parse_config_str_list",
184 shrpx::test_util_parse_config_str_list) ||
185 !CU_add_test(pSuite, "util_make_http_hostport",
186 shrpx::test_util_make_http_hostport) ||
187 !CU_add_test(pSuite, "util_make_hostport",
188 shrpx::test_util_make_hostport) ||
189 !CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) ||
190 !CU_add_test(pSuite, "util_random_alpha_digit",
191 shrpx::test_util_random_alpha_digit) ||
192 !CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) ||
193 !CU_add_test(pSuite, "util_is_hex_string",
194 shrpx::test_util_is_hex_string) ||
195 !CU_add_test(pSuite, "util_decode_hex", shrpx::test_util_decode_hex) ||
196 !CU_add_test(pSuite, "util_extract_host",
197 shrpx::test_util_extract_host) ||
198 !CU_add_test(pSuite, "util_split_hostport",
199 shrpx::test_util_split_hostport) ||
200 !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
201 !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
202 !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
203 !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) ||
204 !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) ||
205 !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) ||
206 !CU_add_test(pSuite, "memchunk_recycle",
207 nghttp2::test_memchunks_recycle) ||
208 !CU_add_test(pSuite, "memchunk_reset", nghttp2::test_memchunks_reset) ||
209 !CU_add_test(pSuite, "peek_memchunk_append",
210 nghttp2::test_peek_memchunks_append) ||
211 !CU_add_test(pSuite, "peek_memchunk_disable_peek_drain",
212 nghttp2::test_peek_memchunks_disable_peek_drain) ||
213 !CU_add_test(pSuite, "peek_memchunk_disable_peek_no_drain",
214 nghttp2::test_peek_memchunks_disable_peek_no_drain) ||
215 !CU_add_test(pSuite, "peek_memchunk_reset",
216 nghttp2::test_peek_memchunks_reset) ||
217 !CU_add_test(pSuite, "template_immutable_string",
218 nghttp2::test_template_immutable_string) ||
219 !CU_add_test(pSuite, "template_string_ref",
220 nghttp2::test_template_string_ref) ||
221 !CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) ||
222 !CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) {
223 CU_cleanup_registry();
224 return CU_get_error();
225 }
226
227 // Run all tests using the CUnit Basic interface
228 CU_basic_set_mode(CU_BRM_VERBOSE);
229 CU_basic_run_tests();
230 num_tests_failed = CU_get_number_of_tests_failed();
231 CU_cleanup_registry();
232 if (CU_get_error() == CUE_SUCCESS) {
233 return num_tests_failed;
234 } else {
235 printf("CUnit Error: %s\n", CU_get_error_msg());
236 return CU_get_error();
237 }
238 }
239