tizen 2.4 release
[external/nghttp2.git] / src / shrpx-unittest.cc
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 <openssl/ssl.h>
33 #include <openssl/err.h>
34 // include test cases' include files here
35 #include "shrpx_ssl_test.h"
36 #include "shrpx_downstream_test.h"
37 #include "shrpx_config_test.h"
38 #include "http2_test.h"
39 #include "util_test.h"
40 #include "nghttp2_gzip_test.h"
41 #include "buffer_test.h"
42 #include "memchunk_test.h"
43 #include "shrpx_config.h"
44
45 static int init_suite1(void) { return 0; }
46
47 static int clean_suite1(void) { return 0; }
48
49 int main(int argc, char *argv[]) {
50   CU_pSuite pSuite = NULL;
51   unsigned int num_tests_failed;
52
53   OpenSSL_add_all_algorithms();
54   SSL_load_error_strings();
55   SSL_library_init();
56
57   shrpx::create_config();
58
59   // initialize the CUnit test registry
60   if (CUE_SUCCESS != CU_initialize_registry())
61     return CU_get_error();
62
63   // add a suite to the registry
64   pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1);
65   if (NULL == pSuite) {
66     CU_cleanup_registry();
67     return CU_get_error();
68   }
69
70   // add the tests to the suite
71   if (!CU_add_test(pSuite, "ssl_create_lookup_tree",
72                    shrpx::test_shrpx_ssl_create_lookup_tree) ||
73       !CU_add_test(pSuite, "ssl_cert_lookup_tree_add_cert_from_file",
74                    shrpx::test_shrpx_ssl_cert_lookup_tree_add_cert_from_file) ||
75       !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) ||
76       !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) ||
77       !CU_add_test(pSuite, "http2_copy_headers_to_nva",
78                    shrpx::test_http2_copy_headers_to_nva) ||
79       !CU_add_test(pSuite, "http2_build_http1_headers_from_headers",
80                    shrpx::test_http2_build_http1_headers_from_headers) ||
81       !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) ||
82       !CU_add_test(pSuite, "http2_rewrite_location_uri",
83                    shrpx::test_http2_rewrite_location_uri) ||
84       !CU_add_test(pSuite, "http2_parse_http_status_code",
85                    shrpx::test_http2_parse_http_status_code) ||
86       !CU_add_test(pSuite, "http2_index_header",
87                    shrpx::test_http2_index_header) ||
88       !CU_add_test(pSuite, "http2_lookup_token",
89                    shrpx::test_http2_lookup_token) ||
90       !CU_add_test(pSuite, "http2_check_http2_pseudo_header",
91                    shrpx::test_http2_check_http2_pseudo_header) ||
92       !CU_add_test(pSuite, "http2_http2_header_allowed",
93                    shrpx::test_http2_http2_header_allowed) ||
94       !CU_add_test(pSuite, "http2_mandatory_request_headers_presence",
95                    shrpx::test_http2_mandatory_request_headers_presence) ||
96       !CU_add_test(pSuite, "http2_parse_link_header",
97                    shrpx::test_http2_parse_link_header) ||
98       !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) ||
99       !CU_add_test(pSuite, "downstream_index_request_headers",
100                    shrpx::test_downstream_index_request_headers) ||
101       !CU_add_test(pSuite, "downstream_index_response_headers",
102                    shrpx::test_downstream_index_response_headers) ||
103       !CU_add_test(pSuite, "downstream_get_request_header",
104                    shrpx::test_downstream_get_request_header) ||
105       !CU_add_test(pSuite, "downstream_get_response_header",
106                    shrpx::test_downstream_get_response_header) ||
107       !CU_add_test(pSuite, "downstream_crumble_request_cookie",
108                    shrpx::test_downstream_crumble_request_cookie) ||
109       !CU_add_test(pSuite, "downstream_assemble_request_cookie",
110                    shrpx::test_downstream_assemble_request_cookie) ||
111       !CU_add_test(pSuite, "downstream_rewrite_location_response_header",
112                    shrpx::test_downstream_rewrite_location_response_header) ||
113       !CU_add_test(pSuite, "config_parse_config_str_list",
114                    shrpx::test_shrpx_config_parse_config_str_list) ||
115       !CU_add_test(pSuite, "config_parse_header",
116                    shrpx::test_shrpx_config_parse_header) ||
117       !CU_add_test(pSuite, "config_parse_log_format",
118                    shrpx::test_shrpx_config_parse_log_format) ||
119       !CU_add_test(pSuite, "config_read_tls_ticket_key_file",
120                    shrpx::test_shrpx_config_read_tls_ticket_key_file) ||
121       !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) ||
122       !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) ||
123       !CU_add_test(pSuite, "util_inp_strlower",
124                    shrpx::test_util_inp_strlower) ||
125       !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) ||
126       !CU_add_test(pSuite, "util_percent_encode_token",
127                    shrpx::test_util_percent_encode_token) ||
128       !CU_add_test(pSuite, "util_quote_string",
129                    shrpx::test_util_quote_string) ||
130       !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) ||
131       !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) ||
132       !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) ||
133       !CU_add_test(pSuite, "util_ipv6_numeric_addr",
134                    shrpx::test_util_ipv6_numeric_addr) ||
135       !CU_add_test(pSuite, "util_utos_with_unit",
136                    shrpx::test_util_utos_with_unit) ||
137       !CU_add_test(pSuite, "util_utos_with_funit",
138                    shrpx::test_util_utos_with_funit) ||
139       !CU_add_test(pSuite, "util_parse_uint_with_unit",
140                    shrpx::test_util_parse_uint_with_unit) ||
141       !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) ||
142       !CU_add_test(pSuite, "util_parse_duration_with_unit",
143                    shrpx::test_util_parse_duration_with_unit) ||
144       !CU_add_test(pSuite, "util_duration_str",
145                    shrpx::test_util_duration_str) ||
146       !CU_add_test(pSuite, "util_format_duration",
147                    shrpx::test_util_format_duration) ||
148       !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
149       !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
150       !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
151       !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) ||
152       !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) ||
153       !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) ||
154       !CU_add_test(pSuite, "memchunk_recycle",
155                    nghttp2::test_memchunks_recycle)) {
156     CU_cleanup_registry();
157     return CU_get_error();
158   }
159
160   // Run all tests using the CUnit Basic interface
161   CU_basic_set_mode(CU_BRM_VERBOSE);
162   CU_basic_run_tests();
163   num_tests_failed = CU_get_number_of_tests_failed();
164   CU_cleanup_registry();
165   if (CU_get_error() == CUE_SUCCESS) {
166     return num_tests_failed;
167   } else {
168     printf("CUnit Error: %s\n", CU_get_error_msg());
169     return CU_get_error();
170   }
171 }