diff options
Diffstat (limited to 'src/tests/xb_test_ndx.cpp')
-rwxr-xr-x | src/tests/xb_test_ndx.cpp | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/src/tests/xb_test_ndx.cpp b/src/tests/xb_test_ndx.cpp new file mode 100755 index 0000000..31306c0 --- /dev/null +++ b/src/tests/xb_test_ndx.cpp @@ -0,0 +1,330 @@ +/* xb_test_ndx.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +// This program tests the class xbIxNdx + +// usage: xb_test_ndx QUITE|NORMAL|VERBOSE + + + +// fix me - this program needs to test GetUnique + +#include "xbase.h" + +using namespace xb; + +#include "tstfuncs.cpp" + + +int main( int argCnt, char **av ) +{ + int iRc = 0; + int iRc2 = 0; + int iPo = 1; /* print option */ + /* 0 - QUIET */ + /* 1 - NORMAL */ + /* 2 - VERBOSE */ + + if( argCnt > 1 ) { + if( av[1][0] == 'Q' ) + iPo = 0; + else if( av[1][0] == 'V' ) + iPo = 2; + } + + + xbSchema MyV3Record[] = + { + { "CFLD", XB_CHAR_FLD, 30, 0 }, + { "DFLD", XB_DATE_FLD, 8, 0 }, + { "NFLD", XB_NUMERIC_FLD, 12, 0 }, + { "",0,0,0 } + }; + + + xbXBase x; +#ifdef XB_LOGGING_SUPPORT + x.EnableMsgLogging(); + if( iPo ){ + std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; + } + xbString sMsg; + sMsg.Sprintf( "Program [%s] initializing...", av[0] ); + x.WriteLogMessage( sMsg ); + x.SetLogSize( 1000000 ); +#endif + + x.SetDataDirectory( PROJECT_DATA_DIR ); + x.EnableMsgLogging(); +// x.DisableDefaultAutoLock(); + InitTime(); + + char c; + xbString s; + xbInt32 lRecCnt = 0; + iRc = 0; + + + if( iPo > 0 ) + std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; + + xbDbf *V3Dbf = new xbDbf3( &x ); + + xbIx *ixPtr; + void *ndx; + + iRc2 = V3Dbf->CreateTable( "TestNdx.DBF", "TestNdx", MyV3Record, XB_OVERLAY, XB_MULTI_USER ); + iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + + if( iRc2 ) + x.DisplayError( iRc2 ); + + + iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxC.NDX", "CFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxC.NDX", 0 ); + iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + + iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxD.NDX", "DFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxD.NDX", 0 ); + iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + + iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxN.NDX", "NFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxN.NDX", 0 ); + iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + + + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxC", 8 ); + iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxN" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxN", 8 ); + xbDouble dbl = 100; + iRc += TestMethod( iPo, "Find( 100 )", V3Dbf->Find( dbl ), XB_NOT_FOUND ); + + iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxD" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxD", 8 ); + xbDate dt; + iRc += TestMethod( iPo, "Find( dt )", V3Dbf->Find( dt ), XB_NOT_FOUND ); + + iRc += TestMethod( iPo, "GetFirstKey()", ixPtr->GetFirstKey(), XB_EMPTY ); + iRc += TestMethod( iPo, "GetNextKey()", ixPtr->GetFirstKey(), XB_EMPTY ); + iRc += TestMethod( iPo, "GetLasttKey()", ixPtr->GetLastKey(), XB_EMPTY ); + iRc += TestMethod( iPo, "GetPrevKey()", ixPtr->GetPrevKey(), XB_EMPTY ); + iRc += TestMethod( iPo, "FindKey()", ixPtr->FindKey( NULL, "19611101", 8, 0 ), XB_NOT_FOUND ); + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "AAA" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); + + xbDate d( "19890209" ); + + //for( xbUInt16 i = 0; i < 35 && iRc == XB_NO_ERROR; i++ ){ + for( xbUInt16 i = 0; i < 2 && iRc == XB_NO_ERROR; i++ ){ + for( xbUInt16 j = 0; j < 35 && iRc == XB_NO_ERROR; j++ ){ + c = j + 65; + s = c; + s.PadRight( c, (xbUInt32) i + 1 ); + V3Dbf->BlankRecord(); + V3Dbf->PutField( "CFLD", s ); + V3Dbf->PutLongField( "NFLD", ++lRecCnt ); + V3Dbf->PutField( "DFLD", d.Str() ); + d++; + + iRc = V3Dbf->AppendRecord(); + } + } + + iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxN" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxN", 8 ); + + dbl = 55.0; + iRc += TestMethod( iPo, "Find( 55.0 )", V3Dbf->Find( dbl ), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxC" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxC", 8 ); + + s = "AAA"; + iRc += TestMethod( iPo, "Find( 'AAA' )", V3Dbf->Find( s ), XB_NO_ERROR ); + + s = "AzAA"; + iRc += TestMethod( iPo, "Find( 'AzAA' )", V3Dbf->Find( s ), XB_NOT_FOUND ); + + iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxD" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxD", 8 ); + + std::cout << d.Str() << "\n"; + iRc += TestMethod( iPo, "Find( '19890420' )", V3Dbf->Find( d ), XB_NOT_FOUND ); + + V3Dbf->GetRecord( 26 ); + V3Dbf->PutField( "CFLD", "AAA" ); + V3Dbf->PutRecord( 26 ); + + V3Dbf->GetRecord( 14 ); + V3Dbf->PutField( "CFLD", "AAAA" ); + V3Dbf->PutRecord( 14 ); + + V3Dbf->GetRecord( 11 ); + V3Dbf->PutField( "CFLD", "III" ); + V3Dbf->PutRecord( 11 ); + + V3Dbf->GetRecord( 25 ); + V3Dbf->PutField( "CFLD", "DDD" ); + V3Dbf->PutRecord( 25 ); + + V3Dbf->GetRecord( 12 ); + V3Dbf->PutField( "CFLD", "EEE" ); + V3Dbf->PutRecord( 12 ); + + V3Dbf->GetRecord( 26 ); + V3Dbf->PutField( "CFLD", "CCC" ); + V3Dbf->PutRecord( 26 ); + + V3Dbf->GetRecord( 13 ); + V3Dbf->PutField( "CFLD", "CCCC" ); + V3Dbf->PutRecord( 13 ); + + V3Dbf->GetRecord( 27 ); + V3Dbf->PutField( "CFLD", "AAA" ); + V3Dbf->PutRecord( 27 ); + + V3Dbf->GetRecord( 28 ); + V3Dbf->PutField( "CFLD", "CCC" ); + V3Dbf->PutRecord( 28 ); + + V3Dbf->GetRecord( 24 ); + V3Dbf->PutField( "CFLD", "FFF" ); + V3Dbf->PutRecord( 24 ); + + V3Dbf->GetRecord( 10 ); + V3Dbf->PutField( "CFLD", "HHH" ); + V3Dbf->PutRecord( 10 ); + + + for( xbUInt16 i = 0; i < 35 && iRc == XB_NO_ERROR; i++ ){ + for( xbUInt16 j = 0; j < 14 && iRc == XB_NO_ERROR; j++ ){ + c = j + 65; + s = c; + s.PadRight( c, (xbUInt32) i + 1 ); + V3Dbf->BlankRecord(); + V3Dbf->PutField( "CFLD", s ); + V3Dbf->PutLongField( "NFLD", ++lRecCnt ); + V3Dbf->PutField( "DFLD", d.Str() ); + d++; + iRc = V3Dbf->AppendRecord(); + } + } + + for( xbUInt16 i = 0; i < 2 && iRc == XB_NO_ERROR; i++ ){ + for( xbUInt16 j = 0; j < 14 && iRc == XB_NO_ERROR; j++ ){ + c = j + 65; + s = c; + s.PadRight( c, (xbUInt32) i + 1 ); + + V3Dbf->BlankRecord(); + V3Dbf->PutField( "CFLD", s ); + V3Dbf->PutLongField( "NFLD", ++lRecCnt ); + V3Dbf->PutField( "DFLD", d.Str() ); + d++; + + iRc = V3Dbf->AppendRecord(); + } + } + + V3Dbf->GetRecord( 26 ); + V3Dbf->PutField( "CFLD", "AAA" ); + V3Dbf->PutRecord( 26 ); + + V3Dbf->GetRecord( 14 ); + V3Dbf->PutField( "CFLD", "AAAA" ); + V3Dbf->PutRecord( 14 ); + + V3Dbf->GetRecord( 11 ); + V3Dbf->PutField( "CFLD", "III" ); + V3Dbf->PutRecord( 11 ); + + V3Dbf->GetRecord( 25 ); + V3Dbf->PutField( "CFLD", "DDD" ); + V3Dbf->PutRecord( 25 ); + + V3Dbf->GetRecord( 12 ); + V3Dbf->PutField( "CFLD", "EEE" ); + V3Dbf->PutRecord( 12 ); + + V3Dbf->GetRecord( 26 ); + V3Dbf->PutField( "CFLD", "CCC" ); + V3Dbf->PutRecord( 26 ); + + V3Dbf->GetRecord( 13 ); + V3Dbf->PutField( "CFLD", "CCCC" ); + V3Dbf->PutRecord( 13 ); + + V3Dbf->GetRecord( 27 ); + V3Dbf->PutField( "CFLD", "AAA" ); + V3Dbf->PutRecord( 27 ); + + V3Dbf->GetRecord( 28 ); + V3Dbf->PutField( "CFLD", "CCC" ); + V3Dbf->PutRecord( 28 ); + + V3Dbf->GetRecord( 24 ); + V3Dbf->PutField( "CFLD", "FFF" ); + V3Dbf->PutRecord( 24 ); + + V3Dbf->GetRecord( 10 ); + V3Dbf->PutField( "CFLD", "HHH" ); + V3Dbf->PutRecord( 10 ); + + // just in case there are any issues outstanding + V3Dbf->Abort(); + + xbIxList *ixl = V3Dbf->GetIxList(); + xbIxNdx *ix; + xbString sTagName; + while( ixl ){ + if( *ixl->sFmt == "NDX" ){ + ix = (xbIxNdx *) ixl->ix; + //ix->GetTagName( 0, sTagName ); + sMsg.Sprintf( "CheckTagIntegrity() - [%s]", ix->GetTagName(ix->GetCurTag()).Str()); + iRc += TestMethod( iPo, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 2 ), XB_NO_ERROR ); + ixl = ixl->next; + } + } + + iRc += TestMethod( iPo, "Close()", V3Dbf->Close(), XB_NO_ERROR ); + delete V3Dbf; + + if( iPo > 0 || iRc < 0 ) + fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); + +#ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 ); + x.WriteLogMessage( sMsg, 2 ); +#endif + + return iRc; +} |