Upgrade to 1.46.0
[platform/upstream/nghttp2.git] / tests / failmalloc.c
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 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
34 #include "failmalloc_test.h"
35
36 static int init_suite1(void) { return 0; }
37
38 static int clean_suite1(void) { return 0; }
39
40 int main(void) {
41   CU_pSuite pSuite = NULL;
42   unsigned int num_tests_failed;
43
44   /* initialize the CUnit test registry */
45   if (CUE_SUCCESS != CU_initialize_registry())
46     return (int)CU_get_error();
47
48   /* add a suite to the registry */
49   pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1);
50   if (NULL == pSuite) {
51     CU_cleanup_registry();
52     return (int)CU_get_error();
53   }
54
55   /* add the tests to the suite */
56   if (!CU_add_test(pSuite, "failmalloc_session_send",
57                    test_nghttp2_session_send) ||
58       !CU_add_test(pSuite, "failmalloc_session_send_server",
59                    test_nghttp2_session_send_server) ||
60       !CU_add_test(pSuite, "failmalloc_session_recv",
61                    test_nghttp2_session_recv) ||
62       !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame) ||
63       !CU_add_test(pSuite, "failmalloc_hd", test_nghttp2_hd)) {
64     CU_cleanup_registry();
65     return (int)CU_get_error();
66   }
67
68   /* Run all tests using the CUnit Basic interface */
69   CU_basic_set_mode(CU_BRM_VERBOSE);
70   CU_basic_run_tests();
71   num_tests_failed = CU_get_number_of_tests_failed();
72   CU_cleanup_registry();
73   if (CU_get_error() == CUE_SUCCESS) {
74     return (int)num_tests_failed;
75   } else {
76     printf("CUnit Error: %s\n", CU_get_error_msg());
77     return (int)CU_get_error();
78   }
79 }