diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-07 13:17:14 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-07 13:17:14 +0100 |
commit | 4875a3dd9b183dcd2256e2abfc4ccf7484c233b4 (patch) | |
tree | 0abbea881ded030851014ffdd60fbf71fead8f65 /src/tests/xb_test_filter.cpp | |
parent | daf17154bf13139d9375f48525d19d6aaba08155 (diff) |
New upstream version 4.0.2upstream/4.0.2
Diffstat (limited to 'src/tests/xb_test_filter.cpp')
-rwxr-xr-x | src/tests/xb_test_filter.cpp | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/src/tests/xb_test_filter.cpp b/src/tests/xb_test_filter.cpp new file mode 100755 index 0000000..2aeade3 --- /dev/null +++ b/src/tests/xb_test_filter.cpp @@ -0,0 +1,185 @@ +/* xb_test_filter.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2020,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 xbIxFilter + +// usage: xb_test_filter QUITE|NORMAL|VERBOSE + + +#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 MyV4Record[] = + { + { "CFLD", XB_CHAR_FLD, 6, 0 }, + { "NFLD", XB_NUMERIC_FLD, 6, 0 }, + { "ZFLD", XB_CHAR_FLD, 1, 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(); + + char c; + xbString s; + xbInt32 lRecCnt = 0; + iRc = 0; + + if( iPo > 0 ) + std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; + + xbDbf *V4Dbf = new xbDbf4( &x ); + + iRc2 = V4Dbf->CreateTable( "TestFilt.DBF", "TestFilter", MyV4Record, XB_OVERLAY, XB_MULTI_USER ); + iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + + + #ifdef XB_NDX_SUPPORT + xbIx *ixPtr; + void *ndx; + iRc2 = V4Dbf->CreateTag( "NDX", "TestFilt.NDX", "CFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + #endif // XB_NDX_SUPPORT + + + if( iRc2 ) + x.DisplayError( iRc2 ); + + for( xbUInt16 i = 0; i < 5 && iRc == XB_NO_ERROR; i++ ){ + // for( xbUInt16 j = 0; j < 26 && iRc == XB_NO_ERROR; j++ ){ + for( xbInt16 j = 25; j >= 0 && iRc == XB_NO_ERROR; j-- ){ + c = j + 65; + s = c; + s.PadRight( c, (xbUInt32) i + 1 ); + V4Dbf->BlankRecord(); + V4Dbf->PutField( "CFLD", s ); + V4Dbf->PutLongField( "NFLD", ++lRecCnt ); + iRc = V4Dbf->AppendRecord(); + } + } + + iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR ); + xbFilter f1( &x, V4Dbf ); + xbString sMyFilterExpression = "LEFT( CFLD, 2 ) = 'YY'"; + iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 28 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 54 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 ); + iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 106 ); + iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 ); + + sMyFilterExpression = "LEFT( CFLD, 2 ) = 'CC'"; + iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 50 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 ); + iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 128 ); + iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 ); + + + #ifdef XB_NDX_SUPPORT + f1.SetLimit( 0 ); + + // change things up a bit + iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 32 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 52 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 76 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 103 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Commit()", V4Dbf->Commit(), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "TestFilt" ), XB_NO_ERROR ); + sMyFilterExpression = "ZFLD = 'Z'"; + iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 52 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 103 ); + iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); + iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 32 ); + iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); + + #endif // XB_NDX_SUPPORT + + + iRc += TestMethod( iPo, "Close()", V4Dbf->Close(), XB_NO_ERROR ); + delete V4Dbf; + + 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; +} |