Added a few new unit tests.

git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@74 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
dsandersoremutah
2006-02-08 16:37:36 +00:00
parent 548fd93d55
commit d6a8656f0d

View File

@@ -41,10 +41,216 @@ FSTATIC const char * gv_pszSampleDictionary =
" 2 field 3\n"
" 3 required\n";
const char * gv_pszFamilyNames[] =
{
"Walton",
"Abernathy",
"Stillwell",
"Anderson",
"Armstrong",
"Adamson",
"Bagwell",
"Ballard",
"Bennett",
"Blackman",
"Bottoms",
"Bradley",
"Butterfield",
"Cavanagh",
"Chadwick",
"Clark",
"Crabtree",
"Cunningham",
"Darnell",
"McClintock",
"Davidson",
"Dingman",
"Doyle",
"Eastman",
"Ballantine",
"Edmunds",
"Neil",
"Erickson",
"Fetterman",
"Finn",
"Flanagan",
"Gerber",
"Thedford",
"Thorman",
"Gibson",
"Gruszczynski",
"Haaksman",
"Hathaway",
"Pernell",
"Phillips",
"Highsmith",
"Hollingworth",
"Frankenberger",
"Hutchison",
"Irving",
"Weatherspoon",
"Itaya",
"Janiszewski",
"Jenkins",
"Jung",
"Keller",
"Jackson",
"Kingsbury",
"Klostermann",
"Langley",
"Liddle",
"Lockhart",
"Ludwig",
"Kristjanson",
"MacCormack",
"Richards",
"Robbins",
"McAuliffe",
"Merryweather",
"Moynihan",
"Muller",
"Newland",
"OCarroll",
"Okuzawa",
"Ortiz",
"Pachulski",
"Parmaksezian",
"Peacocke",
"Poole",
"Prewitt",
"Quigley",
"Qureshi",
"Ratcliffe",
"Rundle",
"Ryder",
"Sampson",
"Satterfield",
"Sharkey",
"Silverman",
"Snedeker",
"Goodman",
"Spitzer",
"Szypulski",
"Talbott",
"Trisko",
"Turrubiarte",
"Upchurch",
"Valdez",
"Vandenheede",
"Volker",
"Wilke",
"Wojciechowski",
"Wyndham",
"Yamashita",
"York",
"Zahn",
"Zimmermann",
NULL
};
const char * gv_pszGivenNames[] =
{
"Robby",
"Agatha",
"Anatoli",
"Zsazsa",
"Arlen",
"Augusta",
"Bambi",
"Bee",
"Bennie",
"Bonni",
"Brennan",
"Bryon",
"Cal",
"Caroline",
"Charlotte",
"Cristine",
"Danny",
"Dean",
"Desdemona",
"Dixie",
"Doug",
"Ellie",
"Zelma",
"Elsie",
"Ursula",
"Ernest",
"Fanny",
"Francis",
"Gailya",
"Gertrude",
"Gloria",
"Greg",
"Harriot",
"Hennrietta",
"Howard",
"Ian",
"Sherwood",
"Xavier",
"Ira",
"Jacklyn",
"Jeff",
"Philippe",
"Vivianne",
"Jeremy",
"Wendie",
"Abbie",
"Johnny",
"Kerrie",
"Lacey",
"Lilly",
"Lucas",
"Magdalena",
"Maryanne",
"Matt",
"Dorelle",
"Myron",
"Netty",
"Nicolette",
"Octavio",
"Oliver",
"Paige",
"Parker",
"Patti",
"Merv",
"Preston",
"Quinn",
"Randall",
"Jean",
"Rebekah",
"Ricardo",
"Rose",
"Russell",
"Scarlet",
"Shannon",
"Larry",
"Sophie",
"Stephen",
"Susette",
"Christina",
"Ted",
"Enrico",
"Theresa",
"Timothy",
"Tony",
"Vanna",
"Kalli",
"Vern",
"Alicia",
"Wallace",
"Yogi",
"Aaron",
"Yuji",
"Zack",
NULL
};
#define PERSON_TAG 1
#define LAST_NAME_TAG 2
#define FIRST_NAME_TAG 3
#define AGE_TAG 4
#define LAST_NAME_FIRST_NAME_IX 5
#ifdef FLM_NLM
#define DB_NAME_STR "SYS:\\SAMPLE.DB"
@@ -90,6 +296,13 @@ public:
RCODE queryRecordTest( void);
RCODE keyRetrieveTest(
FLMUINT uiIndex,
FLMBOOL bLastNameFirstNameIx);
RCODE addIndexTest(
FLMUINT * puiIndex);
RCODE removeDbTest( void);
RCODE execute( void);
@@ -175,9 +388,13 @@ RCODE IFlmTestImpl::addRecordTest(
{
RCODE rc = FERR_OK;
FlmRecord * pRec = NULL;
FlmRecord * pCopyRec = NULL;
void * pvField;
FLMBOOL bTransActive = FALSE;
FLMBOOL bPassed = FALSE;
FLMUINT uiLoop;
FLMUINT uiLoop2;
FLMUINT uiDrn2;
beginTest( "FlmRecordAdd Test");
@@ -260,6 +477,50 @@ RCODE IFlmTestImpl::addRecordTest(
MAKE_ERROR_STRING( "calling FlmRecordAdd", rc, m_szFailInfo);
goto Exit;
}
for (uiLoop = 0; gv_pszFamilyNames [uiLoop]; uiLoop++)
{
for (uiLoop2 = 0; gv_pszGivenNames [uiLoop2]; uiLoop2++)
{
if ((pCopyRec = pRec->copy()) == NULL)
{
rc = RC_SET( FERR_MEM);
MAKE_ERROR_STRING( "calling FlmRecord->copy()", rc, m_szFailInfo);
goto Exit;
}
if ((pvField = pCopyRec->find( pCopyRec->root(), FIRST_NAME_TAG)) == NULL)
{
rc = RC_SET( FERR_DATA_ERROR);
MAKE_ERROR_STRING( "corruption calling FlmRecord->copy()", rc, m_szFailInfo);
goto Exit;
}
if( RC_BAD( rc = pCopyRec->setNative( pvField, gv_pszGivenNames [uiLoop2])))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
if ((pvField = pCopyRec->find( pCopyRec->root(), LAST_NAME_TAG)) == NULL)
{
rc = RC_SET( FERR_DATA_ERROR);
MAKE_ERROR_STRING( "corruption calling FlmRecord->copy()", rc, m_szFailInfo);
goto Exit;
}
if( RC_BAD( rc = pCopyRec->setNative( pvField, gv_pszFamilyNames [uiLoop])))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
uiDrn2 = 0;
if( RC_BAD( rc = FlmRecordAdd( m_hDb, FLM_DATA_CONTAINER,
&uiDrn2, pCopyRec, 0)))
{
MAKE_ERROR_STRING( "calling FlmRecordAdd", rc, m_szFailInfo);
goto Exit;
}
pCopyRec->Release();
pCopyRec = NULL;
}
}
// Commit the transaction
// If FlmDbTransCommit returns without an error, the changes made
@@ -286,6 +547,11 @@ Exit:
pRec->Release();
}
if( pCopyRec)
{
pCopyRec->Release();
}
endTest( bPassed);
return( rc);
}
@@ -510,6 +776,317 @@ Exit:
return( rc);
}
/***************************************************************************
Desc:
****************************************************************************/
RCODE IFlmTestImpl::keyRetrieveTest(
FLMUINT uiIndex,
FLMBOOL bLastNameFirstNameIx)
{
RCODE rc = FERR_OK;
FLMBOOL bPassed = FALSE;
FLMUINT uiFlags = FO_FIRST;
FlmRecord * pSearchKey = NULL;
FLMUINT uiSearchDrn = 0;
FlmRecord * pFoundKey = NULL;
FLMUINT uiFoundDrn = 0;
char szLastFirstName [100];
char szLastLastName [100];
char szCurrFirstName [100];
char szCurrLastName [100];
void * pvField;
FLMUINT uiLen;
FLMINT iLastCmp;
FLMINT iFirstCmp;
if (bLastNameFirstNameIx)
{
beginTest( "FlmKeyRetrieve Test (Last+FirstIx)");
}
else
{
beginTest( "FlmKeyRetrieve Test (First+LastIx)");
}
szLastFirstName [0] = 0;
szLastLastName [0] = 0;
for (;;)
{
if (RC_BAD( rc = FlmKeyRetrieve( m_hDb, uiIndex,
0, pSearchKey, uiSearchDrn, uiFlags,
&pFoundKey, &uiFoundDrn)))
{
if (rc == FERR_EOF_HIT)
{
rc = FERR_OK;
break;
}
else
{
MAKE_ERROR_STRING( "calling FlmKeyRetrieve", rc, m_szFailInfo);
goto Exit;
}
}
// Make sure this key is greater than the last key.
if ((pvField = pFoundKey->find( pFoundKey->root(), LAST_NAME_TAG)) == NULL)
{
rc = RC_SET( FERR_DATA_ERROR);
MAKE_ERROR_STRING( "corruption calling FlmRecord->find()", rc, m_szFailInfo);
goto Exit;
}
uiLen = sizeof( szCurrLastName);
if (RC_BAD( rc = pFoundKey->getNative( pvField, szCurrLastName, &uiLen)))
{
MAKE_ERROR_STRING( "calling FlmRecord->getNative()", rc, m_szFailInfo);
goto Exit;
}
if ((pvField = pFoundKey->find( pFoundKey->root(), FIRST_NAME_TAG)) == NULL)
{
rc = RC_SET( FERR_DATA_ERROR);
MAKE_ERROR_STRING( "corruption calling FlmRecord->find()", rc, m_szFailInfo);
goto Exit;
}
uiLen = sizeof( szCurrFirstName);
if (RC_BAD( rc = pFoundKey->getNative( pvField, szCurrFirstName, &uiLen)))
{
MAKE_ERROR_STRING( "calling FlmRecord->getNative()", rc, m_szFailInfo);
goto Exit;
}
iLastCmp = f_strcmp( szCurrLastName, szLastLastName);
iFirstCmp = f_strcmp( szCurrFirstName, szLastFirstName);
if (bLastNameFirstNameIx)
{
if (iLastCmp < 0)
{
rc = RC_SET( FERR_DATA_ERROR);
f_sprintf( m_szFailInfo, "Invalid last name order in index: "
" %s before %s", szLastLastName, szCurrLastName);
goto Exit;
}
else if (iLastCmp == 0)
{
if (iFirstCmp < 0)
{
rc = RC_SET( FERR_DATA_ERROR);
f_sprintf( m_szFailInfo, "Invalid first name order in index: "
" %s before %s", szLastFirstName, szCurrFirstName);
goto Exit;
}
}
}
else
{
if (iFirstCmp < 0)
{
rc = RC_SET( FERR_DATA_ERROR);
f_sprintf( m_szFailInfo, "Invalid first name order in index: "
" %s before %s", szLastFirstName, szCurrFirstName);
goto Exit;
}
else if (iFirstCmp == 0)
{
if (iLastCmp < 0)
{
rc = RC_SET( FERR_DATA_ERROR);
f_sprintf( m_szFailInfo, "Invalid last name order in index: "
" %s before %s", szLastLastName, szCurrLastName);
goto Exit;
}
}
}
// Setup to get the next key.
uiFlags = FO_EXCL;
uiSearchDrn = uiFoundDrn;
if (pSearchKey)
{
pSearchKey->Release();
}
pSearchKey = pFoundKey;
pFoundKey = NULL;
uiFoundDrn = 0;
f_strcpy( szLastLastName, szCurrLastName);
f_strcpy( szLastFirstName, szCurrFirstName);
}
bPassed = TRUE;
Exit:
if (pSearchKey)
{
pSearchKey->Release();
}
if (pFoundKey)
{
pFoundKey->Release();
}
endTest( bPassed);
return( rc);
}
/***************************************************************************
Desc:
****************************************************************************/
RCODE IFlmTestImpl::addIndexTest(
FLMUINT * puiIndex
)
{
RCODE rc = FERR_OK;
FlmRecord * pRec = NULL;
void * pvField;
FLMBOOL bTransActive = FALSE;
FLMBOOL bPassed = FALSE;
char szFieldNum [20];
beginTest( "Add FirstName+LastName Index 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;
}
// 0 index FirstLast_IX
if( RC_BAD( rc = pRec->insertLast( 0, FLM_INDEX_TAG,
FLM_TEXT_TYPE, &pvField)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
if( RC_BAD( rc = pRec->setNative( pvField, "FirstLast_IX")))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
// 1 language US
if( RC_BAD( rc = pRec->insertLast( 1, FLM_LANGUAGE_TAG,
FLM_TEXT_TYPE, &pvField)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
if( RC_BAD( rc = pRec->setNative( pvField, "US")))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
// 1 key
if( RC_BAD( rc = pRec->insertLast( 1, FLM_KEY_TAG,
FLM_CONTEXT_TYPE, NULL)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
// 2 field <FIRST_NAME_TAG>
if( RC_BAD( rc = pRec->insertLast( 2, FLM_FIELD_TAG,
FLM_TEXT_TYPE, &pvField)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
f_sprintf( szFieldNum, "%u", FIRST_NAME_TAG);
if( RC_BAD( rc = pRec->setNative( pvField, szFieldNum)))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
// 3 required
if( RC_BAD( rc = pRec->insertLast( 3, FLM_REQUIRED_TAG,
FLM_TEXT_TYPE, NULL)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
// 2 field <LAST_NAME_TAG>
if( RC_BAD( rc = pRec->insertLast( 2, FLM_FIELD_TAG,
FLM_TEXT_TYPE, &pvField)))
{
MAKE_ERROR_STRING( "calling insertLast", rc, m_szFailInfo);
goto Exit;
}
f_sprintf( szFieldNum, "%u", LAST_NAME_TAG);
if( RC_BAD( rc = pRec->setNative( pvField, szFieldNum)))
{
MAKE_ERROR_STRING( "calling setNative", rc, m_szFailInfo);
goto Exit;
}
// 3 required
if( RC_BAD( rc = pRec->insertLast( 3, FLM_REQUIRED_TAG,
FLM_TEXT_TYPE, NULL)))
{
MAKE_ERROR_STRING( "calling insertLast", 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.
*puiIndex = 0;
if( RC_BAD( rc = FlmRecordAdd( m_hDb, FLM_DICT_CONTAINER,
puiIndex, 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:
****************************************************************************/
@@ -542,6 +1119,7 @@ RCODE IFlmTestImpl::execute( void)
{
RCODE rc = FERR_OK;
FLMUINT uiDrn;
FLMUINT uiIndex;
// Initialize the FLAIM database engine. This call
// must be made once by the application prior to making any
@@ -587,6 +1165,27 @@ RCODE IFlmTestImpl::execute( void)
goto Exit;
}
// FlmKeyRetrieve test
if (RC_BAD( rc = keyRetrieveTest( LAST_NAME_FIRST_NAME_IX, TRUE)))
{
goto Exit;
}
// Add index test
if (RC_BAD( rc = addIndexTest( &uiIndex)))
{
goto Exit;
}
// FlmKeyRetrieve test
if (RC_BAD( rc = keyRetrieveTest( uiIndex, FALSE)))
{
goto Exit;
}
// Close the database
FlmDbClose( &m_hDb);