From 608776f8ed43e6bb1dac562f01b491b5be20e358 Mon Sep 17 00:00:00 2001 From: dsandersoremutah Date: Mon, 6 Feb 2006 21:31:40 +0000 Subject: [PATCH] Simplified unit test creation. Split basic unit tests into different functions. Added some new unit tests. git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@65 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- flaim/util/basic_test.cpp | 762 +++++++++++++++++++++++-------------- flaim/util/flmunittest.cpp | 211 +++------- flaim/util/flmunittest.h | 82 +--- 3 files changed, 549 insertions(+), 506 deletions(-) diff --git a/flaim/util/basic_test.cpp b/flaim/util/basic_test.cpp index 2a39ff4..a035aef 100644 --- a/flaim/util/basic_test.cpp +++ b/flaim/util/basic_test.cpp @@ -59,12 +59,44 @@ class IFlmTestImpl : public TestBase { public: + IFlmTestImpl() + { + m_hDb = HFDB_NULL; + } + + virtual ~IFlmTestImpl() + { + if (m_hDb != HFDB_NULL) + { + (void)FlmDbClose( &m_hDb); + } + } + inline const char * getName( void) { return( "Basic Test"); } + RCODE createDbTest( void); + + RCODE addRecordTest( + FLMUINT * puiDrn); + + RCODE modifyRecordTest( + FLMUINT uiDrn); + + RCODE deleteRecordTest( + FLMUINT uiDrn); + + RCODE queryRecordTest( void); + + RCODE removeDbTest( void); + RCODE execute( void); + +private: + + HFDB m_hDb; }; /**************************************************************************** @@ -86,20 +118,430 @@ Exit: return( rc); } +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::createDbTest( void) +{ + RCODE rc = FERR_OK; + FLMBOOL bPassed = FALSE; + + beginTest( "Create Database Test"); + + for (;;) + { + if( RC_BAD( rc = FlmDbCreate( DB_NAME_STR, NULL, + NULL, NULL, gv_pszSampleDictionary, NULL, &m_hDb))) + { + if( rc == FERR_FILE_EXISTS) + { + // Since the database already exists, we'll make a call + // to FlmDbOpen to get a handle to it. + + if( RC_BAD( rc = FlmDbRemove( DB_NAME_STR, + NULL, NULL, TRUE))) + { + MAKE_ERROR_STRING( "calling FlmDbRemove", rc, m_szFailInfo); + goto Exit; + } + } + else + { + MAKE_ERROR_STRING( "calling FlmDbCreate", rc, m_szFailInfo); + goto Exit; + } + } + else + { + break; + } + } + + bPassed = TRUE; + +Exit: + + endTest( bPassed); + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::addRecordTest( + FLMUINT * puiDrn + ) +{ + RCODE rc = FERR_OK; + FlmRecord * pRec = NULL; + void * pvField; + FLMBOOL bTransActive = FALSE; + FLMBOOL bPassed = FALSE; + + beginTest( "FlmRecordAdd Test"); + + // Create a record object + + if( (pRec = new FlmRecord) == NULL) + { + rc = RC_SET( FERR_MEM); + MAKE_ERROR_STRING( "allocating FlmRecord", rc, m_szFailInfo); + goto Exit; + } + + // Populate the record object with fields and values + // The first field of a record will be inserted at + // level zero (the first parameter of insertLast() + // specifies the level number). Subsequent fields + // will be inserted at a non-zero level. + + if( RC_BAD( rc = pRec->insertLast( 0, PERSON_TAG, + FLM_TEXT_TYPE, NULL))) + { + MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->insertLast( 1, FIRST_NAME_TAG, + FLM_TEXT_TYPE, &pvField))) + { + MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->setNative( pvField, "Foo"))) + { + MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->insertLast( 1, LAST_NAME_TAG, + FLM_TEXT_TYPE, &pvField))) + { + MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->setNative( pvField, "Bar"))) + { + MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->insertLast( 1, AGE_TAG, + FLM_NUMBER_TYPE, &pvField))) + { + MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = pRec->setUINT( pvField, 32))) + { + MAKE_ERROR_STRING( "calling setUINT", rc, m_szFailInfo); + goto Exit; + } + + // Start an update transaction + + if( RC_BAD( rc = FlmDbTransBegin( m_hDb, FLM_UPDATE_TRANS, 15))) + { + MAKE_ERROR_STRING( "calling FlmDbTransBegin", rc, m_szFailInfo); + goto Exit; + } + bTransActive = TRUE; + + // Add the record to the database. + + *puiDrn = 0; + if( RC_BAD( rc = FlmRecordAdd( m_hDb, FLM_DATA_CONTAINER, + puiDrn, pRec, 0))) + { + MAKE_ERROR_STRING( "calling FlmRecordAdd", rc, m_szFailInfo); + goto Exit; + } + + // Commit the transaction + // If FlmDbTransCommit returns without an error, the changes made + // above will be durable even if the system crashes. + + if( RC_BAD( rc = FlmDbTransCommit( m_hDb))) + { + MAKE_ERROR_STRING( "calling FlmDbTransCommit", rc, m_szFailInfo); + goto Exit; + } + bTransActive = FALSE; + + bPassed = TRUE; + +Exit: + + if( bTransActive) + { + (void)FlmDbTransAbort( m_hDb); + } + + if( pRec) + { + pRec->Release(); + } + + endTest( bPassed); + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::modifyRecordTest( + FLMUINT uiDrn + ) +{ + RCODE rc = FERR_OK; + FlmRecord * pRec = NULL; + FlmRecord * pModRec = NULL; + void * pvField; + FLMBOOL bTransActive = FALSE; + FLMBOOL bPassed = FALSE; + + // Retrieve the record from the database by ID + + beginTest( "FlmRecordRetrieve Test"); + if( RC_BAD( rc = FlmRecordRetrieve( m_hDb, FLM_DATA_CONTAINER, + uiDrn, FO_EXACT, &pRec, NULL))) + { + MAKE_ERROR_STRING( "calling FlmRecordRetrieve", rc, m_szFailInfo); + goto Exit; + } + endTest( TRUE); + + + beginTest( "FlmRecordModify Test"); + + // Copy the record so we can modify it + + if( (pModRec = pRec->copy()) == NULL) + { + rc = RC_SET( FERR_MEM); + MAKE_ERROR_STRING( "calling FlmRecord->copy()", rc, m_szFailInfo); + goto Exit; + } + + // Find the first name field and change it. + + pvField = pModRec->find( pModRec->root(), FIRST_NAME_TAG); + if( RC_BAD( rc = pModRec->setNative( pvField, "FooFoo"))) + { + MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo); + goto Exit; + } + + // Start an update transaction + + if( RC_BAD( rc = FlmDbTransBegin( m_hDb, FLM_UPDATE_TRANS, 15))) + { + MAKE_ERROR_STRING( "calling FlmDbTransBegin", rc, m_szFailInfo); + goto Exit; + } + bTransActive = TRUE; + + // Add the record to the database. + + if( RC_BAD( rc = FlmRecordModify( m_hDb, FLM_DATA_CONTAINER, + uiDrn, pModRec, 0))) + { + MAKE_ERROR_STRING( "calling FlmRecordAdd", rc, m_szFailInfo); + goto Exit; + } + + // Commit the transaction + // If FlmDbTransCommit returns without an error, the changes made + // above will be durable even if the system crashes. + + if( RC_BAD( rc = FlmDbTransCommit( m_hDb))) + { + MAKE_ERROR_STRING( "calling FlmDbTransCommit", rc, m_szFailInfo); + goto Exit; + } + bTransActive = FALSE; + + bPassed = TRUE; + +Exit: + + if( bTransActive) + { + (void)FlmDbTransAbort( m_hDb); + } + + if( pRec) + { + pRec->Release(); + } + + if( pModRec) + { + pModRec->Release(); + } + + endTest( bPassed); + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::deleteRecordTest( + FLMUINT uiDrn + ) +{ + RCODE rc = FERR_OK; + FLMBOOL bPassed = FALSE; + + // Delete a record from the database + + beginTest( "FlmRecordDelete Test"); + if( RC_BAD( rc = FlmRecordDelete( m_hDb, FLM_DATA_CONTAINER, + uiDrn, FLM_AUTO_TRANS | 15))) + { + MAKE_ERROR_STRING( "calling FlmRecordDelete", rc, m_szFailInfo); + goto Exit; + } + bPassed = TRUE; + +Exit: + + endTest( bPassed); + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::queryRecordTest( void) +{ + RCODE rc = FERR_OK; + FlmRecord * pRec = NULL; + HFCURSOR hCursor = HFCURSOR_NULL; + FLMBYTE ucTmpBuf[ 64]; + FLMBOOL bPassed = FALSE; + + // Now, build a query that retrieves the sample record. + // First we need to initialize a cursor handle. + + beginTest( "Retrieve Record by query Test"); + + if( RC_BAD( rc = FlmCursorInit( m_hDb, FLM_DATA_CONTAINER, &hCursor))) + { + MAKE_ERROR_STRING( "calling FlmCursorInit", rc, m_szFailInfo); + goto Exit; + } + + // We will search by first name and last name. This will use the + // LastFirst_IX defined in the sample dictionary for optimization. + + if( RC_BAD( rc = FlmCursorAddField( hCursor, LAST_NAME_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_EQ_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + f_sprintf( (char *)ucTmpBuf, "Bar"); + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_STRING_VAL, + ucTmpBuf, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_AND_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp failed", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddField( hCursor, FIRST_NAME_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_EQ_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + f_sprintf( (char *)ucTmpBuf, "FooFoo"); + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_STRING_VAL, + ucTmpBuf, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorFirst( hCursor, &pRec))) + { + MAKE_ERROR_STRING( "calling FlmCursorFirst", rc, m_szFailInfo); + goto Exit; + } + bPassed = TRUE; + +Exit: + + if (hCursor != HFCURSOR_NULL) + { + FlmCursorFree( &hCursor); + } + + if( pRec) + { + pRec->Release(); + } + + endTest( bPassed); + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::removeDbTest( void) +{ + RCODE rc = FERR_OK; + FLMBOOL bPassed = FALSE; + + // FlmDbRemove will delete the database and all of its files + + beginTest( "Remove Database Test"); + + if( RC_BAD( rc = FlmDbRemove( DB_NAME_STR, NULL, NULL, TRUE))) + { + MAKE_ERROR_STRING( "calling FlmDbRemove", rc, m_szFailInfo); + goto Exit; + } + bPassed = TRUE; + +Exit: + + endTest( bPassed); + return( rc); +} + /*************************************************************************** Desc: ****************************************************************************/ RCODE IFlmTestImpl::execute( void) { - RCODE rc = FERR_OK; - HFDB hDb = HFDB_NULL; - HFCURSOR hCursor = HFCURSOR_NULL; - FLMBOOL bTransActive = FALSE; - FLMUINT uiDrn; - FlmRecord * pDefRec = NULL; - FlmRecord * pRec = NULL; - void * pvField; - FLMBYTE ucTmpBuf[ 64]; + RCODE rc = FERR_OK; + FLMUINT uiDrn; // Initialize the FLAIM database engine. This call // must be made once by the application prior to making any @@ -110,296 +552,54 @@ RCODE IFlmTestImpl::execute( void) goto Exit; } - // Create or open a database. - - beginTest( - "Create Database Test", - "Create a new database", - "Self-explanatory", - ""); - -Retry_Create: - - if( RC_BAD( rc = FlmDbCreate( DB_NAME_STR, NULL, - NULL, NULL, gv_pszSampleDictionary, NULL, &hDb))) + // Create database test + + if (RC_BAD( rc = createDbTest())) { - if( rc == FERR_FILE_EXISTS) - { - // Since the database already exists, we'll make a call - // to FlmDbOpen to get a handle to it. - - if( RC_BAD( rc = FlmDbRemove( DB_NAME_STR, - NULL, NULL, TRUE))) - { - MAKE_ERROR_STRING( "FlmDbRemove failed", m_szDetails, rc); - goto Exit; - } - - goto Retry_Create; - } - else - { - MAKE_ERROR_STRING( "FlmDbCreate failed", m_szDetails, rc); - goto Exit; - } + goto Exit; } - - endTest( "PASS"); - - beginTest( - "Create/Populate Record Test", - "Create a new record and populate it with data", - "Self-explanatory", - ""); - - // Create a record object - - if( (pDefRec = new FlmRecord) == NULL) + + // FlmRecordAdd test + + if (RC_BAD( rc = addRecordTest( &uiDrn))) + { + goto Exit; + } + + // FlmRecordModify test + + if (RC_BAD( rc = modifyRecordTest( uiDrn))) + { + goto Exit; + } + + // Retrieve record and query tests + + if (RC_BAD( rc = queryRecordTest())) { - rc = RC_SET( FERR_MEM); - MAKE_ERROR_STRING( "Could not allocate FlmRecord", m_szDetails, rc); goto Exit; } - // Populate the record object with fields and values - // The first field of a record will be inserted at - // level zero (the first parameter of insertLast() - // specifies the level number). Subsequent fields - // will be inserted at a non-zero level. - - if( RC_BAD( rc = pDefRec->insertLast( 0, PERSON_TAG, - FLM_TEXT_TYPE, NULL))) + // FlmRecordDelete test + + if (RC_BAD( rc = deleteRecordTest( uiDrn))) { - MAKE_ERROR_STRING( "insertLast failed", m_szDetails, rc); goto Exit; } - - if( RC_BAD( rc = pDefRec->insertLast( 1, FIRST_NAME_TAG, - FLM_TEXT_TYPE, &pvField))) - { - MAKE_ERROR_STRING( "insertLast failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = pDefRec->setNative( pvField, "Foo"))) - { - MAKE_ERROR_STRING( "setNative failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = pDefRec->insertLast( 1, LAST_NAME_TAG, - FLM_TEXT_TYPE, &pvField))) - { - MAKE_ERROR_STRING( "insertLast failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = pDefRec->setNative( pvField, "Bar"))) - { - MAKE_ERROR_STRING( "setNative failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = pDefRec->insertLast( 1, AGE_TAG, - FLM_NUMBER_TYPE, &pvField))) - { - MAKE_ERROR_STRING( "insertLast failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = pDefRec->setUINT( pvField, 32))) - { - MAKE_ERROR_STRING( "setUINT failed", m_szDetails, rc); - goto Exit; - } - - // Start an update transaction - - if( RC_BAD( rc = FlmDbTransBegin( hDb, FLM_UPDATE_TRANS, 15))) - { - MAKE_ERROR_STRING( "FlmDbTransBegin failed", m_szDetails, rc); - goto Exit; - } - bTransActive = TRUE; - - // Add the record to the database. Initialize uiDrn to 0 so that FLAIM - // will automatically assign a unique ID to the new record. We could - // also have specified a specific 32-bit ID to use for the record by - // setting uiDrn to the desired ID value. - - uiDrn = 0; - if( RC_BAD( rc = FlmRecordAdd( hDb, FLM_DATA_CONTAINER, - &uiDrn, pDefRec, 0))) - { - MAKE_ERROR_STRING( "FlmRecordAdd failed", m_szDetails, rc); - goto Exit; - } - - // Commit the transaction - // If FlmDbTransCommit returns without an error, the changes made - // above will be durable even if the system crashes. - - if( RC_BAD( rc = FlmDbTransCommit( hDb))) - { - MAKE_ERROR_STRING( "FlmDbTransCommit failed", m_szDetails, rc); - goto Exit; - } - bTransActive = FALSE; - - endTest("PASS"); - - // Retrieve the record from the database by ID - - beginTest( - "Retrieve Record by ID Test", - "Retrieve the record we just created by its ID", - "Self-explanatory", - ""); - - if( RC_BAD( rc = FlmRecordRetrieve( hDb, FLM_DATA_CONTAINER, - uiDrn, FO_EXACT, &pRec, NULL))) - { - MAKE_ERROR_STRING( "FlmRecordRetrieve failed", m_szDetails, rc); - goto Exit; - } - - endTest("PASS"); - - // Now, build a query that retrieves the sample record. - // First we need to initialize a cursor handle. - - beginTest( - "Retrieve Record by query Test", - "Retrieve the record we just created using a query", - "Self-explanatory", - ""); - - if( RC_BAD( rc = FlmCursorInit( hDb, FLM_DATA_CONTAINER, &hCursor))) - { - MAKE_ERROR_STRING( "FlmCursorInit failed", m_szDetails, rc); - goto Exit; - } - - // We will search by first name and last name. This will use the - // LastFirst_IX defined in the sample dictionary for optimization. - - if( RC_BAD( rc = FlmCursorAddField( hCursor, LAST_NAME_TAG, 0))) - { - MAKE_ERROR_STRING( "FlmCursorAddField failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_EQ_OP))) - { - MAKE_ERROR_STRING( "FlmCursorAddOp failed", m_szDetails, rc); - goto Exit; - } - - f_sprintf( (char *)ucTmpBuf, "Bar"); - if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_STRING_VAL, - ucTmpBuf, 0))) - { - MAKE_ERROR_STRING( "FlmCursorAddValue failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_AND_OP))) - { - MAKE_ERROR_STRING( "FlmCursorAddOp failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = FlmCursorAddField( hCursor, FIRST_NAME_TAG, 0))) - { - MAKE_ERROR_STRING( "FlmCursorAddField failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_EQ_OP))) - { - MAKE_ERROR_STRING( "FlmCursorAddOp failed", m_szDetails, rc); - goto Exit; - } - - f_sprintf( (char *)ucTmpBuf, "Foo"); - if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_STRING_VAL, - ucTmpBuf, 0))) - { - MAKE_ERROR_STRING( "FlmCursorAddValue failed", m_szDetails, rc); - goto Exit; - } - - if( RC_BAD( rc = FlmCursorFirst( hCursor, &pRec))) - { - MAKE_ERROR_STRING( "FlmCursorFirst failed", m_szDetails, rc); - goto Exit; - } - - // Free the cursor handle - - FlmCursorFree( &hCursor); - endTest("PASS"); - + // Close the database - FlmDbClose( &hDb); - - // FlmDbRemove will delete the database and all of its files - - beginTest( - "Remove Database Test", - "Remove the database", - "Self-explanatory", - ""); - - if( RC_BAD( FlmDbRemove( DB_NAME_STR, NULL, NULL, TRUE))) + FlmDbClose( &m_hDb); + + if (RC_BAD( rc = removeDbTest())) { - MAKE_ERROR_STRING( "FlmDbRemove failed", m_szDetails, rc); goto Exit; } - endTest("PASS"); - Exit: - if( RC_BAD( rc)) - { - endTest("FAIL"); - } - - if( pDefRec) - { - pDefRec->Release(); - } - - if( pRec) - { - pRec->Release(); - } - - if( hCursor != HFCURSOR_NULL) - { - FlmCursorFree( &hCursor); - } - - if( bTransActive) - { - (void)FlmDbTransAbort( hDb); - } - - if( hDb != HFDB_NULL) - { - FlmDbClose( &hDb); - } - FlmShutdown(); - if( RC_BAD( rc)) - { - f_sprintf( (char *)ucTmpBuf, "Error %04X -- %s", (unsigned)rc, - (char *)FlmErrorString( rc)); - displayLine( (char *)ucTmpBuf); - } - return( rc); } + diff --git a/flaim/util/flmunittest.cpp b/flaim/util/flmunittest.cpp index 8fb48f1..36163a5 100644 --- a/flaim/util/flmunittest.cpp +++ b/flaim/util/flmunittest.cpp @@ -65,7 +65,6 @@ struct TEST_INFO bool bLog; char pszLogfile[ 256]; bool bDisplay; - bool bVerboseDisplay; char pszEnvironment[ 32]; char pszBuild[ 32]; char pszUser[ 32]; @@ -76,7 +75,6 @@ struct TEST_INFO { bLog = FALSE; bDisplay = FALSE; - bVerboseDisplay = FALSE; pNext = NULL; pszLogfile[ 0] = 0; pszConfig[ 0] = 0; @@ -122,14 +120,12 @@ ITestReporter::~ITestReporter() Desc: ****************************************************************************/ RCODE ITestReporter::recordUnitTestResults( - const char * testName, - const char * testDescr, - const char * steps, - const char * status, - const char * resultDetails) + const char * pszTestName, + FLMBOOL bPassed, + const char * pszFailInfo) { - return ::recordUnitTestResults( &(this->m_uTD), testName, testDescr, - steps, status, resultDetails); + return ::recordUnitTestResults( &(this->m_uTD), pszTestName, bPassed, + pszFailInfo); } /**************************************************************************** @@ -286,10 +282,6 @@ int main( { f_strcpy( testInfo.pszUser, &args[i][2]); } - else if( (args[i][1] == 'v') || (args[i][1] == 'V')) - { - testInfo.bVerboseDisplay = TRUE; - } else if( (args[i][1] == 'i') || (args[i][1] == 'I')) { bPauseBeforeExit = TRUE; @@ -319,7 +311,7 @@ int main( } if( pTest->init( testInfo.bLog, testInfo.pszLogfile, testInfo.bDisplay, - testInfo.bVerboseDisplay, testInfo.pszConfig, testInfo.pszEnvironment, + testInfo.pszConfig, testInfo.pszEnvironment, testInfo.pszBuild, testInfo.pszUser) != 0) { #ifndef FLM_NLM @@ -822,33 +814,27 @@ Exit: Desc: After each unit test call this to record the unit test status to a CSV file. uTD - contains the configuration information - testName - a Unique for this module unite test name. - testDescr - A description of the unit test. - steps - The steps the unit test performs. - status - Maybe be PASS or FAIL - resultDetails - details that explain the result status. + pszTestName - a unique name for this unit test. + bPassed - Did unit test pass? + pszFailInfo - If unit test failed, reason is here ****************************************************************************/ RCODE recordUnitTestResults( unitTestData * uTD, - const char * testName, - const char * testDescr, - const char * steps, - const char * status, - const char * resultDetails) + const char * pszTestName, + FLMBOOL bPassed, + const char * pszFailInfo) { RCODE rc = FERR_OK; char buffer[ MAX_BUFFER_SIZE]; - if( !testName || !testDescr || !steps || !status || !resultDetails || !uTD ) - { - flmAssert(0); - } + flmAssert( pszTestName && uTD); if( uTD->csvFilename[ 0]) { f_sprintf( buffer, "%s,%s,%s,%s,%s,%s,%s,%s,"/*%s,*/"%s,%s\n", - testName, uTD->userName, testDescr, steps, uTD->buildNumber, status, - uTD->environment, resultDetails, uTD->attrs, uTD->folder); + pszTestName, uTD->userName, pszTestName, pszTestName, uTD->buildNumber, + (const char *)(bPassed ? "PASS" : "FAIL"), + uTD->environment, pszFailInfo, uTD->attrs, uTD->folder); if( RC_BAD( rc = f_filecat( uTD->csvFilename, buffer))) { @@ -868,7 +854,6 @@ RCODE TestBase::init( FLMBOOL bLog, const char * pszLogfile, FLMBOOL bDisplay, - FLMBOOL bVerboseDisplay, const char * pszConfigFile, const char * pszEnvironment, const char * pszBuild, @@ -927,7 +912,6 @@ RCODE TestBase::init( { goto Exit; } - m_bDisplayVerbose = bVerboseDisplay; Exit: @@ -938,48 +922,11 @@ Exit: Desc: ****************************************************************************/ void TestBase::beginTest( - const char * pszTestName, - const char * pszTestDesc, - const char * pszTestSteps, - const char * pszDetails) + const char * pszTestName) { - char szTemp[ 256]; - m_pszTestName = pszTestName; - m_pszTestDesc = pszTestDesc; - m_pszSteps = pszTestSteps; - - if( m_bDisplayVerbose) - { - displayLine( - "========================================" - "======================================="); - - f_sprintf( szTemp, "Test Name: %s", m_pszTestName); - displayLine( szTemp); - - f_sprintf( szTemp, "Test Description: %s", m_pszTestDesc); - displayLine( szTemp); - - f_sprintf( szTemp, "Steps: %s", m_pszSteps); - displayLine( szTemp); - } - else - { - f_sprintf( szTemp, "Test Name: %s ... ", m_pszTestName); - display( szTemp); - } - - f_strcpy( m_szDetails, pszDetails); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void TestBase::endTest( - const char * pszTestResult) -{ - outputAll( pszTestResult); + display( m_pszTestName); + display( " ... "); } /**************************************************************************** @@ -1123,119 +1070,61 @@ Exit: /**************************************************************************** Desc: ****************************************************************************/ -RCODE TestBase::logTestResults( - const char * pszTestResult) +void TestBase::logTestResults( + FLMBOOL bPassed) { - RCODE rc = FERR_OK; - char * pszTemp = NULL; + char szMsg [300]; - if( RC_BAD( rc = f_alloc( DETAILS_BUF_SIZ + 64, &pszTemp))) + if (m_bLog) { - goto Exit; + log( "==============================================================================="); + + f_sprintf( szMsg, "Test Name: %s", m_pszTestName); + log( szMsg); + + f_sprintf( szMsg, "Test Result: %s", (char *)(bPassed ? "PASS" : "FAIL")); + log( szMsg); + + if (!bPassed) + { + log( m_szFailInfo); + } + + log( "==============================================================================="); } - - log( - "========================================" - "======================================="); - - f_sprintf( pszTemp, "Test Name: %s", m_pszTestName); - log( pszTemp); - - f_sprintf( pszTemp, "Test Description: %s", m_pszTestDesc); - log( pszTemp); - - f_sprintf( pszTemp, "Steps: %s", m_pszSteps); - log( pszTemp); - - f_sprintf( pszTemp, "Test Result: %s", pszTestResult); - log( pszTemp); - - f_sprintf( pszTemp, "Details: %s", m_szDetails); - log( pszTemp); - - log( - "========================================" - "======================================="); - -Exit: - - if( pszTemp) - { - f_free( &pszTemp); - } - - return( rc); } /**************************************************************************** Desc: ****************************************************************************/ -RCODE TestBase::displayTestResults( - const char * pszTestResult) +void TestBase::displayTestResults( + FLMBOOL bPassed) { - RCODE rc = FERR_OK; - char * pszTemp = NULL; - - if( RC_BAD( rc = f_alloc( DETAILS_BUF_SIZ + 64, &pszTemp))) + if (bPassed) { - goto Exit; - } - - if( m_bDisplayVerbose) - { - f_sprintf( pszTemp, "Test Result: %s", pszTestResult); - displayLine( pszTemp); - - f_sprintf( pszTemp, "Details: %s", m_szDetails); - displayLine( pszTemp); - - displayLine( - "========================================" - "======================================="); + displayLine( "PASS"); } else { - f_sprintf( pszTemp, "Result: %s", pszTestResult); - displayLine( pszTestResult); + displayLine( "FAIL"); + displayLine( m_szFailInfo); } - -Exit: - - if( pszTemp) - { - f_free( &pszTemp); - } - - return( rc); } /**************************************************************************** Desc: ****************************************************************************/ -RCODE TestBase::outputAll( - const char * pszTestResult) +void TestBase::endTest( + FLMBOOL bPassed) { - RCODE rc = FERR_OK; - - if( RC_BAD( rc = displayTestResults( pszTestResult))) + displayTestResults( bPassed); + if (m_bLog) { - goto Exit; + logTestResults( bPassed); } - if( RC_BAD( rc = logTestResults( pszTestResult))) - { - goto Exit; - } - - if( RC_BAD( rc = m_pReporter->recordUnitTestResults( - m_pszTestName, m_pszTestDesc, m_pszSteps, pszTestResult, m_szDetails))) - { - goto Exit; - } - -Exit: - - return( rc); + (void)m_pReporter->recordUnitTestResults( + m_pszTestName, bPassed, m_szFailInfo); } /**************************************************************************** diff --git a/flaim/util/flmunittest.h b/flaim/util/flmunittest.h index 48d2923..4064566 100644 --- a/flaim/util/flmunittest.h +++ b/flaim/util/flmunittest.h @@ -33,9 +33,6 @@ // Status codes passed to recordUnitTestResults -#define PASS "PASS" -#define FAIL "FAIL" - #define MAX_SMALL_BUFFER_SIZE 255 #define MAX_BUFFER_SIZE 2500 @@ -47,34 +44,9 @@ sizeof(a) / sizeof(a[0]) #endif -#define MAKE_ERR_STRING( str, buf) \ - f_sprintf( buf, str" file: %s. line: %u.", __FILE__, __LINE__); \ - flmAssert( 0) - -#define MAKE_ERROR_STRING( str, buf, rcode) \ - f_sprintf( buf, str" "#rcode" == %X. file: %s. line: %u.", \ - (unsigned)rcode, __FILE__, __LINE__); \ - flmAssert( 0) - -#define MAKE_FLM_ERROR_STRING( str, buf, rcode) \ - f_sprintf( buf, str" "#rcode" == %X : %s. file: %s. line: %u.", \ - (unsigned)rcode, FlmErrorString( rcode), __FILE__, __LINE__); \ - flmAssert( 0); - -#define MAKE_GENERIC_ERROR_STRING( str, buf, num) \ - f_sprintf( buf, str": %lX file: %s. line: %u.", \ - (unsigned long)num, __FILE__, __LINE__); \ - flmAssert( 0); - -#define MAKE_GENERIC_ERROR_STRING64( str, buf, num) \ - f_sprintf( buf, str": %llX file: %s. line: %u.", \ - (unsigned long long)num, __FILE__, __LINE__); \ - flmAssert( 0); - -#define MAKE_SMI_ERR_STRING( str, buf, err) \ - f_sprintf( buf, "%s. ERROR: %d (%x). File: %s, Line %u.", \ - str, err, err, __FILE__, __LINE__); \ - flmAssert( 0); +#define MAKE_ERROR_STRING( pszWhat, rc, pszFailInfo) \ + f_sprintf( pszFailInfo, "Error %s: %X, file: %s, line: %u.", \ + pszWhat, (unsigned)rc, __FILE__, (unsigned)__LINE__); // Error Codes @@ -121,11 +93,9 @@ RCODE createUnitTest( RCODE recordUnitTestResults( unitTestData * uTD, - const char * testName, - const char * testDescr, - const char * steps, - const char * status, - const char * resultDetails); + const char * pszTestName, + FLMBOOL bPassed, + const char * pszFailInfo); /**************************************************************************** Desc: @@ -138,7 +108,6 @@ public: FLMBOOL bLog, const char * pszLogfile, FLMBOOL bDisplay, - FLMBOOL bVerboseDisplay, const char * pszConfigFile, const char * pszEnvironment, const char * pszBuild, @@ -189,11 +158,9 @@ public: const char * userName); RCODE recordUnitTestResults( - const char * testName, - const char * testDescr, - const char * steps, - const char * status, - const char * resultDetails); + const char * pszTestName, + FLMBOOL bPassed, + const char * pszFailInfo); }; /**************************************************************************** @@ -390,14 +357,12 @@ public: { m_bLog = FALSE; m_bDisplay = FALSE; - m_bDisplayVerbose = FALSE; m_pLogger = NULL; m_pDisplayer = NULL; m_pReporter = NULL; m_hDb = HFDB_NULL; m_pszTestName = NULL; - m_pszTestDesc = NULL; - m_pszSteps = NULL; + m_szFailInfo [0] = 0; } virtual ~TestBase(); @@ -406,7 +371,6 @@ public: FLMBOOL bLog, const char * pszLogfile, FLMBOOL bDisplay, - FLMBOOL bVerboseDisplay, const char * pszConfigFile, const char * pszEnvironment, const char * pszBuild, @@ -416,25 +380,18 @@ protected: FLMBOOL m_bLog; FLMBOOL m_bDisplay; - FLMBOOL m_bDisplayVerbose; IFlmTestLogger * m_pLogger; IFlmTestDisplayer * m_pDisplayer; ITestReporter * m_pReporter; HFDB m_hDb; -#define DETAILS_BUF_SIZ 1024 - char m_szDetails[ DETAILS_BUF_SIZ]; + char m_szFailInfo [100]; const char * m_pszTestName; - const char * m_pszTestDesc; - const char * m_pszSteps; void beginTest( - const char * pszTestName, - const char * pszTestDesc, - const char * pszTestSteps, - const char * pszDetails); + const char * pszTestName); - void endTest( - const char * pszTestResult); + void endTest( + FLMBOOL bPassed); void log( const char * pszString); @@ -445,14 +402,11 @@ protected: void displayLine( const char * pszString); - RCODE logTestResults( - const char * pszTestResult); + void logTestResults( + FLMBOOL bPassed); - RCODE displayTestResults( - const char * pszTestResult); - - RCODE outputAll( - const char * pszTestResult); + void displayTestResults( + FLMBOOL bPassed); RCODE initCleanTestState( const char * pszDibName);