Check
Unit testing framework for C
Defines | Typedefs | Enumerations | Functions
check.h File Reference
#include <stddef.h>
#include <string.h>
#include <check_stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Defines

#define tcase_add_test(tc, tf)   tcase_add_test_raise_signal(tc,tf,0)
#define tcase_add_test_raise_signal(tc, tf, signal)   _tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 0, 1)
#define tcase_add_exit_test(tc, tf, expected_exit_value)   _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),0,1)
#define tcase_add_loop_test(tc, tf, s, e)   _tcase_add_test((tc),(tf),"" # tf "",0,0,(s),(e))
#define tcase_add_loop_test_raise_signal(tc, tf, signal, s, e)   _tcase_add_test((tc),(tf),"" # tf "",(signal),0,(s),(e))
#define tcase_add_loop_exit_test(tc, tf, expected_exit_value, s, e)   _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),(s),(e))
#define START_TEST(__testname)
#define END_TEST   }
#define ck_assert(expr)   ck_assert_msg(expr, NULL)
#define ck_assert_msg(expr,...)
#define ck_abort()   ck_abort_msg(NULL)
#define ck_abort_msg(...)   _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
#define ck_assert_int_eq(X, Y)   _ck_assert_int(X, ==, Y)
#define ck_assert_int_ne(X, Y)   _ck_assert_int(X, !=, Y)
#define ck_assert_int_lt(X, Y)   _ck_assert_int(X, <, Y)
#define ck_assert_int_le(X, Y)   _ck_assert_int(X, <=, Y)
#define ck_assert_int_gt(X, Y)   _ck_assert_int(X, >, Y)
#define ck_assert_int_ge(X, Y)   _ck_assert_int(X, >=, Y)
#define ck_assert_uint_eq(X, Y)   _ck_assert_uint(X, ==, Y)
#define ck_assert_uint_ne(X, Y)   _ck_assert_uint(X, !=, Y)
#define ck_assert_uint_lt(X, Y)   _ck_assert_uint(X, <, Y)
#define ck_assert_uint_le(X, Y)   _ck_assert_uint(X, <=, Y)
#define ck_assert_uint_gt(X, Y)   _ck_assert_uint(X, >, Y)
#define ck_assert_uint_ge(X, Y)   _ck_assert_uint(X, >=, Y)
#define ck_assert_str_eq(X, Y)   _ck_assert_str(X, ==, Y)
#define ck_assert_str_ne(X, Y)   _ck_assert_str(X, !=, Y)
#define ck_assert_str_lt(X, Y)   _ck_assert_str(X, <, Y)
#define ck_assert_str_le(X, Y)   _ck_assert_str(X, <=, Y)
#define ck_assert_str_gt(X, Y)   _ck_assert_str(X, >, Y)
#define ck_assert_str_ge(X, Y)   _ck_assert_str(X, >=, Y)
#define ck_assert_ptr_eq(X, Y)   _ck_assert_ptr(X, ==, Y)
#define ck_assert_ptr_ne(X, Y)   _ck_assert_ptr(X, !=, Y)
#define mark_point()   _mark_point(__FILE__,__LINE__)

Typedefs

typedef struct TCase TCase
typedef void(* TFun )(int)
typedef void(* SFun )(void)
typedef struct Suite Suite
typedef struct SRunner SRunner
typedef struct TestResult TestResult

Enumerations

enum  test_result { CK_TEST_RESULT_INVALID, CK_PASS, CK_FAILURE, CK_ERROR }
enum  print_output {
  CK_SILENT, CK_MINIMAL, CK_NORMAL, CK_VERBOSE,
  CK_ENV, CK_SUBUNIT, CK_LAST
}
enum  ck_result_ctx { CK_CTX_INVALID, CK_CTX_SETUP, CK_CTX_TEST, CK_CTX_TEARDOWN }
enum  fork_status { CK_FORK_GETENV, CK_FORK, CK_NOFORK }

Functions

CK_DLL_EXP Suite *CK_EXPORT suite_create (const char *name)
CK_DLL_EXP int CK_EXPORT suite_tcase (Suite *s, const char *tcname)
CK_DLL_EXP void CK_EXPORT suite_add_tcase (Suite *s, TCase *tc)
CK_DLL_EXP TCase *CK_EXPORT tcase_create (const char *name)
CK_DLL_EXP void CK_EXPORT tcase_add_unchecked_fixture (TCase *tc, SFun setup, SFun teardown)
CK_DLL_EXP void CK_EXPORT tcase_add_checked_fixture (TCase *tc, SFun setup, SFun teardown)
CK_DLL_EXP void CK_EXPORT tcase_set_timeout (TCase *tc, double timeout)
CK_DLL_EXP void CK_EXPORT tcase_fn_start (const char *fname, const char *file, int line)
CK_DLL_EXP int CK_EXPORT tr_rtype (TestResult *tr)
CK_DLL_EXP enum ck_result_ctx
CK_EXPORT 
tr_ctx (TestResult *tr)
CK_DLL_EXP const char *CK_EXPORT tr_msg (TestResult *tr)
CK_DLL_EXP int CK_EXPORT tr_lno (TestResult *tr)
CK_DLL_EXP const char *CK_EXPORT tr_lfile (TestResult *tr)
CK_DLL_EXP const char *CK_EXPORT tr_tcname (TestResult *tr)
CK_DLL_EXP SRunner *CK_EXPORT srunner_create (Suite *s)
CK_DLL_EXP void CK_EXPORT srunner_add_suite (SRunner *sr, Suite *s)
CK_DLL_EXP void CK_EXPORT srunner_free (SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_run_all (SRunner *sr, enum print_output print_mode)
CK_DLL_EXP void CK_EXPORT srunner_run (SRunner *sr, const char *sname, const char *tcname, enum print_output print_mode)
CK_DLL_EXP int CK_EXPORT srunner_ntests_failed (SRunner *sr)
CK_DLL_EXP int CK_EXPORT srunner_ntests_run (SRunner *sr)
CK_DLL_EXP TestResult **CK_EXPORT srunner_failures (SRunner *sr)
CK_DLL_EXP TestResult **CK_EXPORT srunner_results (SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_print (SRunner *sr, enum print_output print_mode)
CK_DLL_EXP void CK_EXPORT srunner_set_log (SRunner *sr, const char *fname)
CK_DLL_EXP int CK_EXPORT srunner_has_log (SRunner *sr)
CK_DLL_EXP const char *CK_EXPORT srunner_log_fname (SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_set_xml (SRunner *sr, const char *fname)
CK_DLL_EXP int CK_EXPORT srunner_has_xml (SRunner *sr)
CK_DLL_EXP const char *CK_EXPORT srunner_xml_fname (SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_set_tap (SRunner *sr, const char *fname)
CK_DLL_EXP int CK_EXPORT srunner_has_tap (SRunner *sr)
CK_DLL_EXP const char *CK_EXPORT srunner_tap_fname (SRunner *sr)
CK_DLL_EXP enum fork_status
CK_EXPORT 
srunner_fork_status (SRunner *sr)
CK_DLL_EXP void CK_EXPORT srunner_set_fork_status (SRunner *sr, enum fork_status fstat)
CK_DLL_EXP pid_t CK_EXPORT check_fork (void)
CK_DLL_EXP void CK_EXPORT check_waitpid_and_exit (pid_t pid) CK_ATTRIBUTE_NORETURN

Define Documentation

#define ck_abort ( )    ck_abort_msg(NULL)

Unconditionally fail the test

Note:
Once called, the remaining of the test is aborted
Since:
0.9.6
#define ck_abort_msg (   ...)    _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)

Unconditionally fail the test; print a message

Parameters:
...message to print (in printf format)
Note:
Once called, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert (   expr)    ck_assert_msg(expr, NULL)

Fail the test if expression is false

Parameters:
exprexpression to evaluate
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_int_eq (   X,
 
)    _ck_assert_int(X, ==, Y)

Check two signed integers to determine if X==Y

If not X==Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_int_ge (   X,
 
)    _ck_assert_int(X, >=, Y)

Check two signed integers to determine if X>=Y

If not X>=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_int_gt (   X,
 
)    _ck_assert_int(X, >, Y)

Check two signed integers to determine if X>Y

If not X>Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_int_le (   X,
 
)    _ck_assert_int(X, <=, Y)

Check two signed integers to determine if X<=Y

If not X<=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_int_lt (   X,
 
)    _ck_assert_int(X, <, Y)

Check two signed integers to determine if X<Y

If not X<Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_int_ne (   X,
 
)    _ck_assert_int(X, !=, Y)

Check two signed integers to determine if X!=Y

If not X!=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_msg (   expr,
  ... 
)
Value:
(expr) ? \
     _mark_point(__FILE__, __LINE__) : \
     _ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL)

Fail the test if the expression is false; print message on failure

Parameters:
exprexpression to evaluate
...message to print (in printf format) if expression is false
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_ptr_eq (   X,
 
)    _ck_assert_ptr(X, ==, Y)

Check if two pointers are equal.

If the two passed pointers are not equal, the test fails.

Parameters:
Xpointer
Ypointer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_ptr_ne (   X,
 
)    _ck_assert_ptr(X, !=, Y)

Check if two pointers are not.

If the two passed pointers are equal, the test fails.

Parameters:
Xpointer
Ypointer to compare against X
Since:
0.9.10
#define ck_assert_str_eq (   X,
 
)    _ck_assert_str(X, ==, Y)

Check two strings to determine if 0==strcmp(X,Y)

If not 0==strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_str_ge (   X,
 
)    _ck_assert_str(X, >=, Y)

Check two strings to determine if 0>=strcmp(X,Y) (e.g. strcmp(X,Y)<=0)

If not 0>=strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_str_gt (   X,
 
)    _ck_assert_str(X, >, Y)

Check two strings to determine if 0<strcmp(X,Y) (e.g. strcmp(X,Y)>0)

If not 0<strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_str_le (   X,
 
)    _ck_assert_str(X, <=, Y)

Check two strings to determine if 0<=strcmp(X,Y) (e.g. strcmp(X,Y)>=0)

If not 0<=strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_str_lt (   X,
 
)    _ck_assert_str(X, <, Y)

Check two strings to determine if 0<strcmp(X,Y), (e.g. strcmp(X,Y)>0)

If not 0<strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_str_ne (   X,
 
)    _ck_assert_str(X, !=, Y)

Check two strings to determine if 0!=strcmp(X,Y)

If not 0!=strcmp(X,Y), the test fails.

Parameters:
Xstring
Ystring to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.6
#define ck_assert_uint_eq (   X,
 
)    _ck_assert_uint(X, ==, Y)

Check two unsigned integers to determine if X==Y

If not X==Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_uint_ge (   X,
 
)    _ck_assert_uint(X, >=, Y)

Check two unsigned integers to determine if X>=Y

If not X>=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_uint_gt (   X,
 
)    _ck_assert_uint(X, >, Y)

Check two unsigned integers to determine if X>Y

If not X>Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_uint_le (   X,
 
)    _ck_assert_uint(X, <=, Y)

Check two unsigned integers to determine if X<=Y

If not X<=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_uint_lt (   X,
 
)    _ck_assert_uint(X, <, Y)

Check two unsigned integers to determine if X<Y

If not X<Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define ck_assert_uint_ne (   X,
 
)    _ck_assert_uint(X, !=, Y)

Check two unsigned integers to determine if X!=Y

If not X!=Y, the test fails.

Parameters:
Xsigned integer
Ysigned integer to compare against X
Note:
If the check fails, the remaining of the test is aborted
Since:
0.9.10
#define END_TEST   }

End a unit test

Since:
0.6.0
#define mark_point ( )    _mark_point(__FILE__,__LINE__)

Mark the last point reached in a unit test.

If the test throws a signal or exits, the location noted with the failure is the last location of a ck_assert*() or ck_abort() call. Use mark_point() to record intermediate locations (useful for tracking down crashes or exits).

Since:
0.6.0
#define START_TEST (   __testname)
Value:
static void __testname (int _i CK_ATTRIBUTE_UNUSED)\
{\
  tcase_fn_start (""# __testname, __FILE__, __LINE__);

Start a unit test with START_TEST(unit_name), end with END_TEST.

One must use braces within a START_/END_ pair to declare new variables

Since:
0.6.0
#define tcase_add_exit_test (   tc,
  tf,
  expected_exit_value 
)    _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),0,1)

Add a test function with an expected exit value to a test case

The added test is expected to terminate by exiting with the given value

Parameters:
tctest case to add test to
tftest function to add to test case
expected_exit_valueexit value for test function to return in order for the test to be considered passing
Since:
0.9.7
#define tcase_add_loop_exit_test (   tc,
  tf,
  expected_exit_value,
  s,
 
)    _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),(s),(e))

Add a looping test function with an expected exit value to a test case

The test will be called in a for(i = s; i < e; i++) loop with each iteration being executed in a new context. The loop variable 'i' is available in the test.

The added test is expected to terminate by exiting with the given value

Parameters:
tctest case to add test to
tffunction to add to test case
expected_exit_valueexit value for test function to return in order for the test to be considered passing
sstarting index for value "i" in test
eending index for value "i" in test
Since:
0.9.7
#define tcase_add_loop_test (   tc,
  tf,
  s,
 
)    _tcase_add_test((tc),(tf),"" # tf "",0,0,(s),(e))

Add a looping test function to a test case

The test will be called in a for(i = s; i < e; i++) loop with each iteration being executed in a new context. The loop variable 'i' is available in the test.

Parameters:
tctest case to add test to
tffunction to add to test case
sstarting index for value "i" in test
eending index for value "i" in test
Since:
0.9.4
#define tcase_add_loop_test_raise_signal (   tc,
  tf,
  signal,
  s,
 
)    _tcase_add_test((tc),(tf),"" # tf "",(signal),0,(s),(e))

Add a looping test function with signal handling to a test case

The test will be called in a for(i = s; i < e; i++) loop with each iteration being executed in a new context. The loop variable 'i' is available in the test.

The added test is expected to terminate by throwing the given signal

Todo:
add a test case; this is untested as part of Check's tests.
Parameters:
tctest case to add test to
tffunction to add to test case
signalexpected signal for test function to throw in order for the test to be considered passing
sstarting index for value "i" in test
eending index for value "i" in test
Since:
0.9.5
#define tcase_add_test (   tc,
  tf 
)    tcase_add_test_raise_signal(tc,tf,0)

Add a test function to a test case

Parameters:
tctest case to add test to
tftest function to add to test case
Since:
0.6.0
#define tcase_add_test_raise_signal (   tc,
  tf,
  signal 
)    _tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 0, 1)

Add a test function with signal handling to a test case

The added test is expected to terminate by throwing the given signal

Parameters:
tctest case to add test to
tftest function to add to test case
signalexpected signal for test function to throw in order for the test to be considered passing
Since:
0.9.2

Typedef Documentation

typedef void(* SFun)(void)

Type for a setup/teardown function

typedef struct SRunner SRunner

Holds state for a running of a test suite

typedef struct Suite Suite

Type for a test suite

typedef struct TCase TCase

Type for a test case

A TCase represents a test case. Create with tcase_create, free with tcase_free. For the moment, test cases can only be run through a suite

typedef struct TestResult TestResult

Opaque type for a test failure

typedef void(* TFun)(int)

Type for a test function


Enumeration Type Documentation

Enum representing the types of contexts for a test

Enumerator:
CK_CTX_INVALID 

Default value; should not encounter this

CK_CTX_SETUP 

Setup before a test

CK_CTX_TEST 

Body of test itself

CK_CTX_TEARDOWN 

Teardown after a test

Enum describing the current fork usage.

Enumerator:
CK_FORK_GETENV 

look in the environment for CK_FORK

CK_FORK 

call fork to run tests

CK_NOFORK 

don't call fork

Enum specifying the verbosity of output a SRunner should produce

Enumerator:
CK_SILENT 

No output

CK_MINIMAL 

Only summary output

CK_NORMAL 

All failed tests

CK_VERBOSE 

All tests

CK_ENV 

Look at environment var CK_VERBOSITY for what verbosity to use, which can be either "silent", "minimal", "normal", or "verbose". If the environment variable is not set, then CK_NORMAL will be used.

CK_SUBUNIT 

Run as a subunit child process

CK_LAST 

Not a valid option

Enum describing the possible results of a test

Enumerator:
CK_TEST_RESULT_INVALID 

Default value; should not encounter this

CK_PASS 

Test passed

CK_FAILURE 

Test completed but failed

CK_ERROR 

Test failed to complete (unexpected signal or non-zero early exit)


Function Documentation

CK_DLL_EXP pid_t CK_EXPORT check_fork ( void  )

Invoke fork() during a test and assign the child to the same process group that the rest of the test case uses.

One can invoke fork() directly during a test; however doing so may not guarantee that any children processes are destroyed once the test finishes. Once a test has completed, all processes in the process group will be killed; using this wrapper will prevent orphan processes.

Returns:
On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, an error will be printed and exit() invoked.
Since:
0.9.3
CK_DLL_EXP void CK_EXPORT check_waitpid_and_exit ( pid_t  pid)

Wait for the pid and exit.

This is to be used in conjunction with check_fork(). When called, will wait for the given process to terminate. If the process exited without error, exit(EXIT_SUCCESS) is invoked; otherwise exit(EXIT_FAILURE) is invoked.

Parameters:
pidprocess to wait for, created by check_fork()
Since:
0.9.3
CK_DLL_EXP void CK_EXPORT srunner_add_suite ( SRunner sr,
Suite s 
)

Add an additional suite to a suite runner.

The first suite in a suite runner is always added in srunner_create(). This call adds additional suites to a suite runner.

Parameters:
srsuite runner to add the given suite
ssuite to add to the given suite runner
Since:
0.7.0
CK_DLL_EXP SRunner* CK_EXPORT srunner_create ( Suite s)

Creates a suite runner for the given suite.

Once created, additional suites can be added to the suite runner using srunner_add_suite(), and the suite runner can be run with srunner_run_all(). Once finished, the suite runner must be freed with srunner_free().

Parameters:
ssuite to generate a suite runner for
Returns:
suite runner for the given suite
Since:
0.6.0
CK_DLL_EXP TestResult** CK_EXPORT srunner_failures ( SRunner sr)

Return an array of results for all failures found by a suite runner.

Number of results is equal to srunner_nfailed_tests().

Information about individual results can be queried using: tr_rtype(), tr_ctx(), tr_msg(), tr_lno(), tr_lfile(), and tr_tcname().

Memory is malloc'ed and must be freed; however free the entire structure instead of individual test cases.

Parameters:
srsuite runner to retrieve results from
Returns:
array of TestResult objects
Since:
0.6.0
CK_DLL_EXP enum fork_status CK_EXPORT srunner_fork_status ( SRunner sr)

Retrieve the current fork status for the given suite runner

Parameters:
srsuite runner to check fork status of
Since:
0.8.0
CK_DLL_EXP void CK_EXPORT srunner_free ( SRunner sr)

Frees a suite runner, including all contained suite and test cases.

This call is responsible for freeing all resources related to a suite runner and all contained suites and test cases. Suite and test cases need not be freed individually, as this call handles that.

Parameters:
srsuite runner to free
Since:
0.6.0
CK_DLL_EXP int CK_EXPORT srunner_has_log ( SRunner sr)

Checks if the suite runner is assigned a file for log output.

Parameters:
srsuite runner to check
Returns:
1 iff the suite runner currently is configured to output in log format; 0 otherwise
Since:
0.7.1
CK_DLL_EXP int CK_EXPORT srunner_has_tap ( SRunner sr)

Checks if the suite runner is assigned a file for TAP output.

Parameters:
srsuite runner to check
Returns:
1 iff the suite runner currently is configured to output in TAP format; 0 otherwise
Since:
0.9.12
CK_DLL_EXP int CK_EXPORT srunner_has_xml ( SRunner sr)

Checks if the suite runner is assigned a file for XML output.

Parameters:
srsuite runner to check
Returns:
1 iff the suite runner currently is configured to output in XML format; 0 otherwise
Since:
0.9.1
CK_DLL_EXP const char* CK_EXPORT srunner_log_fname ( SRunner sr)

Retrieves the name of the currently assigned file for log output, if any exists.

Returns:
the name of the log file, or NULL if none is configured
Since:
0.7.1
CK_DLL_EXP int CK_EXPORT srunner_ntests_failed ( SRunner sr)

Retrieve the number of failed tests executed by a suite runner.

This value represents both test failures and errors.

Parameters:
srsuite runner to query for all failed tests
Returns:
number of test failures and errors found by the suite runner
Since:
0.6.1
CK_DLL_EXP int CK_EXPORT srunner_ntests_run ( SRunner sr)

Retrieve the total number of tests run by a suite runner.

Parameters:
srsuite runner to query for all tests run
Returns:
number of all tests run by the suite runner
Since:
0.6.1
CK_DLL_EXP void CK_EXPORT srunner_print ( SRunner sr,
enum print_output  print_mode 
)

Print the results contained in an SRunner to stdout.

Parameters:
srsuite runner to print results for to stdout
print_modethe print_output (verbosity) to use to report the result
Since:
0.7.0
CK_DLL_EXP TestResult** CK_EXPORT srunner_results ( SRunner sr)

Return an array of results for all tests run by a suite runner.

Number of results is equal to srunner_ntests_run(), and excludes failures due to setup function failure.

Information about individual results can be queried using: tr_rtype(), tr_ctx(), tr_msg(), tr_lno(), tr_lfile(), and tr_tcname().

Memory is malloc'ed and must be freed; however free the entire structure instead of individual test cases.

Parameters:
srsuite runner to retrieve results from
Returns:
array of TestResult objects
Since:
0.6.1
CK_DLL_EXP void CK_EXPORT srunner_run ( SRunner sr,
const char *  sname,
const char *  tcname,
enum print_output  print_mode 
)

Run a specific suite or test case from a suite runner, printing results to stdout as specified by the print_mode.

In addition to running any applicable suites or test cases, if the suite runner has been configured to output to a log, that is also performed.

Parameters:
srsuite runner where the given suite or test case must be
snamesuite name to run. A NULL means "any suite".
tcnametest case name to run. A NULL means "any test case"
print_modethe verbosity in which to report results to stdout
Since:
0.9.9
CK_DLL_EXP void CK_EXPORT srunner_run_all ( SRunner sr,
enum print_output  print_mode 
)

Runs a suite runner and all contained suite, printing results to stdout as specified by the print_mode.

In addition to running all suites, if the suite runner has been configured to output to a log, that is also performed.

Note that if the CK_RUN_CASE and/or CK_RUN_SUITE environment variables are defined, then only the named suite and/or test case is run.

Parameters:
srsuite runner to run all suites from
print_modethe verbosity in which to report results to stdout
Since:
0.6.0
CK_DLL_EXP void CK_EXPORT srunner_set_fork_status ( SRunner sr,
enum fork_status  fstat 
)

Set the fork status for a given suite runner.

The default fork status is CK_FORK_GETENV, which will look for the CK_FORK environment variable, which can be set to "yes" or "no". If the environment variable is not present, CK_FORK will be used if fork() is available on the system, otherwise CK_NOFORK is used.

If set to CK_FORK or CK_NOFORK, the environment variable if defined is ignored.

Parameters:
srsuite runner to assign the fork status to
fstatfork status to assign
Since:
0.8.0
CK_DLL_EXP void CK_EXPORT srunner_set_log ( SRunner sr,
const char *  fname 
)

Set the suite runner to output the result in log format to the given file.

Note: log file setting is an initialize only operation -- it should be done immediately after SRunner creation, and the log file can't be changed after being set.

This setting does not conflict with the other log output types; all logging types can occur concurrently if configured.

Parameters:
srsuite runner to log results of in log format
fnamefile name to output log results to
Since:
0.7.1
CK_DLL_EXP void CK_EXPORT srunner_set_tap ( SRunner sr,
const char *  fname 
)

Set the suite runner to output the result in TAP format to the given file.

Note: TAP file setting is an initialize only operation -- it should be done immediately after SRunner creation, and the TAP file can't be changed after being set.

This setting does not conflict with the other log output types; all logging types can occur concurrently if configured.

Parameters:
srsuite runner to log results of in TAP format
fnamefile name to output TAP results to
Since:
0.9.12
CK_DLL_EXP void CK_EXPORT srunner_set_xml ( SRunner sr,
const char *  fname 
)

Set the suite runner to output the result in XML format to the given file.

Note: XML file setting is an initialize only operation -- it should be done immediately after SRunner creation, and the XML file can't be changed after being set.

This setting does not conflict with the other log output types; all logging types can occur concurrently if configured.

Parameters:
srsuite runner to log results of in XML format
fnamefile name to output XML results to
Since:
0.9.1
CK_DLL_EXP const char* CK_EXPORT srunner_tap_fname ( SRunner sr)

Retrieves the name of the currently assigned file for TAP output, if any exists.

Returns:
the name of the TAP file, or NULL if none is configured
Since:
0.9.12
CK_DLL_EXP const char* CK_EXPORT srunner_xml_fname ( SRunner sr)

Retrieves the name of the currently assigned file for XML output, if any exists.

Returns:
the name of the XML file, or NULL if none is configured
Since:
0.9.1
CK_DLL_EXP void CK_EXPORT suite_add_tcase ( Suite s,
TCase tc 
)

Add a test case to a suite

Parameters:
ssuite to add test case to
tctest case to add to suite
Since:
0.6.0
CK_DLL_EXP Suite* CK_EXPORT suite_create ( const char *  name)

Creates a test suite with the given name.

Create a suite, which will contain test cases. Once created, use suite_add_tcase() to add test cases. When finished, create a suite runner from the suite using srunner_create()

Parameters:
namename of the suite
Returns:
suite
Since:
0.6.0
CK_DLL_EXP int CK_EXPORT suite_tcase ( Suite s,
const char *  tcname 
)

Determines whether a given test suite contains a case named after a given string.

Parameters:
ssuite to check
tcnametest case to look for
Returns:
1 iff the given test case is within the given suite; 0 otherwise
Since:
0.9.9
CK_DLL_EXP void CK_EXPORT tcase_add_checked_fixture ( TCase tc,
SFun  setup,
SFun  teardown 
)

Add fixture setup/teardown functions to a test case

Checked fixture functions are run before and after unit tests. Unlike unchecked fixture functions, checked fixture functions are run in the same separate address space as the test program, and thus the test function will survive signals or unexpected exits in the fixture function. Also, IF the setup function is idempotent, unit test behavior will be the same in CK_FORK and CK_NOFORK modes.

However, since fixture functions are run before and after each unit test, they should not be expensive code.

Parameters:
tctest case to add checked fixture setup/teardown to
setupfunction to add to be executed before each unit test in the test case; if NULL no setup function is added
teardownfunction to add to be executed after each unit test in the test case; if NULL no teardown function is added
Since:
0.8.0
CK_DLL_EXP void CK_EXPORT tcase_add_unchecked_fixture ( TCase tc,
SFun  setup,
SFun  teardown 
)

Add unchecked fixture setup/teardown functions to a test case

If unchecked fixture functions are run at the start and end of the test case, and not before and after unit tests. Note that unchecked setup/teardown functions are not run in a separate address space, like test functions, and so must not exit or signal (e.g., segfault)

Also, when run in CK_NOFORK mode, unchecked fixture functions may lead to different unit test behavior IF unit tests change data setup by the fixture functions.

Parameters:
tctest case to add unchecked fixture setup/teardown to
setupfunction to add to be executed before the test case; if NULL no setup function is added
teardownfunction to add to be executed after the test case; if NULL no teardown function is added
Since:
0.8.0
CK_DLL_EXP TCase* CK_EXPORT tcase_create ( const char *  name)

Create a test case.

Once created, tests can be added with the tcase_add_test() function, and the test case assigned to a suite with the suite_add_tcase() function.

Parameters:
namename of the test case
Returns:
test case containing no tests
Since:
0.6.0
CK_DLL_EXP void CK_EXPORT tcase_fn_start ( const char *  fname,
const char *  file,
int  line 
)
CK_DLL_EXP void CK_EXPORT tcase_set_timeout ( TCase tc,
double  timeout 
)

Set the timeout for all tests in a test case.

A test that lasts longer than the timeout (in seconds) will be killed and thus fail with an error.

If not set, the default timeout is one assigned at compile time. If the environment variable CK_DEFAULT_TIMEOUT is defined and no timeout is set, the value in the environment variable is used.

Parameters:
tctest case to assign timeout to
timeoutto use, in seconds. If the value contains a decimal portion, but no high resolution timer is available, the value is rounded up to the nearest second.
Since:
0.9.2
CK_DLL_EXP enum ck_result_ctx CK_EXPORT tr_ctx ( TestResult tr)

Retrieve context in which the result occurred for the given test result.

The types of contents include the test setup, teardown, or the body of the test itself.

Parameters:
trtest result to retrieve context from
Returns:
context to which the given test result applies
Since:
0.8.0
CK_DLL_EXP const char* CK_EXPORT tr_lfile ( TestResult tr)

Retrieve file name at which a failure occurred, if applicable.

Returns:
If the test resulted in a failure, returns a string containing the name of the file where the failure occurred; otherwise returns NULL.
Since:
0.6.0
CK_DLL_EXP int CK_EXPORT tr_lno ( TestResult tr)

Retrieve line number at which a failure occurred, if applicable.

Returns:
If the test resulted in a failure, returns the line number that the failure occurred on; otherwise returns -1.
Since:
0.6.0
CK_DLL_EXP const char* CK_EXPORT tr_msg ( TestResult tr)

Retrieve failure message from test result, if applicable.

Returns:
pointer to a message, if one exists. NULL otherwise.
Since:
0.6.0
CK_DLL_EXP int CK_EXPORT tr_rtype ( TestResult tr)

Retrieve type of result that the given test result represents.

This is a member of test_result, and can represent a pass, failure, or error.

Parameters:
trtest result to retrieve result from
Returns:
result of given test
Since:
0.6.0
CK_DLL_EXP const char* CK_EXPORT tr_tcname ( TestResult tr)

Retrieve test case name in which a failure occurred, if applicable.

Returns:
If the test resulted in a failure, returns a string containing the name of the test suite where the failure occurred; otherwise returns NULL.
Since:
0.6.0
 All Files Functions Typedefs Enumerations Enumerator Defines