unitc
A simple unit testing library for C.
Typedefs | Functions
unitc.h File Reference

Function prototypes, macros, and typedefs for unitc. More...

Go to the source code of this file.

Macros

Options
#define UC_OPT_NONE
 

Typedefs

typedef struct uc_suiteuc_suite
 

Functions

void uc_add_test (uc_suite suite, void(*test_func)(uc_suite suite), const char *name, const char *comment)
 
bool uc_all_tests_passed (uc_suite suite)
 
void uc_check (uc_suite suite, const bool cond, const char *comment)
 
void uc_free (uc_suite suite)
 
uc_suite uc_init (const uint_least8_t options, const char *name, const char *comment)
 
void uc_report_basic (uc_suite suite)
 
void uc_report_standard (uc_suite suite)
 
void uc_run_tests (uc_suite suite)
 

Detailed Description

Function prototypes, macros, and typedefs for unitc.

Macro Definition Documentation

#define UC_OPT_NONE

No options set.

Typedef Documentation

typedef struct uc_suite* uc_suite

A uc_suite carries specified options, tests, successes/failures, and comments of a test suite.

Function Documentation

void uc_add_test ( uc_suite  suite,
void(*)(uc_suite suite)  test_func,
const char *  name,
const char *  comment 
)

Add a test to suite to be executed when run_test is called on the same suite.

Parameters
suiteTest suite to add the test to.
test_funcTest to execute. A test is a collection of uc_checks. test takes in a uc_suite which is the instance used in calling uc_check within test. suite will be passed to it.
nameName of the test - to appear in reports. Defaults to "Test #" where # depends on it's position in the queue if NULL.
commentA description of the test - to appear in reports. Can be omitted by passing NULL.
bool uc_all_tests_passed ( uc_suite  suite)

Check if all tests run for suite have passed (i.e. all checks were successful).

Parameters
suiteTest suite to check.
Returns
true if all tests that have been run for suite have passed (this includes "dangling" checks), false otherwise. Returns true if no tests or checks have been run.
void uc_check ( uc_suite  suite,
const bool  cond,
const char *  comment 
)

Check whether an expression evaluates as expected. Does nothing if suite is NULL.

Parameters
suiteTest suite in which the check belongs to.
condThe condition to check - a check is deemed successful when cond evaluates to true.
commentInformation about what is being checked. No other information about a check is available in (applicable) reports. Can be omitted by passing NULL.
void uc_free ( uc_suite  suite)

Free a test suite. Using suite after this call results in undefined behaviour. Does nothing if suite is NULL.

Parameters
suiteTest suite to free.
uc_suite uc_init ( const uint_least8_t  options,
const char *  name,
const char *  comment 
)

Create a test suite with the specified options.

Parameters
optionsLogical OR of values prefixed with UC_OPT.
nameName of the suite - to appear as the title of reports. Defaults to 'Main' if NULL.
commentA description of the suite - to appear as a complement to name. Can be omitted by passing NULL.
Returns
A uc_suite with options specified by options or NULL on error.
void uc_report_basic ( uc_suite  suite)

Outputs a report showing suite's title, comment, and the number of successful checks vs. failed checks as a fraction. Outputs nothing if suite is NULL.

Example: Suite name Some information about the suite. Successful checks: 5/20.

Parameters
suiteTest suite to generate report from.
void uc_report_standard ( uc_suite  suite)

Outputs a report showing suite's title, comment, the number of successful checks vs. failed checks as a fraction, and all comments of failed checks. Outputs nothing if suite is NULL. Example (the 'Check #8.' is auto generated when no comment is provided): Suite name Some information about the suite. Successful checks: 17/20. Check failed: A comment Check failed: Another comment. Check failed: Check #8.

Parameters
suiteTest suite to generate report from.
void uc_run_tests ( uc_suite  suite)

Run all tests added by uc_add_test (in order they were added in).

Parameters
suiteTest suite to run tests for.