CUnit Programmers Reference  3.0
Macros | Functions | Variables
Automated

Macros

#define automated_run_tests()   CU_automated_run_tests()
 Deprecated (version 1). More...
 
#define set_output_filename(x)   CU_set_output_filename((x))
 Deprecated (version 1). More...
 

Functions

CU_EXPORT void CU_automated_run_tests (void)
 Runs CUnit tests using the automated interface. More...
 
CU_EXPORT CU_ErrorCode CU_list_tests_to_file (void)
 Generates an xml file containing a list of all tests in all suites in the active registry. More...
 
CU_EXPORT void CU_set_output_filename (const char *szFilenameRoot)
 Sets the root file name for automated test output files. More...
 
void CU_automated_package_name_set (const char *pName)
 Set tests suites package name.
 
const char * CU_automated_package_name_get (void)
 Get tests suites package name.
 
CU_EXPORT void CCU_automated_add_handlers (void)
 Append the automated (xml) test event handlers.
 
static CU_ErrorCode automated_list_all_tests (CU_pTestRegistry pRegistry, const char *szFilename)
 Generates an xml listing of all tests in all suites for the specified test registry. More...
 
static CU_ErrorCode initialize_result_file (const char *szFilename)
 Initializes the test results file generated by the automated interface. More...
 
static CU_ErrorCode uninitialize_result_file (void)
 Finalizes and closes the results output file generated by the automated interface.
 
static void automated_run_all_tests (CU_pTestRegistry pRegistry)
 Runs the registered tests using the automated interface. More...
 
static void automated_test_start_message_handler (const CU_pTest pTest, const CU_pSuite pSuite)
 Handler function called at start of each test. More...
 
static void automated_test_complete_message_handler (const CU_pTest pTest, const CU_pSuite pSuite, const CU_pFailureRecord pFailure)
 Handler function called at completion of each test. More...
 
static void automated_test_skipped_message_handler (const CU_pTest pTest, const CU_pSuite pSuite)
 Handler function called when a test is being skipped. More...
 
static void automated_all_tests_complete_message_handler (const CU_pFailureRecord pFailure)
 Handler function called at completion of all tests in a suite. More...
 
static void automated_suite_init_failure_message_handler (const CU_pSuite pSuite)
 Handler function called when suite initialization fails. More...
 
static void automated_suite_cleanup_failure_message_handler (const CU_pSuite pSuite)
 Handler function called when suite cleanup fails. More...
 
void CU_automated_enable_junit_xml (CU_BOOL bFlag)
 Enable or Disable the XML output format to JUnit-like. More...
 

Variables

static CU_pSuite f_pRunningSuite = NULL
 The running test suite.
 
static char f_szDefaultFileRoot [] = "CUnitAutomated"
 Default filename root for automated output files.
 
static char f_szTestListFileName [MAX_FILENAME_LENGTH] = ""
 Current output file name for the test listing file.
 
static char f_szTestResultFileName [MAX_FILENAME_LENGTH] = ""
 Current output file name for the test results file.
 
static FILE * f_pTestResultFile = NULL
 FILE pointer the test results file.
 
static CU_BOOL f_bWriting_CUNIT_RUN_SUITE = CU_FALSE
 Flag for keeping track of when a closing xml tag is required.
 
static CU_BOOL bJUnitXmlOutput = CU_FALSE
 Flag for toggling the xml junit output or keeping the original. More...
 

Detailed Description

Macro Definition Documentation

◆ automated_run_tests

#define automated_run_tests ( )    CU_automated_run_tests()

Deprecated (version 1).

Deprecated:
Use CU_automated_run_tests().

◆ set_output_filename

#define set_output_filename (   x)    CU_set_output_filename((x))

Deprecated (version 1).

Deprecated:
Use CU_set_output_filename().

Function Documentation

◆ automated_all_tests_complete_message_handler()

static void automated_all_tests_complete_message_handler ( const CU_pFailureRecord  pFailure)
static

Handler function called at completion of all tests in a suite.

Parameters
pFailurePointer to the test failure record list.

References bJUnitXmlOutput, CU_get_registry(), and CU_get_run_summary().

Referenced by CCU_automated_add_handlers().

◆ automated_list_all_tests()

static CU_ErrorCode automated_list_all_tests ( CU_pTestRegistry  pRegistry,
const char *  szFilename 
)
static

Generates an xml listing of all tests in all suites for the specified test registry.

The output is directed to a file having the specified name.

Parameters
pRegistryTest registry for which to generate list (non-NULL).
szFilenameNon-NULL, non-empty string containing name for listing file.
Returns
A CU_ErrorCode indicating the error status.

References CU_set_error(), CUE_BAD_FILENAME, CUE_FOPEN_FAILED, CUE_NOREGISTRY, CUE_SUCCESS, and f_szTestListFileName.

Referenced by CU_list_tests_to_file().

◆ automated_run_all_tests()

static void automated_run_all_tests ( CU_pTestRegistry  pRegistry)
static

Runs the registered tests using the automated interface.

If non-NULL. the specified registry is set as the active registry for running the tests. If NULL, then the default CUnit test registry is used. The actual test running is performed by CU_run_all_tests().

Parameters
pRegistryThe test registry to run.

References bJUnitXmlOutput, CU_run_all_tests(), CU_set_registry(), f_pRunningSuite, and f_pTestResultFile.

◆ automated_suite_cleanup_failure_message_handler()

static void automated_suite_cleanup_failure_message_handler ( const CU_pSuite  pSuite)
static

Handler function called when suite cleanup fails.

Parameters
pSuiteThe suite for which cleanup failed.

References bJUnitXmlOutput, f_bWriting_CUNIT_RUN_SUITE, f_pTestResultFile, and CU_Suite::pName.

Referenced by CCU_automated_add_handlers().

◆ automated_suite_init_failure_message_handler()

static void automated_suite_init_failure_message_handler ( const CU_pSuite  pSuite)
static

Handler function called when suite initialization fails.

Parameters
pSuiteThe suite for which initialization failed.

References bJUnitXmlOutput, f_bWriting_CUNIT_RUN_SUITE, f_pTestResultFile, and CU_Suite::pName.

Referenced by CCU_automated_add_handlers().

◆ automated_test_complete_message_handler()

static void automated_test_complete_message_handler ( const CU_pTest  pTest,
const CU_pSuite  pSuite,
const CU_pFailureRecord  pFailure 
)
static

Handler function called at completion of each test.

Parameters
pTestThe test being run (non-NULL).
pSuiteThe suite containing the test (non-NULL).
pFailurePointer to the 1st failure record for this test.

References bJUnitXmlOutput, CU_FREE, CU_MALLOC, CU_translate_special_characters(), CU_translated_strlen(), f_pTestResultFile, CU_Test::pName, CU_Suite::pName, CU_FailureRecord::pNext, CU_FailureRecord::pSuite, CU_FailureRecord::pTest, CU_FailureRecord::strCondition, CU_FailureRecord::strFileName, CU_FailureRecord::strFunction, and CU_FailureRecord::uiLineNumber.

Referenced by CCU_automated_add_handlers().

◆ automated_test_skipped_message_handler()

static void automated_test_skipped_message_handler ( const CU_pTest  pTest,
const CU_pSuite  pSuite 
)
static

Handler function called when a test is being skipped.

Parameters
pTestThe test being skipped (non-NULL).
pSuiteThe suite containing the test (non-NULL).

References bJUnitXmlOutput, f_pTestResultFile, CU_Test::pName, and CU_Suite::pName.

Referenced by CCU_automated_add_handlers().

◆ automated_test_start_message_handler()

static void automated_test_start_message_handler ( const CU_pTest  pTest,
const CU_pSuite  pSuite 
)
static

Handler function called at start of each test.

The test result file must have been opened before this function is called (i.e. f_pTestResultFile non-NULL).

Parameters
pTestThe test being run (non-NULL).
pSuiteThe suite containing the test (non-NULL).

References bJUnitXmlOutput, CU_FREE, CU_MALLOC, CU_translate_special_characters(), CU_translated_strlen(), f_bWriting_CUNIT_RUN_SUITE, f_pRunningSuite, f_pTestResultFile, and CU_Suite::pName.

Referenced by CCU_automated_add_handlers().

◆ CU_automated_enable_junit_xml()

void CU_automated_enable_junit_xml ( CU_BOOL  bFlag)

Enable or Disable the XML output format to JUnit-like.

When enabled (CU_TRUE) then the Results xml that is produced can be read by cruisecontrol and displayed in the test results page.

References bJUnitXmlOutput.

◆ CU_automated_run_tests()

void CU_automated_run_tests ( void  )

Runs CUnit tests using the automated interface.

This function sets appropriate callback functions, initializes the test output files, and calls the appropriate functions to list the tests and run them. If an output file name root has not been specified using CU_set_output_filename(), a generic root will be applied. It is an error to call this function before the CUnit test registry has been initialized (check by assertion).

References CU_get_registry(), CU_set_output_filename(), CUE_SUCCESS, f_szDefaultFileRoot, f_szTestResultFileName, and initialize_result_file().

◆ CU_list_tests_to_file()

CU_ErrorCode CU_list_tests_to_file ( void  )

Generates an xml file containing a list of all tests in all suites in the active registry.

The output file will be named according to the most recent call to CU_set_output_filename(), or a default if not previously set.

Returns
An error code indicating the error status.

References automated_list_all_tests(), CU_get_registry(), CU_set_output_filename(), f_szDefaultFileRoot, and f_szTestListFileName.

◆ CU_set_output_filename()

void CU_set_output_filename ( const char *  szFilenameRoot)

Sets the root file name for automated test output files.

The strings "-Listing.xml" and "-Results.xml" are appended to the specified root to generate the filenames. If szFilenameRoot is empty, the default root ("CUnitAutomated") is used.

Parameters
szFilenameRootString containing root to use for file names.

References f_szTestListFileName.

Referenced by CU_automated_run_tests(), and CU_list_tests_to_file().

◆ initialize_result_file()

static CU_ErrorCode initialize_result_file ( const char *  szFilename)
static

Initializes the test results file generated by the automated interface.

A file stream is opened and header information is written.

References bJUnitXmlOutput, CU_get_error(), CU_set_error(), CUE_BAD_FILENAME, CUE_FCLOSE_FAILED, CUE_FOPEN_FAILED, CUE_SUCCESS, and f_pTestResultFile.

Referenced by CU_automated_run_tests().

Variable Documentation

◆ bJUnitXmlOutput

CU_BOOL bJUnitXmlOutput = CU_FALSE
static