94 |
94 |
95 /** Type for the CxTestSuite. */ |
95 /** Type for the CxTestSuite. */ |
96 typedef struct CxTestSuite CxTestSuite; |
96 typedef struct CxTestSuite CxTestSuite; |
97 |
97 |
98 /** Pointer to a test function. */ |
98 /** Pointer to a test function. */ |
|
99 cx_attr_nonnull |
99 typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func); |
100 typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func); |
100 |
101 |
101 /** Type for the internal list of test cases. */ |
102 /** Type for the internal list of test cases. */ |
102 typedef struct CxTestSet CxTestSet; |
103 typedef struct CxTestSet CxTestSet; |
103 |
104 |
135 /** |
136 /** |
136 * Creates a new test suite. |
137 * Creates a new test suite. |
137 * @param name optional name of the suite |
138 * @param name optional name of the suite |
138 * @return a new test suite |
139 * @return a new test suite |
139 */ |
140 */ |
|
141 cx_attr_nonnull |
|
142 cx_attr_nodiscard |
|
143 cx_attr_cstr_arg(1) |
|
144 cx_attr_malloc |
140 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
145 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
141 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
146 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
142 if (suite != NULL) { |
147 if (suite != NULL) { |
143 suite->name = name; |
148 suite->name = name; |
144 suite->success = 0; |
149 suite->success = 0; |
168 * |
174 * |
169 * @param suite the suite, the test function shall be added to |
175 * @param suite the suite, the test function shall be added to |
170 * @param test the test function to register |
176 * @param test the test function to register |
171 * @return zero on success or non-zero on failure |
177 * @return zero on success or non-zero on failure |
172 */ |
178 */ |
|
179 cx_attr_nonnull |
173 static inline int cx_test_register(CxTestSuite* suite, CxTest test) { |
180 static inline int cx_test_register(CxTestSuite* suite, CxTest test) { |
174 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
181 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
175 if (t) { |
182 if (t) { |
176 t->test = test; |
183 t->test = test; |
177 t->next = NULL; |
184 t->next = NULL; |
194 * Runs a test suite and writes the test log to the specified stream. |
201 * Runs a test suite and writes the test log to the specified stream. |
195 * @param suite the test suite to run |
202 * @param suite the test suite to run |
196 * @param out_target the target buffer or file to write the output to |
203 * @param out_target the target buffer or file to write the output to |
197 * @param out_writer the write function writing to \p out_target |
204 * @param out_writer the write function writing to \p out_target |
198 */ |
205 */ |
|
206 cx_attr_nonnull |
199 static inline void cx_test_run(CxTestSuite *suite, |
207 static inline void cx_test_run(CxTestSuite *suite, |
200 void *out_target, cx_write_func out_writer) { |
208 void *out_target, cx_write_func out_writer) { |
201 if (suite->name == NULL) { |
209 if (suite->name == NULL) { |
202 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
210 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
203 } else { |
211 } else { |