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