ucx/cx/test.h

changeset 888
af685cc9d623
parent 852
83fdf679df99
equal deleted inserted replaced
877:b60487c3ec36 888:af685cc9d623
54 * } 54 * }
55 * // cleanup of memory here 55 * // cleanup of memory here
56 * } 56 * }
57 * </code> 57 * </code>
58 * 58 *
59 * @attention Do not call own functions within a test, that use 59 * @attention Do not call own functions within a test that use
60 * CX_TEST_ASSERT() macros and are not defined by using CX_TEST_SUBROUTINE(). 60 * CX_TEST_ASSERT() macros and are not defined by using CX_TEST_SUBROUTINE().
61 * 61 *
62 * @author Mike Becker 62 * @author Mike Becker
63 * @author Olaf Wintermann 63 * @author Olaf Wintermann
64 * 64 *
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;
169 } 166 }
170 167
171 /** 168 /**
172 * Registers a test function with the specified test suite. 169 * Registers a test function with the specified test suite.
173 * 170 *
174 * @param suite the suite, the test function shall be added to 171 * @param suite the suite the test function shall be added to
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);
261 * } 257 * }
262 * // tear down code 258 * // tear down code
263 * } 259 * }
264 * @endcode 260 * @endcode
265 * 261 *
266 * @attention Any CX_TEST_ASSERT() calls must be performed in scope of 262 * @attention Any CX_TEST_ASSERT() calls must be performed in the scope of
267 * #CX_TEST_DO. 263 * #CX_TEST_DO.
268 */ 264 */
269 #define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\ 265 #define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\
270 _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\ 266 _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
271 _writefnc_("... ", 1, 4, _output_);\ 267 _writefnc_("... ", 1, 4, _output_);\

mercurial