Commit 0d041aab authored by jds2's avatar jds2

- Changed test run behavior so suite is run even if it has no tests - user...

  - Changed test run behavior so suite is run even if it has no tests - user may expect init & cleanup functions to be run as long as suite is active.
  - Modified console:  suites/tests selected by number,  inactive tests/suites reported, added help function, added option menu.
  - Modified curses:  suites/tests selected by number, inactive tests/suites reported, added help function, added option menu.
  - Modified automated:  inactive suites/tests reported.


git-svn-id: http://svn.code.sf.net/p/cunit/code/trunk@99 f00e6729-6848-4c17-8bfb-678c97c00071
parent b7047f44
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -23,7 +23,7 @@
*
* Feb 2002 Initial implementation (AK)
*
* 13/Feb/2002 Single interface to automated_run_tests. (AK)
* 13-Feb-2002 Single interface to automated_run_tests. (AK)
*
* 20-Jul-2004 New interface, doxygen comments. (JDS)
*/
......@@ -45,9 +45,36 @@
extern "C" {
#endif
CU_EXPORT void CU_automated_run_tests(void);
CU_EXPORT 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).
*/
CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot);
/**<
* 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.
*
* @return An error code indicating the error status.
*/
CU_EXPORT 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.
*
* @param szFilenameRoot String containing root to use for file names.
*/
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_automated_run_tests(). */
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004,2005,2006 Jerry St.Clair
* Copyright (C) 2004-2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -47,12 +47,64 @@ typedef enum {
CU_BRM_VERBOSE /**< Verbose mode - maximum output of run details. */
} CU_BasicRunMode;
CU_EXPORT CU_ErrorCode CU_basic_run_tests(void);
CU_EXPORT CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite);
CU_EXPORT CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest);
CU_EXPORT void CU_basic_set_mode(CU_BasicRunMode mode);
CU_EXPORT CU_ErrorCode CU_basic_run_tests(void);
/**<
* Runs all registered CUnit tests using the basic interface.
* The default CU_BasicRunMode is used unless it has been
* previously changed using CU_basic_set_mode(). The CUnit test
* registry must have been initialized before calling this function.
*
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOREGISTRY - Registry has not been initialized.
*/
CU_EXPORT CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite);
/**<
* Runs all tests for a specific suite in the basic interface.
* If pSuite is NULL, the function returns without taking any
* action. The default CU_BasicRunMode is used unless it has
* been changed using CU_basic_set_mode().
*
* @param pSuite The CU_Suite to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
*/
CU_EXPORT CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest);
/**<
* Runs a single test in a specific suite in the basic interface.
* If pSuite or pTest is NULL, the function returns without
* taking any action. The default CU_BasicRunMode is used unless
* it has been changed using CU_basic_set_mode.
*
* @param pSuite The CU_Suite holding the CU_Test to run.
* @param pTest The CU_Test to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
* CUE_NOTEST - pTest was NULL.
*/
CU_EXPORT void CU_basic_set_mode(CU_BasicRunMode mode);
/**< Sets the run mode for the basic interface.
* @param mode The new CU_BasicRunMode for subsequent test
* runs using the basic interface.
*/
CU_EXPORT CU_BasicRunMode CU_basic_get_mode(void);
CU_EXPORT void CU_basic_show_failures(CU_pFailureRecord pFailure);
/**< Retrieves the current run mode for the basic interface.
* @return The current CU_BasicRunMode setting for test
* runs using the basic interface.
*/
CU_EXPORT void CU_basic_show_failures(CU_pFailureRecord pFailure);
/**<
* Prints a summary of run failures to stdout.
* This is provided for user convenience upon request, and does
* not take into account the current run mode. The failures are
* printed to stdout independent of the most recent run mode.
*
* @param pFailure List of CU_pFailureRecord's to output.
*/
#ifdef __cplusplus
}
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -48,6 +48,7 @@ extern "C" {
#endif
CU_EXPORT void CU_curses_run_tests(void);
/**< Run registered CUnit tests using the curses interface. */
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_curses_run_tests(). */
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -46,6 +46,7 @@ extern "C" {
#endif
CU_EXPORT void CU_console_run_tests(void);
/**< Run registered CUnit tests using the console interface. */
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_console_run_tests(). */
......
......@@ -856,6 +856,22 @@ CU_pSuite CU_get_suite_by_name(const char *szSuiteName, CU_pTestRegistry pRegist
* @see CU_get_suite()
*/
CU_EXPORT
CU_pSuite CU_get_suite_by_index(unsigned int index, CU_pTestRegistry pRegistry);
/**<
* Retrieves a pointer to the suite at the specified (1-based) index.
* Iterates pRegistry and returns a pointer to the suite located at the
* specified index. pRegistry may not be NULL (checked by assertion).
* Clients should normally use CU_get_suite_at_pos() instead, which
* automatically searches the active test registry.
*
* @param index The 1-based index of the suite to find.
* @param pRegistry The registry to scan (non-NULL).
* @return Pointer to the suite at the specified index, or
* NULL if index is invalid.
* @see CU_get_suite_at_pos()
*/
CU_EXPORT
CU_pTest CU_get_test_by_name(const char* szTestName, CU_pSuite pSuite);
/**<
......@@ -871,6 +887,22 @@ CU_pTest CU_get_test_by_name(const char* szTestName, CU_pSuite pSuite);
* @see CU_get_test()
*/
CU_EXPORT
CU_pTest CU_get_test_by_index(unsigned int index, CU_pSuite pSuite);
/**<
* Retrieves a pointer to the test at the specified (1-based) index.
* Iterates pSuite and returns a pointer to the test located at the
* specified index. pSuite may not be NULL (checked by assertion).
* Clients should normally use CU_get_test_at_pos() instead, which
* automatically searches the active test registry.
*
* @param index The 1-based index of the test to find.
* @param pRegistry The registry to scan (non-NULL).
* @return Pointer to the test at the specified index, or
* NULL if index is invalid.
* @see CU_get_test_at_pos()
*/
#ifdef CUNIT_BUILD_TESTS
void test_cunit_TestDB(void);
#endif
......
......@@ -35,7 +35,9 @@
*
* 05-Sep-2004 Added internal test interface. (JDS)
*
* 17-Apr-2006 Moved doxygen comments into header. (JDS)
* 23-Apr-2006 Moved doxygen comments into header.
* Added type marker to CU_FailureRecord.
* Added support for tracking inactive suites/tests. (JDS)
*/
/** @file
......@@ -67,15 +69,26 @@
extern "C" {
#endif
/** Types of failures occurring during test runs. */
typedef enum CU_FailureTypes
{
CUF_SuiteInactive = 1, /**< Inactive suite was run. */
CUF_SuiteInitFailed, /**< Suite initialization function failed. */
CUF_SuiteCleanupFailed, /**< Suite cleanup function failed. */
CUF_TestInactive, /**< Inactive test was run. */
CUF_AssertFailed /**< CUnit assertion failed during test run. */
} CU_FailureType; /**< Failure type. */
/* CU_FailureRecord type definition. */
/** Data type for holding assertion failure information (linked list). */
typedef struct CU_FailureRecord
{
unsigned int uiLineNumber; /**< Line number of failure. */
char* strFileName; /**< Name of file where failure occurred. */
char* strCondition; /**< Test condition which failed. */
CU_pTest pTest; /**< Test containing failure. */
CU_pSuite pSuite; /**< Suite containing test having failure. */
CU_FailureType type; /**< Failure type. */
unsigned int uiLineNumber; /**< Line number of failure. */
char* strFileName; /**< Name of file where failure occurred. */
char* strCondition; /**< Test condition which failed. */
CU_pTest pTest; /**< Test containing failure. */
CU_pSuite pSuite; /**< Suite containing test having failure. */
struct CU_FailureRecord* pNext; /**< Pointer to next record in linked list. */
struct CU_FailureRecord* pPrev; /**< Pointer to previous record in linked list. */
......@@ -89,8 +102,10 @@ typedef struct CU_RunSummary
{
unsigned int nSuitesRun; /**< Number of suites completed during run. */
unsigned int nSuitesFailed; /**< Number of suites for which initialization failed. */
unsigned int nSuitesInactive; /**< Number of suites which were inactive. */
unsigned int nTestsRun; /**< Number of tests completed during run. */
unsigned int nTestsFailed; /**< Number of tests containing failed assertions. */
unsigned int nTestsInactive; /**< Number of tests which were inactive (in active suites). */
unsigned int nAsserts; /**< Number of assertions tested during run. */
unsigned int nAssertsFailed; /**< Number of failed assertions. */
unsigned int nFailureRecords; /**< Number of failure records generated. */
......@@ -171,7 +186,9 @@ CU_EXPORT CU_ErrorCode CU_run_all_tests(void);
* is called. If an error condition (other than CUE_NOREGISTRY)
* occurs during the run, the action depends on the current error
* action (see CU_set_error_action()). An inactive suite is not
* considered an error for this function.
* considered an error for this function. Note that the run
* statistics (counts of tests, successes, failures) are cleared
* each time this function is run, even if it is unsuccessful.
*
* @return A CU_ErrorCode indicating the first error condition
* encountered while running the tests.
......@@ -190,9 +207,9 @@ CU_EXPORT CU_ErrorCode CU_run_suite(CU_pSuite pSuite);
* then the suite is run using run_single_suite(), and any suite
* cleanup function is called. Note that the run statistics
* (counts of tests, successes, failures) are initialized each
* time this function is called in most cases. If an error
* condition occurs during the run, the action depends on the
* current error action (see CU_set_error_action()).
* time this function is called even if it is unsuccessful. If
* an error condition occurs during the run, the action depends
* on the current error action (see CU_set_error_action()).
*
* @param pSuite The suite containing the test (non-NULL)
* @return A CU_ErrorCode indicating the first error condition
......@@ -214,9 +231,9 @@ CU_EXPORT CU_ErrorCode CU_run_test(CU_pSuite pSuite, CU_pTest pTest);
* called, then the test is run using run_single_test(), and
* any suite cleanup function is called. Note that the
* run statistics (counts of tests, successes, failures)
* may be initialized each time this function is called even
* will be initialized each time this function is called even
* if it is not successful. Both the suite and test specified
* must be active or an error condition occurs.
* must be active for the test to be run.
*
* @param pSuite The suite containing the test (non-NULL)
* @param pTest The test to run (non-NULL)
......@@ -232,6 +249,34 @@ CU_EXPORT CU_ErrorCode CU_run_test(CU_pSuite pSuite, CU_pTest pTest);
* @see CU_run_suite() to run all tests in a specific suite.
*/
/*--------------------------------------------------------------------
* Functions for setting runtime behavior.
*--------------------------------------------------------------------*/
CU_EXPORT void CU_set_fail_on_inactive(CU_BOOL new_inactive);
/**<
* Sets whether an inactive suite or test is treated as a failure.
* If CU_TRUE, then failure records will be generated for inactive
* suites or tests encountered during a test run. The default is
* CU_TRUE so that the client is reminded that the framewrork
* contains inactive suites/tests. Set to CU_FALSE to turn off
* this behavior.
*
* @param new_inactive New setting for whether to treat inactive
* suites and tests as failures during a test
* run (CU_TRUE) or not (CU_FALSE).
* @see CU_get_fail_on_failure()
*/
CU_EXPORT CU_BOOL CU_get_fail_on_inactive(void);
/**<
* Retrieves the current setting for whether inactive suites/tests
* are treated as failures. If CU_TRUE then failure records will
* be generated for inactive suites encountered during a test run.
*
* @return CU_TRUE if inactive suites/tests are failures, CU_FALSE if not.
* @see CU_set_fail_on_inactive()
*/
/*--------------------------------------------------------------------
* Functions for getting information about the previous test run.
*--------------------------------------------------------------------*/
......@@ -239,10 +284,14 @@ CU_EXPORT unsigned int CU_get_number_of_suites_run(void);
/**< Retrieves the number of suites completed during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_suites_failed(void);
/**< Retrieves the number of suites which failed to initialize during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_suites_inactive(void);
/**< Retrieves the number of inactive suites found during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_run(void);
/**< Retrieves the number of tests completed during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_failed(void);
/**< Retrieves the number of tests containing failed assertions during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_inactive(void);
/**< Retrieves the number of inactive tests found during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_asserts(void);
/**< Retrieves the number of assertions processed during the last run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_successes(void);
......@@ -255,14 +304,15 @@ CU_EXPORT unsigned int CU_get_number_of_failure_records(void);
* records may also be created for failed suite initialization and cleanup.
*/
CU_EXPORT CU_pFailureRecord CU_get_failure_list(void);
/**< Retrieves the list of failures which occurred during the last run (reset each run).
* Note that the pointer returned is invalidated when the client initiates a run using
* CU_run_all_tests(), CU_run_suite(), or CU_run_test().
/**< Retrieves the head of the linked list of failures which occurred during the
* last run (reset each run). Note that the pointer returned is invalidated
* when the client initiates a run using CU_run_all_tests(), CU_run_suite(),
* or CU_run_test().
*/
CU_EXPORT CU_pRunSummary CU_get_run_summary(void);
/**< Retrieves the entire run summary for the last test run (reset each run).
* Note that the pFailure pointer in the run summary is invalidated when the client
* initiates a run using CU_run_all_tests(), CU_run_suite(), or CU_run_test().
* Note that the pFailure pointer in the run summary is invalidated when the client
* initiates a run using CU_run_all_tests(), CU_run_suite(), or CU_run_test().
*/
/*--------------------------------------------------------------------
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -59,6 +59,9 @@
#include "TestRun.h"
#include "Automated.h"
/*=================================================================
* Global / Static data definitions
*=================================================================*/
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[FILENAME_MAX] = ""; /**< Current output file name for the test listing file. */
......@@ -67,6 +70,9 @@ static FILE* f_pTestResultFile = NULL; /**< FILE pointer th
static CU_BOOL f_bWriting_CUNIT_RUN_SUITE = CU_FALSE; /**< Flag for keeping track of when a closing xml tag is required. */
/*=================================================================
* Static function forward declarations
*=================================================================*/
static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const char* szFilename);
static CU_ErrorCode initialize_result_file(const char* szFilename);
......@@ -80,16 +86,9 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite);
static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSuite);
/*------------------------------------------------------------------------*/
/** Run 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).
*/
/*=================================================================
* Public Interface functions
*=================================================================*/
void CU_automated_run_tests(void)
{
assert(NULL != CU_get_registry());
......@@ -125,12 +124,6 @@ void CU_automated_run_tests(void)
}
/*------------------------------------------------------------------------*/
/** Set 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.
* @param szFilenameRoot String containing root to use for file names.
*/
void CU_set_output_filename(const char* szFilenameRoot)
{
const char* szListEnding = "-Listing.xml";
......@@ -160,13 +153,6 @@ void CU_set_output_filename(const char* szFilenameRoot)
}
/*------------------------------------------------------------------------*/
/** Generate 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.
* @return An error code indicating the error status.
*/
CU_ErrorCode CU_list_tests_to_file()
{
/* if a filename root hasn't been set, use the default one */
......@@ -177,8 +163,10 @@ CU_ErrorCode CU_list_tests_to_file()
return automated_list_all_tests(CU_get_registry(), f_szTestListFileName);
}
/*------------------------------------------------------------------------*/
/** Run the registered tests using the automated interface.
/*=================================================================
* Static function implementation
*=================================================================*/
/** 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
......@@ -204,7 +192,7 @@ static void automated_run_all_tests(CU_pTestRegistry pRegistry)
}
/*------------------------------------------------------------------------*/
/** Initialize the test results file generated by the automated interface.
/** Initializes the test results file generated by the automated interface.
* A file stream is opened and header information is written.
*/
static CU_ErrorCode initialize_result_file(const char* szFilename)
......@@ -380,10 +368,12 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
" <RUN> %u </RUN> \n"
" <SUCCEEDED> - NA - </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
pRegistry->uiNumberOfSuites,
pRunSummary->nSuitesRun,
pRunSummary->nSuitesFailed
pRunSummary->nSuitesFailed,
pRunSummary->nSuitesInactive
);
fprintf(f_pTestResultFile,
......@@ -393,11 +383,13 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
pRegistry->uiNumberOfTests,
pRunSummary->nTestsRun,
pRunSummary->nTestsRun - pRunSummary->nTestsFailed,
pRunSummary->nTestsFailed
pRunSummary->nTestsFailed,
pRunSummary->nTestsInactive
);
fprintf(f_pTestResultFile,
......@@ -407,6 +399,7 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> -NA- </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n"
" </CUNIT_RUN_SUMMARY> \n",
pRunSummary->nAsserts,
......@@ -471,7 +464,7 @@ static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSui
}
/*------------------------------------------------------------------------*/
/** Finalize and close the results output file generated
/** Finalizes and closes the results output file generated
* by the automated interface.
*/
static CU_ErrorCode uninitialize_result_file(void)
......@@ -498,7 +491,7 @@ static CU_ErrorCode uninitialize_result_file(void)
}
/*------------------------------------------------------------------------*/
/** Generate an xml listing of all tests in all suites for the
/** 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.
* @param pRegistry Test registry for which to generate list (non-NULL).
......@@ -563,20 +556,26 @@ static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const c
" <CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n"
" <INITIALIZE_VALUE> %s </INITIALIZE_VALUE> \n"
" <CLEANUP_VALUE> %s </CLEANUP_VALUE> \n"
" <CLEANUP_VALUE> %s </CLEANUP_VALUE> \n"
" <ACTIVE_VALUE> %s </ACTIVE_VALUE> \n"
" <TEST_COUNT_VALUE> %u </TEST_COUNT_VALUE> \n"
" </CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION> \n",
(NULL != pSuite->pName) ? pSuite->pName : "",
(NULL != pSuite->pInitializeFunc) ? "Yes" : "No",
(NULL != pSuite->pCleanupFunc) ? "Yes" : "No",
(CU_FALSE != pSuite->fActive) ? "Yes" : "No",
pSuite->uiNumberOfTests);
fprintf(pTestListFile,
" <CUNIT_ALL_TEST_LISTING_SUITE_TESTS> \n");
while (NULL != pTest) {
fprintf(pTestListFile,
" <TEST_CASE_NAME> %s </TEST_CASE_NAME> \n",
(NULL != pTest->pName) ? pTest->pName : "");
" <TEST_CASE_DEFINITION> \n"
" <TEST_CASE_NAME> %s </TEST_CASE_NAME> \n"
" <TEST_ACTIVE_VALUE> %s </TEST_ACTIVE_VALUE> \n"
" </TEST_CASE_DEFINITION> \n",
(NULL != pTest->pName) ? pTest->pName : "",
(CU_FALSE != pSuite->fActive) ? "Yes" : "No");
pTest = pTest->pNext;
}
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004, 2005 Anil Kumar, Jerry St.Clair
* Copyright (C) 2004-2006 Jerry St.Clair, Anil Kumar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -20,17 +20,11 @@
/*
* Implementation for basic test runner interface.
*
* Created By : Jerry St.Clair (11-Aug-2004)
* Comment : Initial implementation of basic test runner interface
* EMail : jds2@users.sourceforge.net
* 11-Aug-2004 Initial implementation of basic test runner interface. (JDS)
*
* Modified : 8-Jan-2005 (JDS)
* Comment : Fixed reporting bug (bug report cunit-Bugs-1093861).
* Email : jds2@users.sourceforge.net
* 8-Jan-2005 Fixed reporting bug (bug report cunit-Bugs-1093861). (JDS)
*
* Modified : 30-Apr-2005 (JDS)
* Comment : Added notification of suite cleanup failure.
* Email : jds2@users.sourceforge.net
* 30-Apr-2005 Added notification of suite cleanup failure. (JDS)
*/
/** @file
......@@ -52,12 +46,17 @@
#include "TestRun.h"
#include "Basic.h"
/*=================================================================
* Global/Static Definitions
*=================================================================*/
/** Pointer to the currently running suite. */
static CU_pSuite f_pRunningSuite = NULL;
/** Current run mode. */
static CU_BasicRunMode f_run_mode = CU_BRM_NORMAL;
/* Forward declaration of module functions */
/*=================================================================
* Forward declaration of module functions *
*=================================================================*/
static CU_ErrorCode basic_initialize(void);
static CU_ErrorCode basic_run_all_tests(CU_pTestRegistry pRegistry);
static CU_ErrorCode basic_run_suite(CU_pSuite pSuite);
......@@ -69,14 +68,9 @@ static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFa
static void basic_suite_init_failure_message_handler(const CU_pSuite pSuite);
static void basic_suite_cleanup_failure_message_handler(const CU_pSuite pSuite);
/*------------------------------------------------------------------------*/
/** Run all registered CUnit tests using the basic interface.
* The default CU_BasicRunMode is used unless it has been
* previously changed using CU_basic_set_mode(). The CUnit test
* registry must have been initialized before calling this function.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOREGISTRY - Registry has not been initialized.
*/
/*=================================================================
* Public Interface functions
*=================================================================*/
CU_ErrorCode CU_basic_run_tests(void)
{
CU_ErrorCode error;
......@@ -93,14 +87,6 @@ CU_ErrorCode CU_basic_run_tests(void)
}
/*------------------------------------------------------------------------*/
/** Run all tests for a specific suite in the basic interface.
* If pSuite is NULL, the function returns without taking any
* action. The default CU_BasicRunMode is used unless it has
* been changed using CU_basic_set_mode().
* @param pSuite The CU_Suite to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
*/
CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite)
{
CU_ErrorCode error;
......@@ -114,16 +100,6 @@ CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite)
}
/*------------------------------------------------------------------------*/
/** Run a single test in a specific suite in the basic interface.
* If pSuite or pTest is NULL, the function returns without
* taking any action. The default CU_BasicRunMode is used unless
* it has been changed using CU_basic_set_mode.
* @param pSuite The CU_Suite holding the CU_Test to run.
* @param pTest The CU_Test to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
* CUE_NOTEST - pTest was NULL.
*/
CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest)
{
CU_ErrorCode error;
......@@ -139,33 +115,18 @@ CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest)
}
/*------------------------------------------------------------------------*/
/** Set the run mode for the basic interface.
* @param mode The new CU_BasicRunMode for subsequent test
* runs using the basic interface.
*/
void CU_basic_set_mode(CU_BasicRunMode mode)
{
f_run_mode = mode;
}
/*------------------------------------------------------------------------*/
/** Retrieve the current run mode for the basic interface.
* @return The current CU_BasicRunMode setting for test
* runs using the basic interface.
*/
CU_BasicRunMode CU_basic_get_mode(void)
{
return f_run_mode;
}
/*------------------------------------------------------------------------*/
/** Print a summary of run failures to stdout.
* This is provided for user convenience upon request, and
* does not take into account the current run mode. The
* failures are printed to stdout independent of the most
* recent run mode.
* @param pFailure List of CU_pFailureRecord's to output.
*/
void CU_basic_show_failures(CU_pFailureRecord pFailure)
{
int i;
......@@ -178,8 +139,10 @@ void CU_basic_show_failures(CU_pFailureRecord pFailure)
}
}
/*------------------------------------------------------------------------*/
/** Perform inialization actions for the basic interface.
/*=================================================================
* Static module functions
*=================================================================*/
/** Performs inialization actions for the basic interface.
* This includes setting output to unbuffered, printing a
* welcome message, and setting the test run handlers.
* @return An error code indicating the framework error condition.
......@@ -206,11 +169,10 @@ static CU_ErrorCode basic_initialize(void)
}
/*------------------------------------------------------------------------*/
/** Run all tests within the basic interface.
* If non-NULL, the test registry is changed to the specified
* registry before running the tests, and reset to the original
* registry when done. If NULL, the default CUnit test registry
* will be used.
/** Runs all tests within the basic interface.
* If non-NULL, the test registry is changed to the specified registry
* before running the tests, and reset to the original registry when
* done. If NULL, the default CUnit test registry will be used.
* @param pRegistry The CU_pTestRegistry containing the tests
* to be run. If NULL, use the default registry.
* @return An error code indicating the error status
......@@ -232,7 +194,7 @@ static CU_ErrorCode basic_run_all_tests(CU_pTestRegistry pRegistry)
}
/*------------------------------------------------------------------------*/
/** Run a specified suite within the basic interface.
/** Runs a specified suite within the basic interface.
* @param pSuite The suite to be run (non-NULL).
* @return An error code indicating the error status
* during the test run.
......@@ -244,7 +206,7 @@ static CU_ErrorCode basic_run_suite(CU_pSuite pSuite)
}
/*------------------------------------------------------------------------*/
/** Run a single test for the specified suite within
/** Runs a single test for the specified suite within
* the console interface.
* @param pSuite The suite containing the test to be run (non-NULL).
* @param pTest The test to be run (non-NULL).
......@@ -339,17 +301,19 @@ static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFa
assert(NULL != pRegistry);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout,"\n\n--Run Summary: Type Total Ran Passed Failed"
"\n suites %8u%8u n/a%8u"
"\n tests %8u%8u%8u%8u"
"\n asserts%8u%8u%8u%8u\n",
fprintf(stdout,"\n\n--Run Summary: Type Total Ran Passed Failed Inactive"
"\n suites %8u%8u n/a%8u%8u"
"\n tests %8u%8u%8u%8u%8u"
"\n asserts%8u%8u%8u%8u n/a\n",
pRegistry->uiNumberOfSuites,
pRunSummary->nSuitesRun,
pRunSummary->nSuitesFailed,
pRunSummary->nSuitesInactive,
pRegistry->uiNumberOfTests,
pRunSummary->nTestsRun,
pRunSummary->nTestsRun - pRunSummary->nTestsFailed,
pRunSummary->nTestsFailed,
pRunSummary->nTestsInactive,
pRunSummary->nAsserts,
pRunSummary->nAsserts,
pRunSummary->nAsserts - pRunSummary->nAssertsFailed,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.