![]() |
Oyranos
git-devel
Oyranos is a full featured Color Management System
|
API testing for prototyping and regression checking in CI. More...
![]() |
Macros | |
#define | TEST_RUN(prog, text, do_it) |
#define | OYJL_TEST_NAME argv[0] |
#define | OYJL_TEST_MAX_COUNT 64 |
#define | OYJL_PRINT_SUB_LENGTH "OYJL_PRINT_SUB_LENGTH" |
#define | PRINT_SUB_BASIC(result_, ...) |
Register status and print info of sub test. More... | |
#define | PRINT_SUB(result_, ...) |
#define | PRINT_SUB_INT(result_, count_, ...) |
#define | PRINT_SUB_PROFILING(result_, integer_, duration_, term_, ...) |
#define | OYJL_TEST_WRITE_RESULT(mem, size, hint, suffix) |
Store test data. More... | |
#define | OYJL_TEST_MAIN_SETUP |
setup Oyjl to your needs by defining this macro More... | |
#define | OYJL_TEST_MAIN_FINISH |
end your test program as you need by defining this macro More... | |
Enumerations | |
enum | oyjlTESTRESULT_e { oyjlTESTRESULT_SYSERROR, oyjlTESTRESULT_FAIL, oyjlTESTRESULT_XFAIL, oyjlTESTRESULT_SUCCESS, oyjlTESTRESULT_UNKNOWN } |
Functions | |
oyjlTESTRESULT_e | oyjlTestRun (oyjlTESTRESULT_e(*test)(void), const char *test_name, int number) |
const char * | oyjlIntToString (int integer) |
const char * | oyjlProfilingToString (int integer, double duration, const char *term) |
const char * | oyjlPrintSub (int space, int right, const char *format,...) |
print test results in a canonical way More... | |
const char * | oyjlPrintSubProfiling (int space, int integer, double duration, const char *term, const char *format,...) |
print test results with profiling in a canonical way More... | |
oyjlTESTRESULT_e | displayFail () |
int | main (int argc, char **argv) |
simple start function for testing program More... | |
Variables | |
FILE * | zout |
int | oyjl_print_sub_length = 51 |
default for printed columns More... | |
oyjlTESTRESULT_e | oy_test_last_result = oyjlTESTRESULT_UNKNOWN |
Result of last sub test. More... | |
char * | oyjl_print_sub = 0 |
int | verbose = 0 |
print more results, when the -v argument is passed to the test program. More... | |
API testing for prototyping and regression checking in CI.
The API is designed to be easily useable without much boilerplate. The implementation is declared and defined in header only. No extra linking is needed, except of libm and libc where required.
Define somewhere in your test.c file a TESTS_RUN with your test functions like:
Then include simply the oyjl_test_main.h header and it defines a main() function for you to handle command line parsing, statistics and summary printing after test program finish.
Include oyjl.h before oyjl_test_main.h, in case you need it.
A complete test file is the self test. It includes the oyjl_test_main.h and implicitely other oyjl_test.h headers and compiles without additional dependencies:
#define OYJL_PRINT_SUB_LENGTH "OYJL_PRINT_SUB_LENGTH" |
Macro to override te name of the OYJL_PRINT_SUB_LENGTH environment variable. The environment variable will be used to detect the desired print width inside sub tests. The oyjl_print_sub_length is set accordingly.
Referenced by oyjlTestRun().
#define OYJL_TEST_MAIN_FINISH |
end your test program as you need by defining this macro
Place this macro in front of your #include oyjl_test_main.h. The macro is called as last entry inside oyjl_test_main.h defined main().
#define OYJL_TEST_MAIN_SETUP |
setup Oyjl to your needs by defining this macro
The macro is called as first entry inside oyjl_test_main.h defined main().
The above example let your code set your own debug variable. So you can see if the -v -v option was set, as that increases *oyjl_debug += 1. Or you can e.g. redefine zout to default to a FILE pointer instead of stdout.
Referenced by main().
#define OYJL_TEST_MAX_COUNT 64 |
Macro to override inbuild default of 64 maximum array length for storing test results.
#define OYJL_TEST_NAME argv[0] |
Macro to set the global test name. It will be used as file name component. in OYJL_TEST_WRITE_RESULT.
#define OYJL_TEST_WRITE_RESULT | ( | mem, | |
size, | |||
hint, | |||
suffix | |||
) |
Store test data.
Write test data to a file for easy error comparision. Use the macro after the PRINT_SUB() of the belonging sub test. The macro will generate the file name containing test related infos, like test number and sub test number, status and possibly your provided hint. That way you can easily find your test data in the writeable test directory. In case one test was successful followed by a failed test and the suffix is "txt", then the diff of the successful and the failed file will be shown.
mem | memory pointer |
size | size of mem to write to file |
hint | optional text to place inside the file name |
suffix | file name suffix |
#define PRINT_SUB | ( | result_, | |
... | |||
) |
Like PRINT_SUB_BASIC but with variable columns size.
#define PRINT_SUB_BASIC | ( | result_, | |
... | |||
) |
Register status and print info of sub test.
Print a custom line to stdout followed by the status. Register state.
The PRINT_SUB_BASIC macro remembers the first file position of similar strongly failed sub tests. As macros count the last closing brace ')', the line number is set to (__LINE__ - 1). So it is suggested to place the status macro in one line to let the position fall in front or use a two line macro with falling the debug position in the start of the macro. Here two examples:
result_ | use oyjlTESTRESULT_e for |
... | the argument list to fprint(stdout, ...) |
#define PRINT_SUB_INT | ( | result_, | |
count_, | |||
... | |||
) |
Like PRINT_SUB_BASIC but with variable columns size and right side integer print.
#define PRINT_SUB_PROFILING | ( | result_, | |
integer_, | |||
duration_, | |||
term_, | |||
... | |||
) |
Like PRINT_SUB_BASIC but with variable columns size and right side profiling print.
#define TEST_RUN | ( | prog, | |
text, | |||
do_it | |||
) |
macro to register a test
prog | test function: oyjlTESTRESULT_e (*test)(void) |
text | name of the test |
do_it | enable the test - usually 1 |
enum oyjlTESTRESULT_e |
oyjlTESTRESULT_e displayFail | ( | ) |
helper to check for availablity of display environment for test status
References oyjlTESTRESULT_FAIL, and oyjlTESTRESULT_XFAIL.
int main | ( | int argc | , |
char ** | argv | ||
) |
simple start function for testing program
The OYJL_TEST_MAIN_SETUP macro can be used to do something initially.
Use the verbose variable in your test code to enable additional result printing. The test command argument '-v' will set the verbose variable to 1, default is 0.
The OYJL_TEST_MAIN_FINISH macro can be used to do something after all tests.
References OYJL_TEST_MAIN_SETUP, oyjlTESTRESULT_UNKNOWN, and zout.
const char* oyjlIntToString | ( | int | integer | ) |
helper to print a number
const char* oyjlPrintSub | ( | int | space, |
int | right, | ||
const char * | format, | ||
... | |||
) |
print test results in a canonical way
The funktion is not reentrant. You need to copy the result if calling repeatedly.
[in] | space | number line width: use -1 for default of 51 |
[in] | right | number for right alignment: use -1 to omit |
[in] | format | printf format |
[in] | ... | variable argument list for format |
References OYJL_CREATE_VA_STRING, oyjl_print_sub_length, and oyjlRegExpReplace().
const char* oyjlPrintSubProfiling | ( | int | space, |
int | integer, | ||
double | duration, | ||
const char * | term, | ||
const char * | format, | ||
... | |||
) |
print test results with profiling in a canonical way
The funktion is not reentrant. You need to copy the result if calling repeatedly.
[in] | space | number line width: use -1 for default columns or 51 |
[in] | integer | arg like for oyjlProfilingToString() |
[in] | duration | arg like for oyjlProfilingToString() |
[in] | term | arg like for oyjlProfilingToString() |
[in] | format | printf format |
[in] | ... | variable argument list for format |
References OYJL_CREATE_VA_STRING, oyjl_print_sub_length, and oyjlRegExpReplace().
const char* oyjlProfilingToString | ( | int | integer, |
double | duration, | ||
const char * | term | ||
) |
helper to print tempo
oyjlTESTRESULT_e oyjlTestRun | ( | oyjlTESTRESULT_e(*)(void) | test, |
const char * | test_name, | ||
int | number | ||
) |
run a test and print results on end
test | test function |
test_name | short string for status line |
number | internal test number |
Handle columns width by checking OYJL_PRINT_SUB_LENGTH envar or using terminal window size by asking linux ioctl or use inbuild default.
Print header line and title.
Print sumarisation of sub test.
References OYJL_PRINT_SUB_LENGTH, and oyjlTESTRESULT_UNKNOWN.
oyjlTESTRESULT_e oy_test_last_result = oyjlTESTRESULT_UNKNOWN |
Result of last sub test.
char* oyjl_print_sub = 0 |
Storage location of last return from oyjlPrintSub() and inside the PRINT_SUB() family respectively.
int oyjl_print_sub_length = 51 |
default for printed columns
Referenced by oyjlPrintSub(), and oyjlPrintSubProfiling().
int verbose = 0 |
print more results, when the -v argument is passed to the test program.
FILE* zout |
FILE descriptor for printed inbetween results
A good default might be stdout for a CLI program.
Referenced by main().