#include "testlib.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <inttypes.h>
#include "timer.h"
Enumerations | |
enum | VerbosityLevel { LEVEL_RESULT = 0, LEVEL_GOODRESULT, LEVEL_INFO, LEVEL_LOC, LEVEL_FUNC, LEVEL_DEBUG } |
Verbosity level for output function. More... | |
Functions | |
int | testlib_verbose () |
Increase verbosity level to get more output. More... | |
int | testlib_silent () |
Decrease verbosity level to get less output. More... | |
void | testlib_add_column (const char *name, const char *fmt) |
Adds a new data column for data-driven tests. More... | |
void | testlib_add_row (const char *name,...) |
Adds a new data row for data-driven tests. More... | |
void * | testlib_fetch (const char *name) |
Returns the data for the given column name of the current test dataset. More... | |
int | testlib_fetch_int (const char *name) |
This function behaves exactly like testlib_fetch() but returns an int value previously stored in a %i or %d column. More... | |
unsigned int | testlib_fetch_uint (const char *name) |
This function behaves exactly like testlib_fetch() but returns an unsigned int value previously stored in a %u column. More... | |
double | testlib_fetch_double (const char *name) |
This function behaves exactly like testlib_fetch() but returns a double value previously stored in a %f column. More... | |
void | testlib_run_tests (const char *testname, const char *testset) |
Executes registered test functions. More... | |
void | testlib_list_tests () |
Lists all registered test functions. More... | |
struct testlib_stat * | testlib_result () |
Returns the test result statistic. More... | |
int | testlib_main (int argc, char *argv[]) |
Test main implementation used by UTEST_MAIN. More... | |
add test suites
add support for test skipping
enum VerbosityLevel |
Verbosity level for output function.
The verbosity level can be increased by calling testlib_verbose.
By default if a test fails you get detailed information about the problem:
If the test passes you only see the test result.
By increasing the verbosity leve you can get more information also for passed tests. You can increase the verbosity level by calling testlib_verbose().
void testlib_add_column | ( | const char * | name, |
const char * | fmt | ||
) |
Adds a new data column for data-driven tests.
Call this function only in a test-data preperation function.
name | Name of the column. Used also in testlib_fetch(). |
fmt | Printf like format specifier. |
The following format specifiers are currently supported:
Fmt | Description |
---|---|
%s | C String |
%p | Pointer type |
%i / %d | int |
%u | unsigned int |
%f | double |
Note: In C float
values passed via ... to a variadic function are promoted to double
. char
and short
are promoted to int
. That's why there are only testlib_fetch_int and testlib_fetch_double functions and no functions for float
, short
and char
.
void testlib_add_row | ( | const char * | name, |
... | |||
) |
Adds a new data row for data-driven tests.
Call this function only in a test-data preperation function.
name | Name of the test set. This is used in the output to see with what dataset the test fails. |
... | The subsequent arguments must match the number of specified columns and type. |
void* testlib_fetch | ( | const char * | name | ) |
Returns the data for the given column name
of the current test dataset.
Only call this in data-driven test functions.
The test function is called once for each dataset.
name | the column name registered with testlib_add_column() |
double testlib_fetch_double | ( | const char * | name | ) |
This function behaves exactly like testlib_fetch() but returns a double value previously stored in a %f column.
name | the column name registered with testlib_add_column() |
int testlib_fetch_int | ( | const char * | name | ) |
This function behaves exactly like testlib_fetch() but returns an int value previously stored in a %i or %d column.
name | the column name registered with testlib_add_column() |
unsigned int testlib_fetch_uint | ( | const char * | name | ) |
This function behaves exactly like testlib_fetch() but returns an unsigned int value previously stored in a %u column.
name | the column name registered with testlib_add_column() |
void testlib_list_tests | ( | ) |
Lists all registered test functions.
int testlib_main | ( | int | argc, |
char * | argv[] | ||
) |
Test main implementation used by UTEST_MAIN.
This is a simplified version of testlib_main for systems which have no getopt() implementation or if you simply want to avoid the additional code of getopt(). Of course here you have no commandline option parsing, but it still allows to specify one testname.
struct testlib_stat* testlib_result | ( | ) |
Returns the test result statistic.
void testlib_run_tests | ( | const char * | testname, |
const char * | testset | ||
) |
Executes registered test functions.
If testname
is NULL all functions are executed, otherwise only the one matching testname
. If testset
is NULL all datasets are used for data-driven tests, otherwise only the one matching testset
.
int testlib_silent | ( | ) |
Decrease verbosity level to get less output.
int testlib_verbose | ( | ) |
Increase verbosity level to get more output.