コード例 #1
0
// called by the framework to iterate and execute all unit tests in this library.
// logger - reference to a Logger object used to collect the test results and diagnostic information
// fileCatalogBase - reference to a user provided object (derived from UnitTestFileCatalogBase) that
//                   implements the file catalog for this library
void UnitTestsEngineBase::RunAll( Logger & logger, UnitTestFileCatalogBase & fileCatalogBase )
{
    // log the library name
    logger.NewLibrary( fileCatalogBase.GetLibraryname() );
    printf( "Library: %s\n", fileCatalogBase.GetLibraryname().c_str() );

    // get the list of files/catalog objects in this library
    UnitTestCatalogList& catalogList = fileCatalogBase.GetCatalogs();

    // iterate through all files/catalogs
    UnitTestCatalogList::iterator i;
    for( i = catalogList.begin(); i != catalogList.end(); i++ )
    {
        UnitTestCatalogBase * pUnitTestCatalog = *i;

        // log the catalog name
        logger.NewCatalog( pUnitTestCatalog->GetCatalogName() );
        printf( "\tCatalog: %s\n", pUnitTestCatalog->GetCatalogName().c_str() );

        // get the list of all unit test objects in the current catalog
        UnitTestList& testsList = pUnitTestCatalog->GetTests();

        // iterate through all unit test objects
        UnitTestList::iterator j;
        for( j = testsList.begin(); j != testsList.end(); j++ )
        {
            UnitTestBase* pUnitTest = *j;

            // log the current unit test object name
            logger.NewUnit( pUnitTest->GetUnitName() );
            printf( "\t\tFunction: %s\n", pUnitTest->GetUnitName().c_str() );

            // execute the unit tests in the current unit test object
            pUnitTest->RunAll( logger );
        }
    }

    // indicate the end of the unit tests in the current library
    logger.TestCompleted();
}