134 /** |
134 /** |
135 * Creates a new test suite. |
135 * Creates a new test suite. |
136 * @param name optional name of the suite |
136 * @param name optional name of the suite |
137 * @return a new test suite |
137 * @return a new test suite |
138 */ |
138 */ |
139 cx_attr_nonnull |
139 cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(1) cx_attr_malloc |
140 cx_attr_nodiscard |
|
141 cx_attr_cstr_arg(1) |
|
142 cx_attr_malloc |
|
143 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
140 static inline CxTestSuite* cx_test_suite_new(const char *name) { |
144 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
141 CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); |
145 if (suite != NULL) { |
142 if (suite != NULL) { |
146 suite->name = name; |
143 suite->name = name; |
147 suite->success = 0; |
144 suite->success = 0; |
155 /** |
152 /** |
156 * Deallocates a test suite. |
153 * Deallocates a test suite. |
157 * |
154 * |
158 * @param suite the test suite to free |
155 * @param suite the test suite to free |
159 */ |
156 */ |
160 static inline void cx_test_suite_free(CxTestSuite* suite) { |
157 CX_INLINE void cx_test_suite_free(CxTestSuite* suite) { |
161 if (suite == NULL) return; |
158 if (suite == NULL) return; |
162 CxTestSet *l = suite->tests; |
159 CxTestSet *l = suite->tests; |
163 while (l != NULL) { |
160 while (l != NULL) { |
164 CxTestSet *e = l; |
161 CxTestSet *e = l; |
165 l = l->next; |
162 l = l->next; |
175 * @param test the test function to register |
172 * @param test the test function to register |
176 * @retval zero success |
173 * @retval zero success |
177 * @retval non-zero failure |
174 * @retval non-zero failure |
178 */ |
175 */ |
179 cx_attr_nonnull |
176 cx_attr_nonnull |
180 static inline int cx_test_register(CxTestSuite* suite, CxTest test) { |
177 CX_INLINE int cx_test_register(CxTestSuite* suite, CxTest test) { |
181 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
178 CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); |
182 if (t) { |
179 if (t) { |
183 t->test = test; |
180 t->test = test; |
184 t->next = NULL; |
181 t->next = NULL; |
185 if (suite->tests == NULL) { |
182 if (suite->tests == NULL) { |
202 * @param suite the test suite to run |
199 * @param suite the test suite to run |
203 * @param out_target the target buffer or file to write the output to |
200 * @param out_target the target buffer or file to write the output to |
204 * @param out_writer the write function writing to @p out_target |
201 * @param out_writer the write function writing to @p out_target |
205 */ |
202 */ |
206 cx_attr_nonnull |
203 cx_attr_nonnull |
207 static inline void cx_test_run(CxTestSuite *suite, |
204 CX_INLINE void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer) { |
208 void *out_target, cx_write_func out_writer) { |
|
209 if (suite->name == NULL) { |
205 if (suite->name == NULL) { |
210 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
206 out_writer("*** Test Suite ***\n", 1, 19, out_target); |
211 } else { |
207 } else { |
212 out_writer("*** Test Suite : ", 1, 17, out_target); |
208 out_writer("*** Test Suite : ", 1, 17, out_target); |
213 out_writer(suite->name, 1, strlen(suite->name), out_target); |
209 out_writer(suite->name, 1, strlen(suite->name), out_target); |