file
Tester.hClass Corrade::
Contents
- Reference
Namespaces
- namespace Corrade
- Root namespace.
- namespace Corrade::TestSuite
- Test suite.
Classes
- class Corrade::TestSuite::Tester
- Base class for tests and benchmarks.
- class Corrade::TestSuite::Tester::TesterConfiguration
- Tester configuration.
Defines
- #define CORRADE_TEST_MAIN(Class)
- Create
main()
function for given TestSuite::Tester subclass. - #define CORRADE_VERIFY(expression)
- Verify an expression in TestSuite::
Tester subclass. - #define CORRADE_COMPARE(actual, expected)
- Compare two values in TestSuite::
Tester subclass. - #define CORRADE_COMPARE_AS(actual, expected, Type...)
- Compare two values in TestSuite::
Tester subclass with explicitly specified type. - #define CORRADE_COMPARE_WITH(actual, expected, comparatorInstance)
- Compare two values in TestSuite::
Tester subclass with explicitly specified comparator. - #define CORRADE_EXPECT_FAIL(message)
- Expect failure in all following checks in the same scope.
- #define CORRADE_EXPECT_FAIL_IF(condition, message)
- Conditionally expect failure in all following checks in the same scope.
- #define CORRADE_SKIP(message)
- Skip test case.
- #define CORRADE_BENCHMARK(batchSize)
- Run a benchmark.
Define documentation
#define CORRADE_TEST_MAIN(Class)
Create main()
function for given TestSuite::
Populates TestSuite::Class
, executes the test cases and returns from main()
with code based on the test results. This macro has to be used outside of any namespace.
#define CORRADE_VERIFY(expression)
Verify an expression in TestSuite::
If the expression is not true, the expression is printed and execution of given test case is terminated. Example usage:
string s("hello"); CORRADE_VERIFY(!s.empty());
It is possible to use CORRADE_explicit operator bool()
without doing explicit conversion (e.g. using !!
), for example:
std::unique_ptr<T> t(new T); CORRADE_VERIFY(t);
#define CORRADE_COMPARE(actual, expected)
Compare two values in TestSuite::
If the values are not the same, they are printed for comparison and execution of given test case is terminated. Example usage:
int a = 5 + 3; CORRADE_COMPARE(a, 8);
Comparison of floating-point types is by default done as a fuzzy-compare, see TestSuite::
Note that this macro is usable only if given type implements equality comparison operators and is printable via Utility::
#define CORRADE_COMPARE_AS(actual, expected, Type...)
Compare two values in TestSuite::
If the values are not the same, they are printed for comparison and execution of given test case is terminated. Example usage:
CORRADE_COMPARE_AS(std::sin(0.0), 0.0f, float);
See also TestSuite::
Note that this macro is usable only if the type passed to it is printable via Utility::
#define CORRADE_COMPARE_WITH(actual, expected, comparatorInstance)
Compare two values in TestSuite::
If the values are not the same, they are printed for comparison and execution of given test case is terminated. Example usage:
CORRADE_COMPARE_WITH("actual.txt", "expected.txt", Compare::File("/common/path/prefix"));
See TestSuite::
Note that this macro is usable only if the type passed to it is printable via Utility::
#define CORRADE_EXPECT_FAIL(message)
Expect failure in all following checks in the same scope.
Parameters | |
---|---|
message | Message which will be printed into output as indication of expected failure |
Expects failure in all following CORRADE_
{ CORRADE_EXPECT_FAIL("Not implemented."); CORRADE_VERIFY(isFutureClear()); } int i = 6*7; CORRADE_COMPARE(i, 42);
If any of the following checks passes, an error will be printed to output.
#define CORRADE_EXPECT_FAIL_IF(condition, message)
Conditionally expect failure in all following checks in the same scope.
Parameters | |
---|---|
condition | The failure is expected only if the condition evaluates to true |
message | Message which will be printed into output as indication of expected failure |
With CORRADE_if
block:
{ if(answer != 42) CORRADE_EXPECT_FAIL("This is not our universe."); CORRADE_VERIFY(6*7, 49); // always fails }
The solution is to use CORRADE_EXPECT_FAIL_IF()
:
{ CORRADE_EXPECT_FAIL_IF(answer != 42, "This is not our universe."); CORRADE_VERIFY(6*7, 49); // expect the failure if answer is not 42 }
Similarly to CORRADE_explicit operator bool
without doing explicit conversion (e.g. using !!
).
#define CORRADE_SKIP(message)
Skip test case.
Parameters | |
---|---|
message | Message which will be printed into output as indication of skipped test |
Skips all following checks in given test case. Useful for e.g. indicating that given feature can't be tested on given platform:
if(!bigEndian) { CORRADE_SKIP("Big endian compatibility can't be tested on this system."); }
#define CORRADE_BENCHMARK(batchSize)
Run a benchmark.
Benchmarks the following block or expression by measuring batchSize
iterations of given block. Use in conjunction with TestSuite::volatile
variable or combining all the results to a variable, which is then being used outside of the loop.
void benchmark() { std::string a = "hello", b = "world"; CORRADE_BENCHMARK(1000) { volatile std::string c = a + b; } }
The resulting measured value is divided by batchSize
to represent cost of one iteration.