16 ``` |
16 ``` |
17 |
17 |
18 A test case needs to be defined with the `CX_TEST` macro. |
18 A test case needs to be defined with the `CX_TEST` macro. |
19 The general structure of a test case is 1) setup code, 2) the actual test, 3) tear down code. |
19 The general structure of a test case is 1) setup code, 2) the actual test, 3) tear down code. |
20 In UCX this is realized by the `CX_TEST_DO` macro with which you can define a scope for the actual test. |
20 In UCX this is realized by the `CX_TEST_DO` macro with which you can define a scope for the actual test. |
21 Whenever a test assertion fails, the scope is exited and the tear down code is executed. |
21 Whenever a test assertion fails, the scope is exited and the tear-down code is executed. |
22 |
22 |
23 <tabs> |
23 <tabs> |
24 <tab title="Test"> |
24 <tab title="Test"> |
25 <code-block lang="C"><![CDATA[ |
25 <code-block lang="C"><![CDATA[ |
26 CX_TEST(test_foo) { |
26 CX_TEST(test_foo) { |
108 } |
108 } |
109 free(x); |
109 free(x); |
110 } |
110 } |
111 ``` |
111 ``` |
112 |
112 |
113 > Any test function, test case or test subroutine, is a normal C function. |
113 > Any test function, test case or test subroutine is a normal C function. |
114 > As such you can decide to make them `static` when you do not want external linkage. |
114 > As such you can decide to make them `static` when you do not want external linkage. |
115 > For example, just define the test as `static CX_TEST(test_foo)` instead of `CX_TEST(test_foo)`. |
115 > For example, you can define the test as `static CX_TEST(test_foo)` instead of `CX_TEST(test_foo)`. |
116 |
116 |
117 <seealso> |
117 <seealso> |
118 <category ref="apidoc"> |
118 <category ref="apidoc"> |
119 <a href="https://ucx.sourceforge.io/api/test_8h.html">test.h</a> |
119 <a href="https://ucx.sourceforge.io/api/test_8h.html">test.h</a> |
120 </category> |
120 </category> |