| 134 /** |
130 /** |
| 135 * Creates a new test suite. |
131 * Creates a new test suite. |
| 136 * @param name optional name of the suite |
132 * @param name optional name of the suite |
| 137 * @return a new test suite |
133 * @return a new test suite |
| 138 */ |
134 */ |
| 139 cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(1) cx_attr_malloc |
135 CX_NONNULL CX_NODISCARD CX_CSTR_ARG(1) CX_MALLOC |
| 140 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
136 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
| 141 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
137 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
| 142 if (suite != NULL) { |
138 if (suite != NULL) { |
| 143 suite->name = name; |
139 suite->name = name; |
| 144 suite->success = 0; |
140 suite->success = 0; |
| 171 * @param suite the suite the test function shall be added to |
167 * @param suite the suite the test function shall be added to |
| 172 * @param test the test function to register |
168 * @param test the test function to register |
| 173 * @retval zero success |
169 * @retval zero success |
| 174 * @retval non-zero failure |
170 * @retval non-zero failure |
| 175 */ |
171 */ |
| 176 cx_attr_nonnull |
172 CX_NONNULL |
| 177 CX_INLINE int cx_test_register(CxTestSuite* suite, CxTest test) { |
173 CX_INLINE int cx_test_register(CxTestSuite* suite, CxTest test) { |
| 178 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
174 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
| 179 if (t) { |
175 if (t) { |
| 180 t->test = test; |
176 t->test = test; |
| 181 t->next = NULL; |
177 t->next = NULL; |
| 198 * Runs a test suite and writes the test log to the specified stream. |
194 * Runs a test suite and writes the test log to the specified stream. |
| 199 * @param suite the test suite to run |
195 * @param suite the test suite to run |
| 200 * @param out_target the target buffer or file to write the output to |
196 * @param out_target the target buffer or file to write the output to |
| 201 * @param out_writer the write function writing to @p out_target |
197 * @param out_writer the write function writing to @p out_target |
| 202 */ |
198 */ |
| 203 cx_attr_nonnull |
199 CX_NONNULL |
| 204 CX_INLINE void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer) { |
200 CX_INLINE void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer) { |
| 205 if (suite->name == NULL) { |
201 if (suite->name == NULL) { |
| 206 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
202 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
| 207 } else { |
203 } else { |
| 208 out_writer("*** Test Suite : ", 1, 17, out_target); |
204 out_writer("*** Test Suite : ", 1, 17, out_target); |
| 324 * @see CX_TEST_SUBROUTINE() |
320 * @see CX_TEST_SUBROUTINE() |
| 325 */ |
321 */ |
| 326 #define CX_TEST_CALL_SUBROUTINE(name,...) \ |
322 #define CX_TEST_CALL_SUBROUTINE(name,...) \ |
| 327 name(_suite_,_output_,_writefnc_,_env_,__VA_ARGS__) |
323 name(_suite_,_output_,_writefnc_,_env_,__VA_ARGS__) |
| 328 |
324 |
| 329 #ifdef __cplusplus |
|
| 330 } |
|
| 331 #endif |
|
| 332 |
|
| 333 #endif /* UCX_TEST_H */ |
325 #endif /* UCX_TEST_H */ |
| 334 |
326 |