expression
)
ATF_CHECK_EQUAL(
expression_1
, expression_2
)
ATF_TC(
name
)
ATF_TC_BODY(
name
)
ATF_TC_BODY_NAME(
name
)
ATF_TC_CLEANUP(
name
)
ATF_TC_CLEANUP_NAME(
name
)
ATF_TC_HEAD(
name
)
ATF_TC_HEAD_NAME(
name
)
ATF_TC_NAME(
name
)
ATF_TC_WITH_CLEANUP(
name
)
ATF_TP_ADD_TC(
tp_name
)
ATF_TP_ADD_TCS(
tp_name
, tc_name
)
atf_no_error(
)
atf_tc_fail(
reason
)
atf_tc_pass(
)
atf_tc_skip(
reason
)
C-based test programs always follow this template:
... C-specific includes go here ...
#include
ATF_TC(tc1);
ATF_TC_HEAD(tc1)
{
... first test case's header ...
}
ATF_TC_BODY(tc1)
{
... first test case's body ...
}
ATF_TC_WITH_CLEANUP(tc2);
ATF_TC_HEAD(tc2)
{
... second test case's header ...
}
ATF_TC_BODY(tc2)
{
... second test case's body ...
}
ATF_TC_CLEANUP(tc2)
{
... second test case's cleanup ...
}
... additional test cases ...
ATF_TP_ADD_TCS(tp, tcs)
{
ATF_TP_ADD_TC(tcs, tc1)
ATF_TP_ADD_TC(tcs, tc2)
... add additional test cases ...
return atf_no_error();
}
)
or the
ATF_TC_WITH_CLEANUP(
)
macros, which take a single parameter specifiying the test case's name.
The former does not allow the specification of a cleanup routine for the
test case while the latter does.
It is important to note that these
do not
set the test case up for execution when the program is run.
In order to do so, a later registration is needed with the
ATF_TP_ADD_TC(
)
macro detailed in
Program initialization.
Later on, one must define the three parts of the body by means of three
functions.
Their headers are given by the
ATF_TC_HEAD(),
ATF_TC_BODY(
)
and
ATF_TC_CLEANUP(
)
macros, all of which take the test case name provided to the
ATF_TC(
)
or
ATF_TC_WITH_CLEANUP(
)
macros.
Following each of these, a block of code is expected, surrounded by the
opening and closing brackets.
)
function.
You should never define one on your own, but rely on the
library to do it for you.
This is done by using the
ATF_TP_ADD_TCS(
)
macro, which is passed the name of the object that will hold the test
cases; i.e. the test program instance.
This name can be whatever you want as long as it is a valid variable
identifier.
After the macro, you are supposed to provide the body of a function, which
should only use the
ATF_TP_ADD_TC()
macro to register the test cases the test program will execute and return
a success error code.
The first parameter of this macro matches the name you provided in the
former call.
The success status can be returned using the
atf_no_error(
)
function.
)
method, which takes two parameters: the first one specifies the
meta-data variable to be set and the second one specifies its value.
Both of them are strings.
bool
atf_tc_has_config_var(
)
and the
const
char
*
atf_tc_get_config_var(
)
methods, which can be called in any of the three parts of a test case.
)
function, which takes the base name or full path of a single binary.
Relative paths are forbidden.
If it is not found, the test case will be automatically skipped.
),
atf_tc_fail(
)
or
atf_tc_skip(
).
These three functions terminate the execution of the test case immediately.
The cleanup routine will be processed afterwards in a completely automated
way, regardless of the test case's termination reason.
atf_tc_pass()
does not take any parameters.
atf_tc_fail(
)
and
atf_tc_skip(
)
take a single string that describes why the test case failed or
was skipped, respectively.
It is very important to provide a clear error message in both cases so that
the user can quickly know why the test did not pass.
)
with an appropriate error message.
ATF_CHECK()
takes an expression and raises a failure if it evaluates to false.
ATF_CHECK_EQUAL()
takes two expressions and raises a failure if the two do not evaluate to
the same exact value.
#include
ATF_TC(addition);
ATF_TC_HEAD(addition)
{
atf_tc_set_md_var("descr", "Sample tests for the addition operator");
}
ATF_TC_BODY(addition)
{
ATF_CHECK_EQUAL(0 + 0, 0);
ATF_CHECK_EQUAL(0 + 1, 1);
ATF_CHECK_EQUAL(1 + 0, 1);
ATF_CHECK_EQUAL(1 + 1, 2);
ATF_CHECK_EQUAL(100 + 200, 300);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, addition);
return atf_no_error();
}