root / approxBasisSollya / test / test-read-lines / test-read-lines-basic-driver.c @ 301
Historique | Voir | Annoter | Télécharger (4,02 ko)
1 | 301 | storres | /** @file test-read-lines-basic-driver.c
|
---|---|---|---|
2 | 301 | storres | * Name and purpose
|
3 | 301 | storres | * Driver program to run test suites
|
4 | 301 | storres | * using the CUnit Basic interface.
|
5 | 301 | storres | *
|
6 | 301 | storres | * @author ST
|
7 | 301 | storres | * @date 2018-03-14
|
8 | 301 | storres | */
|
9 | 301 | storres | /******************************************************************************/
|
10 | 301 | storres | |
11 | 301 | storres | /* Includes of system headers */
|
12 | 301 | storres | #include <stdlib.h> |
13 | 301 | storres | #include <stdio.h> |
14 | 301 | storres | |
15 | 301 | storres | /* Includes of project headers */
|
16 | 301 | storres | #include <Basic.h> |
17 | 301 | storres | |
18 | 301 | storres | |
19 | 301 | storres | /* Includes of local (suite) headers */
|
20 | 301 | storres | |
21 | 301 | storres | /* Includes of test suite prototypes */
|
22 | 301 | storres | /* This definition is to limit inclusion to local headers (and
|
23 | 301 | storres | not include functions definition). */
|
24 | 301 | storres | #define TEST_DRIVER 1 |
25 | 301 | storres | #include "test-read-lines-suite-1.c" |
26 | 301 | storres | |
27 | 301 | storres | /* Internal prototypes */
|
28 | 301 | storres | |
29 | 301 | storres | |
30 | 301 | storres | /* Register the test suites.*/
|
31 | 301 | storres | CU_ErrorCode |
32 | 301 | storres | register_suites_and_display_error(CU_SuiteInfo* suites); |
33 | 301 | storres | |
34 | 301 | storres | /* Types, constants and macros definitions */
|
35 | 301 | storres | |
36 | 301 | storres | /* Global variables */
|
37 | 301 | storres | |
38 | 301 | storres | /* Tests. */
|
39 | 301 | storres | /* Individual suite definitions : each suite is defined by:
|
40 | 301 | storres | - a CU_TestInfo array (e.g. suite1);
|
41 | 301 | storres | - a list of individual tests (each element has two fields):
|
42 | 301 | storres | - a name string (e.g. "suite1test1"),
|
43 | 301 | storres | - a function name (e.g. suite1_test1);
|
44 | 301 | storres | - the list ends with a CU_TEST_INFO_NULL element. */
|
45 | 301 | storres | CU_TestInfo test_read_lines_suite_1[] = |
46 | 301 | storres | { |
47 | 301 | storres | {"test_read_lines_suite_1_test_1",
|
48 | 301 | storres | test_read_lines_suite_1_test_1}, |
49 | 301 | storres | {"test_read_lines_suite_1_test_2",
|
50 | 301 | storres | test_read_lines_suite_1_test_2}, |
51 | 301 | storres | {"test_read_lines_suite_1_test_3",
|
52 | 301 | storres | test_read_lines_suite_1_test_3}, |
53 | 301 | storres | {"test_read_lines_suite_1_test_4",
|
54 | 301 | storres | test_read_lines_suite_1_test_4}, |
55 | 301 | storres | {"test_read_lines_suite_1_test_5",
|
56 | 301 | storres | test_read_lines_suite_1_test_5}, |
57 | 301 | storres | CU_TEST_INFO_NULL, |
58 | 301 | storres | }; /* End test_read_lines_suite_1. */
|
59 | 301 | storres | |
60 | 301 | storres | /* Suites definition list defined by:
|
61 | 301 | storres | - a CU_SuiteInfo array (e.g. suites) ;
|
62 | 301 | storres | - a list of suites (each individual element has four fields):
|
63 | 301 | storres | - a name string (e.g. "suite1"),
|
64 | 301 | storres | - a suite initializing function (e.g. suite1_init),
|
65 | 301 | storres | - a suite cleanup function (e.g. suite1_cleanup),
|
66 | 301 | storres | - a suite setup function (e.g. suite_setup),
|
67 | 301 | storres | - a suite teardown function (e.g. suite_teardown),
|
68 | 301 | storres | - the name of the suite tests array (see above);
|
69 | 301 | storres | - the list ends with a CU_SUITE_INFO_NULL element. */
|
70 | 301 | storres | CU_SuiteInfo test_read_lines_suites[] = |
71 | 301 | storres | { |
72 | 301 | storres | {"test_read_lines_suite_1",
|
73 | 301 | storres | test_read_lines_suite_1_init, |
74 | 301 | storres | test_read_lines_suite_1_cleanup, |
75 | 301 | storres | test_read_lines_suite_1_setup, |
76 | 301 | storres | test_read_lines_suite_1_teardown, |
77 | 301 | storres | test_read_lines_suite_1}, |
78 | 301 | storres | CU_SUITE_INFO_NULL, |
79 | 301 | storres | }; /* End test_read_lines_suites. */
|
80 | 301 | storres | |
81 | 301 | storres | /* Functions */
|
82 | 301 | storres | |
83 | 301 | storres | int main(int argc, char** argv) |
84 | 301 | storres | { |
85 | 301 | storres | CU_ErrorCode last_error; |
86 | 301 | storres | unsigned int tests_failed_count = 0; |
87 | 301 | storres | |
88 | 301 | storres | /**************************************/
|
89 | 301 | storres | /* Initialize the CUnit test registry */
|
90 | 301 | storres | /**************************************/
|
91 | 301 | storres | if (CUE_SUCCESS != CU_initialize_registry())
|
92 | 301 | storres | return CU_get_error();
|
93 | 301 | storres | |
94 | 301 | storres | /*****************************************/
|
95 | 301 | storres | /* Add register the suites. */
|
96 | 301 | storres | /*****************************************/
|
97 | 301 | storres | /* The argument is the name of the name of the suites definition list
|
98 | 301 | storres | (e.g. suites)*/
|
99 | 301 | storres | last_error = register_suites_and_display_error(test_read_lines_suites); |
100 | 301 | storres | if (last_error != CUE_SUCCESS)
|
101 | 301 | storres | { |
102 | 301 | storres | CU_cleanup_registry(); |
103 | 301 | storres | return(last_error);
|
104 | 301 | storres | } |
105 | 301 | storres | CU_basic_set_mode(CU_BRM_VERBOSE); |
106 | 301 | storres | last_error = CU_basic_run_tests(); |
107 | 301 | storres | if (last_error != CUE_SUCCESS)
|
108 | 301 | storres | { |
109 | 301 | storres | fprintf(stderr, "Tests execution failed for some internal reason: %s.\n",
|
110 | 301 | storres | CU_get_error_msg()); |
111 | 301 | storres | CU_cleanup_registry(); |
112 | 301 | storres | return(last_error);
|
113 | 301 | storres | } |
114 | 301 | storres | //CU_console_run_tests();
|
115 | 301 | storres | tests_failed_count = CU_get_number_of_tests_failed(); |
116 | 301 | storres | CU_cleanup_registry(); |
117 | 301 | storres | return tests_failed_count;
|
118 | 301 | storres | } /* End main */
|
119 | 301 | storres | |
120 | 301 | storres | /* Helper functions. */
|
121 | 301 | storres | |
122 | 301 | storres | CU_ErrorCode |
123 | 301 | storres | register_suites_and_display_error(CU_SuiteInfo* suites) |
124 | 301 | storres | { |
125 | 301 | storres | CU_ErrorCode register_suites_error; |
126 | 301 | storres | register_suites_error = CU_register_suites(suites); |
127 | 301 | storres | if (register_suites_error != CUE_SUCCESS)
|
128 | 301 | storres | { |
129 | 301 | storres | fprintf(stderr, "%s\n", CU_get_error_msg());
|
130 | 301 | storres | return(register_suites_error);
|
131 | 301 | storres | } /* End if pTest == NULL. */
|
132 | 301 | storres | return CUE_SUCCESS;
|
133 | 301 | storres | } /* End register_suites_and_display_error */ |