Writing Test Cases¶
libMariaS3 uses DDM4’s YATL library to create unit tests, this provides macros to test if the outcomes are as expected.
Adding a Test Case¶
Test cases are basic C applications in the tests/
directory. To add a test case to the suite. To add a test edit the include.am
and add the following (replacing mytest with whatever the test is called):
t_mytest_SOURCES= tests/mytest.c
t_mytest_LDADD= src/libmarias3.la
check_PROGRAMS+= t/mytest
noinst_PROGRAMS+= t/mytest
Using YATL¶
YATL is needed to make sure conditions within the test program are met. To include it in your test application, add the following:
#include <yatl/lite.h>
A test skip can be added if certain conditions aren’t met:
SKIP_IF_(!is_connected, "Cannot connected to a database server")
There are many types of assert provided as can be seen in the next section, they can be used as follows:
ASSERT_EQ_(3, column, "Column count unexpected)
ASSERT_FALSE_(false_condition, "False condition is not false")
ASSERT_STREQ_("test", some_data, "Unexpected data")
YATL Library¶
Parameter Definitions¶
-
__expression
¶ An expression typically used in an
if
statement.
-
__expected
¶ An expected variable or expression
-
__actual
¶ The actual variable or expression
-
__expected_str
¶ The expected string
-
__actual_str
¶ The actual string to compare with
-
__length
¶ The length of a string for comparison
Function Definitions¶
-
SKIP_IF
(__expression)¶ Skips the test if the expression is true
-
SKIP_IF_
(__expression, ...)¶ Skips the test if the expression is true and uses a printf style format message
-
ASSERT_TRUE
(__expression)¶ Make sure the expression is true, test will fail if it is false
-
ASSERT_FALSE
(__expression)¶ Make sure the expression is false, test will fail if it is true
-
ASSERT_FALSE_
(__expression, ...)¶ Make sure the expression is false and use a printf style format message to fail if it is true.
-
ASSERT_NULL_
(__expression, ...)¶ Make sure the expression is
NULL
and use a printf style format message to fail if it isn’t.
-
ASSERT_NOT_NULL
(__expression)¶ Make sure the expression is not
NULL
, test will fail if it isNULL
.
-
ASSERT_NOT_NULL_
(__expression, ...)¶ Make sure the expression is not
NULL
and use a printf style format message to fail if it is.
-
ASSERT_TRUE_
(__expression, ...)¶ Make sure the expression is
true
and use a printf style format message to fail if it is not.
-
ASSERT_EQ
(__expected, __actual)¶ Make sure that one condition or variable matches another one.
Note
Not suitable for string matching
-
ASSERT_EQ_
(__expected, __actual, ...)¶ Make sure that one condition or variable matches another one and use a printf style format message to fail if the do not match.
Note
Not suitable for string matching
-
ASSERT_NEQ
(__expected, __actual)¶ Make sure that one condition or variable does not match another one.
Note
Not suitable for string matching
-
ASSERT_NEQ_
(__expected, __actual, ...)¶ Make sure that one condition or variable does not match another one and use a printf style format message to fail if they do match.
Note
Not suitable for string matching
-
ASSERT_STREQ
(__expected_str, __actual_str)¶ Compare one
NUL
terminated string with another one and fail if they do not match.
-
ASSERT_STREQ_
(__expected_str, __actual_str, ...)¶ Compare one
NUL
terminated string with another one and use a printf style format message to fail if they do not match.
-
ASSERT_STREQL_
(__expected_str, __actual_str, __length, ...)¶ Compare a string of
__length
to another one and use a printf style format message to fail if they do not match.Note
This is designed for use with non-NUL-terminated strings.
-
ASSERT_STRNE
(__expected_str, __actual_str)¶ Compare one
NUL
terminated string with another one and fail if they match.
-
ASSERT_STRNE_
(__expected_str, __actual_str, ...)¶ Compare one
NUL
terminated string with another one and use a printf style format message to fail if they match.