diff options
Diffstat (limited to 'src/tests')
-rwxr-xr-x | src/tests/tstfuncs.cpp | 2 | ||||
-rwxr-xr-x | src/tests/xb_test_date.cpp | 34 | ||||
-rwxr-xr-x | src/tests/xb_test_dbf_v3_memos.cpp | 6 | ||||
-rwxr-xr-x | src/tests/xb_test_dbf_v4_nomemos.cpp | 14 | ||||
-rwxr-xr-x | src/tests/xb_test_expression.cpp | 62 | ||||
-rwxr-xr-x | src/tests/xb_test_file.cpp | 116 | ||||
-rwxr-xr-x | src/tests/xb_test_funcs.cpp | 3 | ||||
-rwxr-xr-x | src/tests/xb_test_lock.cpp | 318 | ||||
-rwxr-xr-x | src/tests/xb_test_lock2.cpp | 34 | ||||
-rwxr-xr-x | src/tests/xb_test_log.cpp | 52 | ||||
-rwxr-xr-x | src/tests/xb_test_mdx.cpp | 15 | ||||
-rwxr-xr-x | src/tests/xb_test_ndx.cpp | 55 | ||||
-rwxr-xr-x | src/tests/xb_test_sql.cpp | 119 | ||||
-rwxr-xr-x | src/tests/xb_test_string.cpp | 176 | ||||
-rwxr-xr-x | src/tests/xb_test_tblmgr.cpp | 33 | ||||
-rwxr-xr-x | src/tests/xb_test_tdx.cpp | 162 | ||||
-rwxr-xr-x | src/tests/xb_test_xbase.cpp | 113 |
17 files changed, 987 insertions, 327 deletions
diff --git a/src/tests/tstfuncs.cpp b/src/tests/tstfuncs.cpp index d9b108d..377b199 100755 --- a/src/tests/tstfuncs.cpp +++ b/src/tests/tstfuncs.cpp @@ -415,7 +415,7 @@ xbInt16 SetCmd( xbXBase &x, const xbString &sFileName, const xbString &sCmd, con #ifdef HAVE__FSOPEN_F // 0x40 is SH_DENYNO or _SH_DENYNO - if(( f = _fsopen( sFileName.Str(), "r", 0x40 )) == NULL){ + if(( f = _fsopen( sFileName.Str(), "w", 0x40 )) == NULL){ x.xbSleep( 250 ); iTryCnt++; } diff --git a/src/tests/xb_test_date.cpp b/src/tests/xb_test_date.cpp index 7aee584..0efe102 100755 --- a/src/tests/xb_test_date.cpp +++ b/src/tests/xb_test_date.cpp @@ -69,6 +69,8 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "FormatDate( '', sOutDate ) (sys default format)", d3.FormatDate( sFmt, sOutDate ), 0 ); iRc += TestMethod( po, "FormatDate( '', sOutDate ) (sys default format)", sOutDate, "07/09/12", 8 ); + + iRc += TestMethod( po, "CenturyOf()" , d3.CenturyOf(), 20 ); iRc += TestMethod( po, "YearOf()", d3.YearOf(), 2012 ); iRc += TestMethod( po, "MonthOf()", d3.MonthOf(), 7 ); @@ -84,12 +86,11 @@ int main( int argCnt, char **av ) d1.Set( "20010102" ); iRc += TestMethod( po, "d1.Set('20010102')", d1.Str(), "20010102", 8 ); - iRc += TestMethod( po, "d1.CalcRollingCenturyForYear(10)", d1.CalcRollingCenturyForYear( 10 ), 20 ); + iRc += TestMethod( po, "d1.CalcRollingCenturyForYear(10)", d1.CalcRollingCenturyForYear( 10 ), 20 ); iRc += TestMethod( po, "d1.JulianDays()", d1.JulianDays(), 2451912 ); - - iRc += TestMethod( po, "d1.Set( '20140709' )", d1.Set( "20140709" ) , 0 ); + d1.CharDayOf( s ); iRc += TestMethod( po, "d1.CharDayOf(s)", s, "Wednesday", 9 ); @@ -135,8 +136,8 @@ int main( int argCnt, char **av ) iRc+= TestMethod( po, "d1+2", d1+2, "20130407", 8 ); iRc+= TestMethod( po, "d1-5", d1-5, "20130402", 8 ); -// d1.Dump( "d1" ); -// d2.Dump( "d2" ); + //d1.Dump( "d1" ); + //d2.Dump( "d2" ); iRc+= TestMethod( po, "d1==d2", d1==d2, 0 ); d2 = d1; @@ -159,6 +160,29 @@ int main( int argCnt, char **av ) iRc+= TestMethod( po, "d1<=d2", d1<=d2, 0 ); iRc+= TestMethod( po, "d1-d2", d1-d2, 1 ); + + // null date testing follows + iRc+= TestMethod( po, "IsNull", d1.IsNull(), xbFalse ); + xbDate dN; + iRc+= TestMethod( po, "IsNull", dN.IsNull(), xbTrue ); + + xbDate dtNull1; + xbDate dtNull2; + + iRc+= TestMethod( po, "dtNull1==dtNull2", dtNull1 == dtNull2, 1 ); + iRc+= TestMethod( po, "dtNull1!=dtNull2", dtNull1 != dtNull2, 0 ); + + iRc+= TestMethod( po, "dtNull1 < d2", dtNull1 < d2, 1 ); + iRc+= TestMethod( po, "dtNull1 > d2", dtNull1 > d2, 0 ); + iRc+= TestMethod( po, "dtNull1 <= d2", dtNull1 <= d2, 1 ); + iRc+= TestMethod( po, "dtNull1 >= d2", dtNull1 >= d2, 0 ); + + iRc+= TestMethod( po, "d2 < dtNull1", d2 < dtNull1, 0 ); + iRc+= TestMethod( po, "d2 > dtNull1", d2 > dtNull1, 1 ); + iRc+= TestMethod( po, "d2 <= dtNull1", d2 <= dtNull1, 0 ); + iRc+= TestMethod( po, "d2 >= dtNull1", d2 >= dtNull1, 1 ); + + /* xbDate d4( "20171015" ); std::cout << "day of [" << d4.Str() << "][" << d4.DayOf( XB_FMT_WEEK ) << "]\n"; diff --git a/src/tests/xb_test_dbf_v3_memos.cpp b/src/tests/xb_test_dbf_v3_memos.cpp index e42edb1..7940c35 100755 --- a/src/tests/xb_test_dbf_v3_memos.cpp +++ b/src/tests/xb_test_dbf_v3_memos.cpp @@ -206,7 +206,6 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "UpdateMemoField()", V3Dbf.UpdateMemoField( fldMemo2, sData ), XB_NO_ERROR ); rc += TestMethod( po, "AppendRecord()", V3Dbf.AppendRecord(), XB_NO_ERROR ); - // Flag 1, 3, 5 and 7 for deletion rc += TestMethod( po, "GetRecord()", V3Dbf.GetRecord( 1 ), XB_NO_ERROR ); rc += TestMethod( po, "DeleteRecord()", V3Dbf.DeleteRecord(), XB_NO_ERROR ); @@ -219,6 +218,7 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "GetRecord()", V3Dbf.GetRecord( 7 ), XB_NO_ERROR ); rc += TestMethod( po, "DeleteRecord()", V3Dbf.DeleteRecord(), XB_NO_ERROR ); + rc += TestMethod( po, "Pack()", V3Dbf.Pack(), XB_NO_ERROR ); xbString sDir; @@ -228,8 +228,8 @@ int main( int argCnt, char **av ) sDbfName.Sprintf( "%snewV3nm.DBF", sDir.Str()); sDbtName.Sprintf( "%snewV3nm.DBT", sDir.Str()); - std::cout << "remove [" << sDbfName.Str() << "\n"; - std::cout << "remove [" << sDbtName.Str() << "\n"; + //std::cout << "remove [" << sDbfName.Str() << "]\n"; + //std::cout << "remove [" << sDbtName.Str() << "]\n"; V3Dbf.xbRemove( sDbfName ); V3Dbf.xbRemove( sDbtName ); diff --git a/src/tests/xb_test_dbf_v4_nomemos.cpp b/src/tests/xb_test_dbf_v4_nomemos.cpp index 984eb63..dd4976d 100755 --- a/src/tests/xb_test_dbf_v4_nomemos.cpp +++ b/src/tests/xb_test_dbf_v4_nomemos.cpp @@ -125,8 +125,22 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "GetFieldNo()", V4Dbf.GetFieldNo("LASTNAME"), 1 ); rc += TestMethod( po, "GetFieldNo()", V4Dbf.GetFieldNo("MIDDLEINIT"), 2 ); + xbBool bIsNull; + rc += TestMethod( po, "GetNullSts()", V4Dbf.GetNullSts( V4Dbf.GetFieldNo("LASTNAME"), bIsNull, 0 ), XB_NO_ERROR ); + rc += TestMethod( po, "GetNullSts()", bIsNull, xbTrue ); + + + xbInt16 fldLastName = V4Dbf.GetFieldNo( "LASTNAME" ); rc += TestMethod( po, "PutField()", V4Dbf.PutField( fldLastName, "NELSON" ), XB_NO_ERROR ); + + rc += TestMethod( po, "GetNullSts()", V4Dbf.GetNullSts( V4Dbf.GetFieldNo("LASTNAME"), bIsNull, 0 ), XB_NO_ERROR ); + rc += TestMethod( po, "GetNullSts()", bIsNull, xbFalse ); + + rc += TestMethod( po, "GetNullSts()", V4Dbf.GetNullSts( V4Dbf.GetFieldNo("FIRSTNAME"), bIsNull, 0 ), XB_NO_ERROR ); + rc += TestMethod( po, "GetNullSts()", bIsNull, xbTrue ); + + rc += TestMethod( po, "PutField()", V4Dbf.PutField( "FIRSTNAME", "WILLIE" ), XB_NO_ERROR ); rc += TestMethod( po, "PutField()", V4Dbf.PutField( "AMOUNT", "12.34" ), XB_NO_ERROR ); xbDate dt( "19500209" ); diff --git a/src/tests/xb_test_expression.cpp b/src/tests/xb_test_expression.cpp index ac1cde7..52c0b5c 100755 --- a/src/tests/xb_test_expression.cpp +++ b/src/tests/xb_test_expression.cpp @@ -384,6 +384,8 @@ int main( int argCnt, char **av ) { "CHAR2", XB_CHAR_FLD, 7, 0 }, { "DATE1", XB_DATE_FLD, 8, 0 }, { "DATE2", XB_DATE_FLD, 8, 0 }, + { "NULLDATE1", XB_DATE_FLD, 8, 0 }, + { "NULLDATE2", XB_DATE_FLD, 8, 0 }, { "NUM1", XB_NUMERIC_FLD, 9, 2 }, { "",0,0,0 } }; @@ -391,6 +393,10 @@ int main( int argCnt, char **av ) xbXBase x; xbDbf * MyFile; xbDate d; + xbDate dtTest1( "19890303" ); + xbDate dtTest2( "20120708" ); + + #ifdef XB_LOGGING_SUPPORT x.SetLogDirectory( PROJECT_LOG_DIR ); @@ -412,8 +418,6 @@ int main( int argCnt, char **av ) std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; } -// return 0; - #ifdef XB_DBF4_SUPPORT MyFile = new xbDbf4( &x ); /* version 4 dbf file */ #else @@ -421,13 +425,8 @@ int main( int argCnt, char **av ) #endif - -// return 0; - rc2 = MyFile->CreateTable( "ExpTest.DBF", "ExpTest", MyRecord, XB_OVERLAY, XB_MULTI_USER ); -// return 0; - iRc += TestMethod( po, "CreateTable()", rc2, XB_NO_ERROR ); iRc += TestMethod( po, "PutField()", MyFile->PutField( "CHAR1", "TEST" ), XB_NO_ERROR ); iRc += TestMethod( po, "PutField()", MyFile->PutField( "CHAR2", "TEST7B" ), XB_NO_ERROR ); @@ -437,8 +436,6 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "AppendRecord()", MyFile->AppendRecord(), XB_NO_ERROR ); -// return 0; - iRc += TestTokenMethod( &x, po, "EOX Test1", "", "", "", '?', XB_EXP_UNKNOWN, XB_NO_ERROR, XB_END_OF_EXPRESSION ); iRc += TestTokenMethod( &x, po, "EOX Test2 ", " ", "", "", '?', XB_EXP_UNKNOWN, XB_NO_ERROR, XB_END_OF_EXPRESSION ); @@ -634,49 +631,64 @@ int main( int argCnt, char **av ) iRc += TestMethod( &x, MyFile, po, "FuncTest41", "VAL( \"89\" )", (xbDouble) 89 ); iRc += TestMethod( &x, MyFile, po, "FuncTest42", "VAL( \"22.13 and some text\" )", (xbDouble) 22.13 ); iRc += TestMethod( &x, MyFile, po, "FuncTest43", "YEAR( STOD( \"20171017\" ))", (xbDouble) 2017 ); + iRc += TestMethod( &x, MyFile, po, "FuncTest44", "CTOD( \"07\\08\\12\" )", dtTest2 ); + xbDate dtToday; + dtToday.Sysdate(); + iRc += TestMethod( &x, MyFile, po, "FuncTest45", "DATE()", dtToday ); + dtTest2 = "28870625"; + iRc += TestMethod( &x, MyFile, po, "FuncTest46", "DESCEND( DATE2 )", dtTest2 ); + iRc += TestMethod( &x, MyFile, po, "FuncTest47", "STOD( \"19890303\" )", dtTest1 ); + // date logic tests - xbDate dtTest1( "19890303" ); - xbDate dtTest2( "20120708" ); + iRc += TestMethod( &x, MyFile, po, "DateTest1", "ExpTest->DATE1", dtTest1 ); iRc += TestMethod( &x, MyFile, po, "DateTest2", "DATE1", dtTest1 ); + dtTest2.Set( "20120708" ); iRc += TestMethod( &x, MyFile, po, "DateTest3", "ExpTest->DATE2", dtTest2 ); iRc += TestMethod( &x, MyFile, po, "DateTest4", "DATE2", dtTest2 ); iRc += TestMethod( &x, MyFile, po, "DateTest5", "DATE2 - DATE1", (xbDouble) 8528 ); + dtTest1.Set( "20120705" ); iRc += TestMethod( &x, MyFile, po, "DateTest6", "DATE2 - 3", dtTest1 ); - iRc += TestMethod( &x, MyFile, po, "DateTest7", "DATE2 -= 3", dtTest1 ); - dtTest1.Set( "20120718" ); iRc += TestMethod( &x, MyFile, po, "DateTest8", "DATE2 + 10", dtTest1 ); iRc += TestMethod( &x, MyFile, po, "DateTest9", "DATE2 += 10", dtTest1 ); - dtTest1.Set( "20120709" ); iRc += TestMethod( &x, MyFile, po, "DateTest10", "++DATE2", dtTest1 ); dtTest1.Set( "20120707" ); iRc += TestMethod( &x, MyFile, po, "DateTest11", "--DATE2", dtTest1 ); - dtTest1.Set( "20120708" ); iRc += TestMethod( &x, MyFile, po, "DateTest12", "DATE2++", dtTest1 ); iRc += TestMethod( &x, MyFile, po, "DateTest13", "DATE2--", dtTest1 ); - iRc += TestMethod( &x, MyFile, po, "DateTest14", "{07/08/12}", dtTest1 ); iRc += TestMethod( &x, MyFile, po, "DateTest15", "{07/08/2012}", dtTest1 ); - iRc += TestMethod( &x, MyFile, po, "DateTest16", "{07/11/12} -3", dtTest1 ); iRc += TestMethod( &x, MyFile, po, "DateTest17", "{07/06/2012} + 2", dtTest1 ); - iRc += TestMethod( &x, MyFile, po, "FuncTest44", "CTOD( \"07\\08\\12\" )", dtTest1 ); - - xbDate dtToday; - iRc += TestMethod( &x, MyFile, po, "FuncTest45", "DATE()", dtToday ); - - dtTest2 = "28870625"; - iRc += TestMethod( &x, MyFile, po, "FuncTest46", "DESCEND( DATE2 )", dtTest2 ); - iRc += TestMethod( &x, MyFile, po, "FuncTest47", "STOD( \"20120708\" )", dtTest1 ); + iRc += TestMethod( &x, MyFile, po, "DateTest18", "ExpTest->NULLDATE1 = {07/06/2012}", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest19", "ExpTest->NULLDATE1 != {07/06/2012}", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest20", "ExpTest->NULLDATE1 < {07/06/2012}", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest21", "ExpTest->NULLDATE1 <= {07/06/2012}", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest22", "ExpTest->NULLDATE1 > {07/06/2012}", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest23", "ExpTest->NULLDATE1 >= {07/06/2012}", (xbBool) xbFalse ); + + iRc += TestMethod( &x, MyFile, po, "DateTest24", "{07/06/2012} = ExpTest->NULLDATE1", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest25", "{07/06/2012} != ExpTest->NULLDATE1", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest26", "{07/06/2012} < ExpTest->NULLDATE1", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest27", "{07/06/2012} <= ExpTest->NULLDATE1", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest28", "{07/06/2012} > ExpTest->NULLDATE1", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest29", "{07/06/2012} >= ExpTest->NULLDATE1", (xbBool) xbTrue ); + + iRc += TestMethod( &x, MyFile, po, "DateTest18", "ExpTest->NULLDATE1 = ExpTest->NULLDATE2", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest19", "ExpTest->NULLDATE1 != ExpTest->NULLDATE2", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest20", "ExpTest->NULLDATE1 < ExpTest->NULLDATE2", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest21", "ExpTest->NULLDATE1 <= ExpTest->NULLDATE2", (xbBool) xbTrue ); + iRc += TestMethod( &x, MyFile, po, "DateTest22", "ExpTest->NULLDATE1 > ExpTest->NULLDATE2", (xbBool) xbFalse ); + iRc += TestMethod( &x, MyFile, po, "DateTest23", "ExpTest->NULLDATE1 >= ExpTest->NULLDATE2", (xbBool) xbTrue ); // boolean logic tests iRc += TestMethod( &x, MyFile, po, "LogicTest1", "3=5", (xbBool) xbFalse ); diff --git a/src/tests/xb_test_file.cpp b/src/tests/xb_test_file.cpp index cf835c2..0db6eca 100755 --- a/src/tests/xb_test_file.cpp +++ b/src/tests/xb_test_file.cpp @@ -27,24 +27,24 @@ using namespace xb; int main( int argCnt, char **av ) { - int rc = 0; - int po = 1; /* print option */ + int iRc = 0; + int iPo = 1; /* print option */ /* 0 - QUIET */ /* 1 - NORMAL */ /* 2 - VERBOSE */ if( argCnt > 1 ) { if( av[1][0] == 'Q' ) - po = 0; + iPo = 0; else if( av[1][0] == 'V' ) - po = 2; + iPo = 2; } xbXBase x; #ifdef XB_LOGGING_SUPPORT x.SetLogDirectory( PROJECT_LOG_DIR ); x.EnableMsgLogging(); - if( po ){ + if( iPo ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; } xbString sMsg; @@ -65,14 +65,14 @@ int main( int argCnt, char **av ) sWrkStr.SwapChars( '\\', '/' ); #endif - rc += TestMethod( po, "Set/GetDataDirectory()", f.GetDataDirectory(), sWrkStr, sWrkStr.Len()); + iRc += TestMethod( iPo, "Set/GetDataDirectory()", f.GetDataDirectory(), sWrkStr, sWrkStr.Len()); f.SetFileName( "TestFile.txt" ); sWrkStr = "TestFile.txt"; - rc += TestMethod( po, "Set/GetFileName()", f.GetFileName(), sWrkStr, sWrkStr.Len()); + iRc += TestMethod( iPo, "Set/GetFileName()", f.GetFileName(), sWrkStr, sWrkStr.Len()); f.GetFileType( sWrkStr ); - rc += TestMethod( po, "GetFileType()", sWrkStr, "TXT", 3 ); + iRc += TestMethod( iPo, "GetFileType()", sWrkStr, "TXT", 3 ); #ifdef WIN32 sWrkStr = "\\my\\directory\\"; @@ -81,10 +81,10 @@ int main( int argCnt, char **av ) #endif f.SetDirectory( sWrkStr ); - rc += TestMethod( po, "Set/GetDirectory()", f.GetDirectory(), sWrkStr, sWrkStr.Len()); + iRc += TestMethod( iPo, "Set/GetDirectory()", f.GetDirectory(), sWrkStr, sWrkStr.Len()); sWrkStr += "TestFile.txt"; - rc += TestMethod( po, "GetFqFileName()", f.GetFqFileName(), sWrkStr, 26 ); + iRc += TestMethod( iPo, "GetFqFileName()", f.GetFqFileName(), sWrkStr, 26 ); #ifdef WIN32 sWrkStr = "\\some\\directory\\myfile.dat"; @@ -95,115 +95,115 @@ int main( int argCnt, char **av ) #endif f.SetFqFileName( sWrkStr ); - rc += TestMethod( po, "GetDirectory()", f.GetDirectory(), sWrkStr2, 16 ); - rc += TestMethod( po, "GetFileName()", f.GetFileName(), "myfile.dat", 10 ); + iRc += TestMethod( iPo, "GetDirectory()", f.GetDirectory(), sWrkStr2, 16 ); + iRc += TestMethod( iPo, "GetFileName()", f.GetFileName(), "myfile.dat", 10 ); - rc += TestMethod( po, "NameSuffixMissing()", f.NameSuffixMissing( "myfile.dbf", 1 ), 0 ); - rc += TestMethod( po, "NameSuffixMissing()", f.NameSuffixMissing( "myfile", 1 ), 1 ); - rc += TestMethod( po, "NameSuffixMissing()", f.NameSuffixMissing( "MYFILE", 1 ), 2 ); + iRc += TestMethod( iPo, "NameSuffixMissing()", f.NameSuffixMissing( "myfile.dbf", 1 ), 0 ); + iRc += TestMethod( iPo, "NameSuffixMissing()", f.NameSuffixMissing( "myfile", 1 ), 1 ); + iRc += TestMethod( iPo, "NameSuffixMissing()", f.NameSuffixMissing( "MYFILE", 1 ), 2 ); f.SetDirectory( PROJECT_DATA_DIR ); f.SetFileName( "xbfile.txt" ); - rc += TestMethod( po, "xbFopen()", f.xbFopen( "w+b", XB_MULTI_USER ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFopen()", f.xbFopen( "w+b", XB_MULTI_USER ), XB_NO_ERROR ); xbString sTest; sTest = "Test Data"; - rc += TestMethod( po, "xbWrite()", f.xbFwrite( sTest.Str(), 9, 1 ), XB_NO_ERROR ); - rc += TestMethod( po, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbWrite()", f.xbFwrite( sTest.Str(), 9, 1 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); - rc += TestMethod( po, "xbFopen()", f.xbFopen( "r+b", XB_MULTI_USER ), XB_NO_ERROR ); - rc += TestMethod( po, "xbFseek()", f.xbFseek( 0, SEEK_SET ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFopen()", f.xbFopen( "r+b", XB_MULTI_USER ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFseek()", f.xbFseek( 0, SEEK_SET ), XB_NO_ERROR ); char buf[10]; for( int i = 0; i < 10; i++ ) buf[i] = 0x00; - rc += TestMethod( po, "xbFread()", f.xbFread( buf, 5, 1 ), XB_NO_ERROR ); - rc += TestMethod( po, "xbFread()", buf, "Test ", 5 ); + iRc += TestMethod( iPo, "xbFread()", f.xbFread( buf, 5, 1 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFread()", buf, "Test ", 5 ); - rc += TestMethod( po, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); - rc += TestMethod( po, "xbRemove()", f.xbRemove(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbRemove()", f.xbRemove(), XB_NO_ERROR ); xbInt16 iWork = 100; char cBuf[9]; char *p = cBuf; f.ePutInt16( cBuf, iWork ); - rc += TestMethod( po, "Put/GetShort()", f.eGetInt16( p ), 100 ); + iRc += TestMethod( iPo, "Put/GetShort()", f.eGetInt16( p ), 100 ); xbInt32 lWork = 10101; f.ePutInt32( p, lWork ); - rc += TestMethod( po, "Put/GetLong()", f.eGetInt32( p ), 10101 ); + iRc += TestMethod( iPo, "Put/GetLong()", f.eGetInt32( p ), 10101 ); lWork = 2147483647; f.ePutInt32( p, lWork ); - rc += TestMethod( po, "Put/GetLong()", f.eGetInt32( p ), 2147483647 ); - rc += TestMethod( po, "Put/GetLong()", (xbInt32) f.eGetUInt32( p ), 2147483647 ); + iRc += TestMethod( iPo, "Put/GetLong()", f.eGetInt32( p ), 2147483647 ); + iRc += TestMethod( iPo, "Put/GetLong()", (xbInt32) f.eGetUInt32( p ), 2147483647 ); xbDouble d = 123456.789; f.ePutDouble( p, d ); - rc += TestMethod( po, "Put/GetDouble()", f.eGetDouble( p ), 123456.789 ); + iRc += TestMethod( iPo, "Put/GetDouble()", f.eGetDouble( p ), 123456.789 ); xbString sFqnS; xbString sFqnT; xbFile f2( &x ); - rc += TestMethod( po, "CreateUniqueFileName()", f2.CreateUniqueFileName( PROJECT_DATA_DIR, "dbf", sFqnS ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "CreateUniqueFileName()", f2.CreateUniqueFileName( PROJECT_DATA_DIR, "dbf", sFqnS ), XB_NO_ERROR ); - rc += TestMethod( po, "FileExists()", f2.FileExists( sFqnS ), xbFalse ); - rc += TestMethod( po, "xbFopen()", f2.xbFopen( "w+b", sFqnS, XB_SINGLE_USER ), XB_NO_ERROR ); - rc += TestMethod( po, "xbFclose()", f2.xbFclose(), XB_NO_ERROR ); - rc += TestMethod( po, "FileExists()", f2.FileExists( sFqnS ), xbTrue ); + iRc += TestMethod( iPo, "FileExists()", f2.FileExists( sFqnS ), xbFalse ); + iRc += TestMethod( iPo, "xbFopen()", f2.xbFopen( "w+b", sFqnS, XB_SINGLE_USER ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFclose()", f2.xbFclose(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "FileExists()", f2.FileExists( sFqnS ), xbTrue ); - rc += TestMethod( po, "CreateUniqueFileName()", f2.CreateUniqueFileName( PROJECT_DATA_DIR, "dbf", sFqnT ), XB_NO_ERROR ); - rc += TestMethod( po, "xbRename()", f2.xbRename( sFqnS, sFqnT ), XB_NO_ERROR ); - rc += TestMethod( po, "xbRemove()", f.xbRemove( sFqnT ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "CreateUniqueFileName()", f2.CreateUniqueFileName( PROJECT_DATA_DIR, "dbf", sFqnT ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbRename()", f2.xbRename( sFqnS, sFqnT ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbRemove()", f.xbRemove( sFqnT ), XB_NO_ERROR ); xbString sFn; - rc += TestMethod( po, "GetFileNamePart()", f2.GetFileNamePart( sFqnS , sFn ), XB_NO_ERROR ); - rc += TestMethod( po, "GetFileExtPart()", f2.GetFileExtPart( sFqnS , sFn ), XB_NO_ERROR ); - rc += TestMethod( po, "GetFileExtPart()", f2.GetFileDirPart( sFqnS , sFn ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFileNamePart()", f2.GetFileNamePart( sFqnS , sFn ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFileExtPart()", f2.GetFileExtPart( sFqnS , sFn ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFileExtPart()", f2.GetFileDirPart( sFqnS , sFn ), XB_NO_ERROR ); - rc += TestMethod( po, "SetBlockSize()", f.SetBlockSize( 100 ), XB_INVALID_BLOCK_SIZE ); - rc += TestMethod( po, "SetBlockSize()", f.SetBlockSize( 512 ), XB_NO_ERROR ); - rc += TestMethod( po, "GetBlockSize()", (xbInt32) f.GetBlockSize(), 512 ); + iRc += TestMethod( iPo, "SetBlockSize()", f.SetBlockSize( 100 ), XB_INVALID_BLOCK_SIZE ); + iRc += TestMethod( iPo, "SetBlockSize()", f.SetBlockSize( 512 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetBlockSize()", (xbInt32) f.GetBlockSize(), 512 ); char BlockBuf[513]; memset( BlockBuf, 0x00, 513 ); - rc += TestMethod( po, "xbFopen()", f.xbFopen( "w+b", XB_SINGLE_USER ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbFopen()", f.xbFopen( "w+b", XB_SINGLE_USER ), XB_NO_ERROR ); for( int i = 0; i < 512; i++ ) BlockBuf[i] = 'A'; - rc += TestMethod( po, "WriteBlock()", f.WriteBlock( 0L, 512, BlockBuf ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "WriteBlock()", f.WriteBlock( 0L, 512, BlockBuf ), XB_NO_ERROR ); for( int i = 0; i < 512; i++ ) BlockBuf[i] = 'B'; - rc += TestMethod( po, "WriteBlock()", f.WriteBlock( 1L, 512, BlockBuf ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "WriteBlock()", f.WriteBlock( 1L, 512, BlockBuf ), XB_NO_ERROR ); for( int i = 0; i < 512; i++ ) BlockBuf[i] = 'C'; - rc += TestMethod( po, "WriteBlock()", f.WriteBlock( 2L, 512, BlockBuf ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "WriteBlock()", f.WriteBlock( 2L, 512, BlockBuf ), XB_NO_ERROR ); char BlockBuf2[513]; memset( BlockBuf2, 0x00, 513 ); - rc += TestMethod( po, "ReadBlock()", f.ReadBlock( 2L, 512, BlockBuf2 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "ReadBlock()", f.ReadBlock( 2L, 512, BlockBuf2 ), XB_NO_ERROR ); xbString s1 = BlockBuf; xbString s2 = BlockBuf2; - rc += TestMethod( po, "ReadBlock()", s1, s2, 512 ); - - rc += TestMethod( po, "xbTruncate()", f.xbTruncate( 1000 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "ReadBlock()", s1, s2, 512 ); + iRc += TestMethod( iPo, "xbTruncate()", f.xbTruncate( 1000 ), XB_NO_ERROR ); xbUInt64 ullFsize; - rc += TestMethod( po, "GetFileSize()", f.GetFileSize( ullFsize ), XB_NO_ERROR ); - rc += TestMethod( po, "xbGetFileSize()", (xbInt32) ullFsize, 1000 ); - rc += TestMethod( po, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetFileSize()", f.GetFileSize( ullFsize ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "xbGetFileSize()", (xbInt32) ullFsize, 1000 ); + iRc += TestMethod( iPo, "xbFclose()", f.xbFclose(), XB_NO_ERROR ); + - if( po > 0 || rc < 0 ) - fprintf( stdout, "Total Errors = %d\n", rc * -1 ); + 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], rc * -1 ); + sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 ); x.WriteLogMessage( sMsg ); #endif - return rc; + return iRc; } diff --git a/src/tests/xb_test_funcs.cpp b/src/tests/xb_test_funcs.cpp index c7bf0d3..7eb8b16 100755 --- a/src/tests/xb_test_funcs.cpp +++ b/src/tests/xb_test_funcs.cpp @@ -125,6 +125,8 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "CTOD( \"01\\03\\87\", dtResult )", x.CTOD( "01\\03\\87", dtResult ), XB_NO_ERROR ); iRc += TestMethod( po, "CTOD( \"01\\03\\87\", dtResult )", dtResult.Str(), "19870103", 8 ); iRc += TestMethod( po, "DATE( dtResult )", x.DATE( dtResult ), XB_NO_ERROR ); + + d.Sysdate(); iRc += TestMethod( po, "DATE( dtResult )", dtResult.Str(), d.Str(), 8 ); iRc += TestMethod( po, "DAY(\"19870103\", dResult )", x.DAY( "19870103", dResult ), XB_NO_ERROR ); iRc += TestMethod( po, "DAY(\"19870103\", dResult )", dResult, (xbDouble) 3 ); @@ -229,6 +231,7 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "x.RTRIM( \"zzz \", sResult )", sResult, "zzz", 3 ); iRc += TestMethod( po, "x.TRIM( \"aaa \", sResult )", x.TRIM( "aaa ", sResult ), XB_NO_ERROR ); iRc += TestMethod( po, "x.TRIM( \"aaa \", sResult )", sResult, "aaa", 3 ); + iRc += TestMethod( po, "x.SPACE( 3, sResult )", x.SPACE( 3, sResult ), XB_NO_ERROR ); iRc += TestMethod( po, "x.SPACE( 3, sResult )", sResult, " ", 3 ); iRc += TestMethod( po, "x.SQRT( 9, dResult )", x.SQRT( 9, dResult ), XB_NO_ERROR ); diff --git a/src/tests/xb_test_lock.cpp b/src/tests/xb_test_lock.cpp index 39332ad..2df71a8 100755 --- a/src/tests/xb_test_lock.cpp +++ b/src/tests/xb_test_lock.cpp @@ -34,7 +34,8 @@ int main( int argCnt, char **av ) /* 2 - VERBOSE */ xbInt16 iErrorStop = 0; - xbString sLockFile = "locktest.txt"; + xbString sLockFile; + xbString sLockFile2; xbString sLockCmd; xbString sResult; @@ -69,23 +70,34 @@ int main( int argCnt, char **av ) x.WriteLogMessage( sMsg ); #endif + x.SetDataDirectory( PROJECT_DATA_DIR ); InitTime(); #ifdef XB_DBF4_SUPPORT - MyFile = new xbDbf4( &x ); /* version 4 dbf file */ + MyFile = new xbDbf4( &x ); // version 4 dbf file #else - MyFile = new xbDbf3( &x ); /* version 3 dbf file */ + MyFile = new xbDbf3( &x ); // version 3 dbf file #endif iRc2 = MyFile->CreateTable( "LockTest.DBF", "LockTest", MyRecord, XB_OVERLAY, XB_MULTI_USER ); iRc += TestMethod( po, "CreateTable()", iRc2, XB_NO_ERROR ); + + #ifdef XB_MDX_SUPPORT + xbIx *ixPtr; + void *pTag; + iRc2 = MyFile->CreateTag( "MDX", "LockTag", "LOCKTEST", "", 0, 0, XB_OVERLAY, &ixPtr, &pTag ); + iRc += TestMethod( po, "CreateTag()", iRc2, XB_NO_ERROR ); + #endif // XB_MDX_SUPPORT + + iRc += TestMethod( po, "PutField()", MyFile->PutField( "LOCKTEST", "TEST" ), XB_NO_ERROR ); iRc += TestMethod( po, "AppendRecord()", MyFile->AppendRecord(), XB_NO_ERROR ); - iRc += TestMethod( po, "Close()", MyFile->Close(), XB_NO_ERROR ); - MyFile->Close(); + iRc += TestMethod( po, "Close()", MyFile->Close(), XB_NO_ERROR ); + + sLockFile.Sprintf( "%slocktest.txt", PROJECT_DATA_DIR ); + // std::cout << "xb_test_lock - lockfile = [ " << sLockFile.Str() << "]\n"; - //unlink( sLockFile ); - remove( sLockFile ); + remove( sLockFile.Str() ); #if defined (HAVE_FORK_F) pid_t pid; @@ -104,14 +116,15 @@ int main( int argCnt, char **av ) xbString sLastLockCmd; #ifdef XB_DBF4_SUPPORT - MyFileChld = new xbDbf4( &x ); /* version 4 dbf file */ + MyFileChld = new xbDbf4( &x ); // version 4 dbf file #else - MyFileChld = new xbDbf3( &x ); /* version 3 dbf file */ + MyFileChld = new xbDbf3( &x ); // version 3 dbf file #endif x.xbSleep( 250 ); while( !bDone ){ + iRc2 = GetCmd( x, sLockFile, sLockCmd, 'C', po ); if( sLockCmd == sLastLockCmd ) @@ -139,7 +152,6 @@ int main( int argCnt, char **av ) x.xbSleep( 250 ); } else { - if( sLockCmd == "START" ){ // begin the process iRcChld = MyFileChld->Open( "LockTest.DBF" ); @@ -199,8 +211,31 @@ int main( int argCnt, char **av ) #else sLockCmd = "OK"; #endif + + } else if( sLockCmd == "IL" ){ + // index lock + #ifdef XB_MDX_SUPPORT + if(( iRcChld = MyFileChld->LockIndices( XB_LOCK )) != XB_NO_ERROR ) + sResult = "FAIL"; + else + sResult = "OK"; + #else + sLockCmd = "OK"; + #endif // XB_MDX_SUPPORT + + } else if( sLockCmd == "IU" ){ + // index unlock + #ifdef XB_MDX_SUPPORT + if(( iRcChld = MyFileChld->LockIndices( XB_UNLOCK )) != XB_NO_ERROR ) + sResult = "FAIL"; + else + sResult = "OK"; + #else + sLockCmd = "OK"; + #endif // XB_MDX_SUPPORT } + #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Child task [%s] Result [%s] RC = [%d]", av[0], sLockCmd.Str(), sResult.Str(), iRcChld ); x.WriteLogMessage( sMsg ); @@ -212,7 +247,6 @@ int main( int argCnt, char **av ) delete MyFileChld; } } - } else { iRc = iRc2; bDone = xbTrue; @@ -226,6 +260,8 @@ int main( int argCnt, char **av ) delete MyFile; delete MyFileChld; + remove( sLockFile ); + if( po > 0 ) std::cout << "Exiting child\n"; @@ -241,9 +277,7 @@ int main( int argCnt, char **av ) xbInt16 iLoopCtr = 0; try{ - // start - #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing START command", av[0] ); x.WriteLogMessage( sMsg ); @@ -266,7 +300,7 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 10; + iErrorStop = 100; iRc2 = -1; throw iRc2; } @@ -294,19 +328,19 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 20; + iErrorStop = 110; iRc2 = -1; throw iRc2; } // attempt to lock table, should fail if(( iRc2 = MyFile->Open( "LockTest.DBF" )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc2; } if(( iRc2 = MyFile->LockTable( XB_LOCK )) == XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc2; } @@ -336,24 +370,24 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 50; + iErrorStop = 140; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc2; } if( po > 0 ) std::cout << "[PASS] LockTable Test 2\n"; if(( iRc2 = MyFile->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc2; } - /* record lock */ + // record lock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing RL command", av[0] ); x.WriteLogMessage( sMsg ); @@ -376,19 +410,19 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 80; + iErrorStop = 170; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockRecord( XB_LOCK, 1 )) == XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; throw iRc2; } if( po > 0 ) std::cout << "[PASS] LockRecord Test 1\n"; - /* record unlock */ + // record unlock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing RU command", av[0] ); x.WriteLogMessage( sMsg ); @@ -411,29 +445,29 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 100; + iErrorStop = 190; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockRecord( XB_LOCK, 1 )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 200; throw iRc2; } std::cout << "[PASS] LockRecord Test 2\n"; if(( iRc2 = MyFile->LockRecord( XB_UNLOCK, 1 )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 210; throw iRc2; } - /* memo lock */ + // memo lock #ifdef XB_MEMO_SUPPORT #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing ML command", av[0] ); x.WriteLogMessage( sMsg ); - #endif + #endif // XB_LOGGING_SUPPORT sLockCmd = "ML"; SetCmd( x, sLockFile, sLockCmd, 'P', po ); @@ -449,26 +483,26 @@ int main( int argCnt, char **av ) #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); x.WriteLogMessage( sMsg ); - #endif + #endif // XB_LOGGING_SUPPORT if( sResult != "OK" ){ - iErrorStop = 130; + iErrorStop = 220; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockMemo( XB_LOCK )) == XB_NO_ERROR ){ - iErrorStop = 140; + iErrorStop = 230; throw iRc2; } if( po > 0 ) std::cout << "[PASS] LockMemo Test 1\n"; - /* memo unlock */ + // memo unlock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing MU command", av[0] ); x.WriteLogMessage( sMsg ); - #endif + #endif // XB_LOGGING_SUPPORT sLockCmd = "MU"; SetCmd( x, sLockFile, sLockCmd, 'P', po ); @@ -484,30 +518,110 @@ int main( int argCnt, char **av ) #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); x.WriteLogMessage( sMsg ); - #endif + #endif // XB_LOGGING_SUPPORT if( sResult != "OK" ){ - iErrorStop = 150; + iErrorStop = 240; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockMemo( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 160; + iErrorStop = 250; throw iRc2; } std::cout << "[PASS] LockMemo Test 2\n"; if(( iRc2 = MyFile->LockMemo( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 170; + iErrorStop = 260; throw iRc2; } - #endif + #endif // XB_MEMO_SUPPORT + + // index lock + #ifdef XB_MDX_SUPPORT + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task issuing IL command", av[0] ); + x.WriteLogMessage( sMsg ); + #endif // XB_LOGGING_SUPPORT + + sLockCmd = "IL"; + SetCmd( x, sLockFile, sLockCmd, 'P', po ); + sResult = ""; + + GetCmd( x, sLockFile, sResult, 'P', po ); + while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 30 ){ + GetCmd( x, sLockFile, sResult, 'P', po ); + x.xbSleep( 250 ); + iLoopCtr++; + } + + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); + x.WriteLogMessage( sMsg ); + #endif // XB_LOGGING_SUPPORT + + if( sResult != "OK" ){ + iErrorStop = 270; + iRc2 = -1; + throw iRc2; + } + + if(( iRc2 = MyFile->LockIndices( XB_LOCK )) == XB_NO_ERROR ){ + iErrorStop = 280; + throw iRc2; + } + if( po > 0 ) + std::cout << "[PASS] LockIndex Test 1\n"; + + // memo unlock + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task issuing IU command", av[0] ); + x.WriteLogMessage( sMsg ); + #endif // XB_LOGGING_SUPPORT + + sLockCmd = "IU"; + SetCmd( x, sLockFile, sLockCmd, 'P', po ); + sResult = ""; + + GetCmd( x, sLockFile, sResult, 'P', po ); + while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 30 ){ + GetCmd( x, sLockFile, sResult, 'P', po ); + x.xbSleep( 250 ); + iLoopCtr++; + } + + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); + x.WriteLogMessage( sMsg ); + #endif // XB_LOGGING_SUPPORT + + if( sResult != "OK" ){ + iErrorStop = 290; + iRc2 = -1; + throw iRc2; + } + + if(( iRc2 = MyFile->LockIndices( XB_LOCK )) != XB_NO_ERROR ){ + iErrorStop = 300; + throw iRc2; + } + + std::cout << "[PASS] LockIndex Test 2\n"; + if(( iRc2 = MyFile->LockMemo( XB_UNLOCK )) != XB_NO_ERROR ){ + iErrorStop = 310; + throw iRc2; + } + #endif // XB_MDX_SUPPORT + + // exit sLockCmd = "EXIT"; SetCmd( x, sLockFile, sLockCmd, 'P', po ); + + } catch (xbInt16 iRc3 ){ iRc = iRc3; if( po > 0 ) @@ -533,6 +647,7 @@ int main( int argCnt, char **av ) SetCmd( x, sLockFile, sLockCmd, 'P', po ); MyFile->Close(); delete MyFile; + } #elif defined (HAVE_CREATEPROCESSW_F) @@ -578,7 +693,7 @@ int main( int argCnt, char **av ) GetCmd( x, sLockFile, sResult, 'P', po ); while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 10 ){ GetCmd( x, sLockFile, sResult, 'P', po ); - x.xbSleep( 250 ); + x.xbSleep( 300 ); iLoopCtr++; } @@ -600,7 +715,7 @@ int main( int argCnt, char **av ) GetCmd( x, sLockFile, sResult, 'P', po ); while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 10 ){ GetCmd( x, sLockFile, sResult, 'P', po ); - x.xbSleep( 250 ); + x.xbSleep( 310 ); iLoopCtr++; } @@ -610,19 +725,19 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 200; + iErrorStop = 320; iRc2 = -1; throw iRc2; } // attempt to lock table, should fail if(( iRc2 = MyFile->Open( "LockTest.DBF" )) != XB_NO_ERROR ){ - iErrorStop = 210; + iErrorStop = 330; throw iRc2; } if(( iRc2 = MyFile->LockTable( XB_LOCK )) == XB_NO_ERROR ){ - iErrorStop = 220; + iErrorStop = 340; throw iRc2; } @@ -658,13 +773,13 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 230; + iErrorStop = 350; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 240; + iErrorStop = 360; throw iRc2; } if( po > 0 ){ @@ -676,11 +791,11 @@ int main( int argCnt, char **av ) } if(( iRc2 = MyFile->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 250; + iErrorStop = 370; throw iRc2; } - /* record lock */ + // record lock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing RL command", av[0] ); x.WriteLogMessage( sMsg ); @@ -693,7 +808,7 @@ int main( int argCnt, char **av ) GetCmd( x, sLockFile, sResult, 'P', po ); while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 10 ){ GetCmd( x, sLockFile, sResult, 'P', po ); - x.xbSleep( 250 ); + x.xbSleep( 380 ); iLoopCtr++; } @@ -703,19 +818,19 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 260; + iErrorStop = 390; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockRecord( XB_LOCK, 1 )) == XB_NO_ERROR ){ - iErrorStop = 270; + iErrorStop = 400; throw iRc2; } if( po > 0 ) std::cout << "[PASS] LockRecord Test 1\n"; - /* record unlock */ + // record unlock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing RU command", av[0] ); x.WriteLogMessage( sMsg ); @@ -738,24 +853,23 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 280; + iErrorStop = 410; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockRecord( XB_LOCK, 1 )) != XB_NO_ERROR ){ - iErrorStop = 290; + iErrorStop = 420; throw iRc2; } std::cout << "[PASS] LockRecord Test 2\n"; if(( iRc2 = MyFile->LockRecord( XB_UNLOCK, 1 )) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 430; throw iRc2; } - - /* memo lock */ + // memo lock #ifdef XB_MEMO_SUPPORT #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing ML command", av[0] ); @@ -779,19 +893,19 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 310; + iErrorStop = 440; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockMemo( XB_LOCK )) == XB_NO_ERROR ){ - iErrorStop = 320; + iErrorStop = 450; throw iRc2; } if( po > 0 ) std::cout << "[PASS] LockMemo Test 1\n"; - /* memo unlock */ + // memo unlock #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Parent task issuing MU command", av[0] ); x.WriteLogMessage( sMsg ); @@ -814,19 +928,95 @@ int main( int argCnt, char **av ) #endif if( sResult != "OK" ){ - iErrorStop = 330; + iErrorStop = 460; iRc2 = -1; throw iRc2; } if(( iRc2 = MyFile->LockMemo( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 340; + iErrorStop = 470; throw iRc2; } std::cout << "[PASS] LockMemo Test 2\n"; if(( iRc2 = MyFile->LockMemo( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 350; + iErrorStop = 480; + throw iRc2; + } + #endif + + // index lock + #ifdef XB_MDX_SUPPORT + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task issuing IL command", av[0] ); + x.WriteLogMessage( sMsg ); + #endif + + sLockCmd = "IL"; + SetCmd( x, sLockFile, sLockCmd, 'P', po ); + sResult = ""; + + GetCmd( x, sLockFile, sResult, 'P', po ); + while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 10 ){ + GetCmd( x, sLockFile, sResult, 'P', po ); + x.xbSleep( 490 ); + iLoopCtr++; + } + + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); + x.WriteLogMessage( sMsg ); + #endif + + if( sResult != "OK" ){ + iErrorStop = 500; + iRc2 = -1; + throw iRc2; + } + + if(( iRc2 = MyFile->LockIndices( XB_LOCK )) == XB_NO_ERROR ){ + iErrorStop = 510; + throw iRc2; + } + if( po > 0 ) + std::cout << "[PASS] LockIndex Test 1\n"; + + // index unlock + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task issuing IU command", av[0] ); + x.WriteLogMessage( sMsg ); + #endif + + sLockCmd = "IU"; + SetCmd( x, sLockFile, sLockCmd, 'P', po ); + sResult = ""; + + GetCmd( x, sLockFile, sResult, 'P', po ); + while( sResult != "OK" && sResult != "FAIL" && iLoopCtr < 10 ){ + GetCmd( x, sLockFile, sResult, 'P', po ); + x.xbSleep( 250 ); + iLoopCtr++; + } + + #ifdef XB_LOGGING_SUPPORT + sMsg.Sprintf( "Program [%s] Parent task retrieved result [%s]", av[0], sResult.Str() ); + x.WriteLogMessage( sMsg ); + #endif + + if( sResult != "OK" ){ + iErrorStop = 520; + iRc2 = -1; + throw iRc2; + } + + if(( iRc2 = MyFile->LockIndices( XB_LOCK )) != XB_NO_ERROR ){ + iErrorStop = 530; + throw iRc2; + } + + std::cout << "[PASS] LockIndex Test 2\n"; + if(( iRc2 = MyFile->LockIndices( XB_UNLOCK )) != XB_NO_ERROR ){ + iErrorStop = 540; throw iRc2; } #endif @@ -835,6 +1025,7 @@ int main( int argCnt, char **av ) sLockCmd = "EXIT"; SetCmd( x, sLockFile, sLockCmd, 'P', po ); + } catch (xbInt16 iRc3 ){ if( po > 0 ) std::cout << "Parent lock task exiting on failure [" << sLockCmd.Str() << "][" << iErrorStop << "]\n"; @@ -852,6 +1043,7 @@ int main( int argCnt, char **av ) } #else + iRc--; sMsg.Sprintf( "Program [%s] not executed. Library does not support 'fork' or 'CreateProcess' function call", av[0] ); #ifdef XB_LOGGING_SUPPORT diff --git a/src/tests/xb_test_lock2.cpp b/src/tests/xb_test_lock2.cpp index d5534ec..82b4dea 100755 --- a/src/tests/xb_test_lock2.cpp +++ b/src/tests/xb_test_lock2.cpp @@ -38,8 +38,7 @@ int main( int argCnt, char **av ) /* 2 - VERBOSE */ xbBool bDone = xbFalse; -// xbInt16 iErrorStop = 0; - xbString sLockFile = "locktest.txt"; + xbString sLockFile; xbString sLockCmd; xbString sResult; xbInt32 iChildLoop = 0; @@ -74,6 +73,9 @@ int main( int argCnt, char **av ) x.SetDataDirectory( PROJECT_DATA_DIR ); InitTime(); + sLockFile.Sprintf( "%slocktest.txt", PROJECT_DATA_DIR ); + // std::cout << "xb_test_lock2 - lockfile = [ " << sLockFile.Str() << "]\n"; + #ifdef XB_DBF4_SUPPORT MyFile = new xbDbf4( &x ); /* version 4 dbf file */ #else @@ -166,7 +168,31 @@ int main( int argCnt, char **av ) #else sLockCmd = "OK"; #endif + + } else if( sLockCmd == "IL" ){ + // index lock + #ifdef XB_MDX_SUPPORT + if(( iRc2 = MyFile->LockIndices( XB_LOCK )) != XB_NO_ERROR ) + sResult = "FAIL"; + else + sResult = "OK"; + #else + sLockCmd = "OK"; + #endif + + } else if( sLockCmd == "IU" ){ + // index unlock + #ifdef XB_MDX_SUPPORT + if(( iRc2 = MyFile->LockIndices( XB_UNLOCK )) != XB_NO_ERROR ) + sResult = "FAIL"; + else + sResult = "OK"; + #else + sLockCmd = "OK"; + #endif } + + #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Child task [%s] Result [%s] RC = [%d]", av[0], sLockCmd.Str(), sResult.Str(), iRc2 ); x.WriteLogMessage( sMsg ); @@ -188,7 +214,7 @@ int main( int argCnt, char **av ) if( po > 0 ) std::cout << "Exiting child\n"; - remove( sLockFile ); + remove( sLockFile.Str() ); #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] Child task terminating", av[0] ); x.WriteLogMessage( sMsg ); @@ -202,6 +228,6 @@ int main( int argCnt, char **av ) x.WriteLogMessage( sMsg ); #endif - ExitProcess( iRc ); + ExitProcess( (xbUInt32) iRc ); } diff --git a/src/tests/xb_test_log.cpp b/src/tests/xb_test_log.cpp index 28ae552..a586809 100755 --- a/src/tests/xb_test_log.cpp +++ b/src/tests/xb_test_log.cpp @@ -41,7 +41,7 @@ int main( int argCnt, char **av ) } xbXBase x; - x.SetLogDirectory( PROJECT_LOG_DIR ); + x.EnableMsgLogging(); InitTime(); if( po ){ @@ -51,28 +51,58 @@ int main( int argCnt, char **av ) sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); - xbString sNewLogFileName = "Logfile2.txt"; - sMsg.Sprintf( "Switching to logfile [%s]", sNewLogFileName.Str() ); - x.WriteLogMessage( sMsg ); + // verify first logfile location is correct + xbString sWork; + x.GetHomeDir( sWork ); + std::cout << "Home Dir = " << sWork.Str() << std::endl; + + // verify home directory > 0 length + xbInt32 iLen = (xbInt32) sWork.Len(); + if( sWork.Len() == 0 ) + rc += TestMethod( po, "GetHomeDir()", iLen, 1 ); + else + rc += TestMethod( po, "GetHomeDir()", iLen, iLen ); + + sWork.Sprintf( "%s%cxbase64%clogs", sWork.Str(), + x.GetPathSeparator(), x.GetPathSeparator()); + + // verify path exists + // std::cout << "Home Dir = " << sHomeDir.Str() << std::endl; + xbFile f( &x ); + rc += TestMethod( po, "FileExists()", f.FileExists( sWork ), xbTrue ); + + + sWork.Sprintf( "%s%c%s", sWork.Str(), + x.GetPathSeparator(), x.GetLogFileName().Str() ); + + // std::cout << "Home Dir = " << sWork.Str() << std::endl; + rc += TestMethod( po, "FileExists()", f.FileExists( sWork ), xbTrue ); + rc += TestMethod( po, "Get Log Status()", x.GetLogStatus(), xbTrue ); + x.DisableMsgLogging(); - rc += TestMethod( po, "Set/Get Log Status()", x.GetLogStatus(), xbFalse ); - x.SetLogFileName( sNewLogFileName ); + rc += TestMethod( po, "Get Log Status()", x.GetLogStatus(), xbFalse ); + xbString sNewLogFileName = "Logfile2.txt"; + x.SetLogDirectory( PROJECT_LOG_DIR ); + x.SetLogFileName( sNewLogFileName ); + sWork.Sprintf( "%s%c%s", + PROJECT_LOG_DIR, x.GetPathSeparator(), sNewLogFileName.Str()); + + sMsg.Sprintf( "Switching to logfile [%s]", sWork.Str() ); x.EnableMsgLogging(); - rc += TestMethod( po, "Set/Get Log Status()", x.GetLogStatus(), 1 ); - rc += TestMethod( po,"WriteLogMessage()", x.WriteLogMessage( "Test log message........" ), XB_NO_ERROR ); + rc += TestMethod( po, "Get Log Status()", x.GetLogStatus(), xbTrue ); + rc += TestMethod( po, "FileExists()", f.FileExists( sWork ), xbTrue ); - sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], rc * -1 ); x.WriteLogMessage( sMsg ); + rc += TestMethod( po, "Get Log Status()", x.GetLogStatus(), xbTrue ); + x.WriteLogMessage( "Test Log Message" ); if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); - #endif /* XB_LOGGING_SUPPORT */ - return rc; } diff --git a/src/tests/xb_test_mdx.cpp b/src/tests/xb_test_mdx.cpp index 2ef5ffb..680be5c 100755 --- a/src/tests/xb_test_mdx.cpp +++ b/src/tests/xb_test_mdx.cpp @@ -1,4 +1,4 @@ -/* xb_test_ndx.cpp +/* xb_test_mdx.cpp XBase64 Software Library @@ -280,9 +280,18 @@ int main( int argCnt, char **av ) iRc += TestMethod( iPo, "CheckTagIntegrity(7)", V4DbfX2->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR ); + + + iRc2 = V4DbfX2->CreateTag( "MDX", "TAG2", "CHAR27", ".NOT. DELETED()", 0, 1, XB_OVERLAY, &pIx, &pTag ); + iRc += TestMethod( iPo, "CreateTag(5)", iRc2, 0 ); + + iRc2 += V4DbfX2->Reindex( 1 ); + iRc += TestMethod( iPo, "Reindex()", iRc2, XB_KEY_NOT_UNIQUE ); + + x.CloseAllTables(); - delete V4DbfX1; - delete V4DbfX2; +// delete V4DbfX1; +// delete V4DbfX2; if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); diff --git a/src/tests/xb_test_ndx.cpp b/src/tests/xb_test_ndx.cpp index 34496b6..320a1c9 100755 --- a/src/tests/xb_test_ndx.cpp +++ b/src/tests/xb_test_ndx.cpp @@ -117,6 +117,14 @@ int main( int argCnt, char **av ) iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxN.NDX", 0 ); iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + xbInt16 iTagCnt = ixPtr->GetTagCount(); + iRc += TestMethod( iPo, "GetTagCount()", (xbInt32) iTagCnt, 1 ); + + xbString sTagName; + sTagName = ixPtr->GetTagName( &ndx ); + iRc += TestMethod( iPo, "GetTagName()", sTagName.Str(), "TestNdxN", 8 ); + + #ifdef XB_LOCKING_SUPPORT iRc += TestMethod( iPo, "LockTable()", V3Dbf->LockTable( XB_LOCK ), XB_NO_ERROR ); #endif @@ -307,13 +315,12 @@ int main( int argCnt, char **av ) 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 ); + iRc += TestMethod( iPo, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 0 ), XB_NO_ERROR ); ixl = ixl->next; } } @@ -382,14 +389,54 @@ int main( int argCnt, char **av ) 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 ); + iRc += TestMethod( iPo, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 0 ), XB_NO_ERROR ); } ixl = ixl->next; } -// iRc += TestMethod( iPo, "DeleteTable()", V3Dbf->DeleteTable(), XB_NO_ERROR ); + iRc2 = V3Dbf->Reindex( 1 ); // reindex all tags + iRc += TestMethod( iPo, "Reindex()", (xbInt32) iRc2, XB_NO_ERROR ); + + iRc += TestMethod( iPo, "DeleteTable()", V3Dbf->DeleteTable(), XB_NO_ERROR ); + + + + // test tag delete on unsuccessful reindex + + iRc2 = V3Dbf->CreateTable( "TestNdx.DBF", "TestNdx", MyV3Record, XB_OVERLAY, XB_MULTI_USER ); + iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + + 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 ); + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), 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 ); + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), 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 ); + + iRc2 = V3Dbf->Reindex( 1 ); // verify reindex works with no tags + iRc += TestMethod( iPo, "Reindex()", (xbInt32) iRc2, XB_NO_ERROR ); + + + x.SetUniqueKeyOpt( XB_HALT_ON_DUPKEY ); + iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxX.NDX", "CFLD", "", 0, 1, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + + iRc2 = V3Dbf->Reindex( 1 ); // verify reindex fails with dup key + iRc += TestMethod( iPo, "Reindex()", (xbInt32) iRc2, XB_KEY_NOT_UNIQUE ); x.CloseAllTables(); +// delete V3Dbf; if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); diff --git a/src/tests/xb_test_sql.cpp b/src/tests/xb_test_sql.cpp index 99a4f0b..3341895 100755 --- a/src/tests/xb_test_sql.cpp +++ b/src/tests/xb_test_sql.cpp @@ -57,11 +57,12 @@ int main( int argCnt, char **av ) { "",0,0,0 } }; - above structure below, depending on how table is created + above structure corresponds to sql below sSql = "CREATE TABLE Address.DBF ( ADDRESS CHAR(30), CITY CHAR(30), STATE CHAR(2), ZIPCODE NUMERIC(9,0), NOTES VARCHAR, LASTUPDATE DATE, ACTIVE LOGICAL )"; */ +/* xbSchema MyZipRecord[] = { { "ZIPCODE", XB_NUMERIC_FLD, 9, 0 }, @@ -69,7 +70,7 @@ int main( int argCnt, char **av ) { "STATE", XB_CHAR_FLD, 2, 0 }, { "",0,0,0 } }; - +*/ xbXBase x; #ifdef XB_LOGGING_SUPPORT @@ -85,54 +86,32 @@ int main( int argCnt, char **av ) x.SetDataDirectory( PROJECT_DATA_DIR ); - InitTime(); xbSql sql( &x ); if( po > 0 ) std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; - - xbDbf4 SqlDbf( &x ); // version 4 dbf file - xbDbf4 SqlDbfZ( &x ); // version 4 dbf file - - - - - - sSql = "DROP TABLE IF EXISTS AddressR.DBF"; +/* + // verify a delete on a non existant table doesn't crash things + sSql = "DROP TABLE IF EXISTS NoTable.DBF"; iRc2 = sql.ExecuteNonQuery( sSql ); iRc += TestMethod( po, "DropTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); - - sSql = "DROP TABLE IF EXISTS Address.DBF"; iRc2 = sql.ExecuteNonQuery( sSql ); iRc += TestMethod( po, "DropTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); - - sSql = "CREATE TABLE Address.DBF ( ADDRESS CHAR(30), CITY CHAR(30), STATE CHAR(2), ZIPCODE NUMERIC(9,0), NOTES VARCHAR, LASTUPDATE DATE, ACTIVE LOGICAL )"; - iRc2 = sql.ExecuteNonQuery( sSql ); iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); -/* - non sql way to create a table - iRc2 = SqlDbf.CreateTable( "Address.DBF", "Address", MyAddressRecord, XB_OVERLAY, XB_MULTI_USER ); - iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); - if( iRc2 ) - x.DisplayError( iRc2 ); -*/ - -// return 0; - #ifdef XB_MDX_SUPPORT sSql = "CREATE INDEX tag1 ON Address.DBF( CITY, STATE, DTOS( LASTUPDATE )) FILTER .NOT. DELETED()"; // xbString sSql = "CREATE INDEX tag1 ON Address.DBF( CITY, STATE )"; @@ -155,8 +134,13 @@ int main( int argCnt, char **av ) if( iRc2 ) x.DisplayError( iRc2 ); - sSql = "ALTER TABLE Address.DBF RENAME TO AddressR.DBF"; + sSql = "DROP TABLE IF EXISTS AddressR.DBF"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "DropTable()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + sSql = "ALTER TABLE Address.DBF RENAME TO AddressR.DBF"; iRc2 = sql.ExecuteNonQuery( sSql ); iRc += TestMethod( po, "SqlAlterTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) @@ -186,64 +170,91 @@ int main( int argCnt, char **av ) if( iRc2 ) x.DisplayError( iRc2 ); + sSql = "DELETE FROM AddressR.DBF WHERE BAD='EXPRESSION'"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_INVALID_FIELD_NAME ); - iRc2 = SqlDbfZ.CreateTable( "ZipCode.DBF", "", MyZipRecord, XB_OVERLAY, XB_MULTI_USER ); - iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + + sSql = "DROP TABLE IF EXISTS AddressR.DBF"; + iRc += TestMethod( po, "Drop Table()", sql.ExecuteNonQuery( sSql ), XB_NO_ERROR ); + iRc += TestMethod( po, "Drop Table()", sql.ExecuteNonQuery( sSql ), XB_NO_ERROR ); + +*/ + + + sSql = "DROP TABLE IF EXISTS ZipCode.DBF"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "DropTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); -// sSql = "INSERT INTO ZipCode.DBF ( ZIPCODE, CITY, STATE ) VALUES ( 75087, 'Rockwall', 'TX' )"; - + sSql = "CREATE TABLE ZipCode.DBF ( ZIPCODE NUMERIC(9,0), CITY CHAR(30), STATE CHAR(2) )"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); -// std::cout << "---------------------------------------------------------\n"; -// std::cout << sSql.Str() << "\n"; + sSql = "INSERT INTO ZipCode.DBF ( ZIPCODE, CITY, STATE ) VALUES ( 75087, 'Rockwall', 'TX' )"; + iRc2 = sql.ExecuteNonQuery( sSql ); - sSql = "INSERT INTO ZipCode ( CITY ) VALUES ( 'city' )"; + sSql = "INSERT INTO ZipCode.DBF ( ZIPCODE, CITY, STATE ) VALUES ( 75087, 'Rockwall', 'TX' )"; iRc2 = sql.ExecuteNonQuery( sSql ); - iRc += TestMethod( po, "SqlInsert()", (xbInt32) iRc2, XB_NO_ERROR ); + +/* + + sSql = "CREATE INDEX ZipCode1.NDX ON ZipCode.DBF( ZIPCODE ) ASSOCIATE"; + iRc2 = sql.ExecuteNonQuery( sSql ); if( iRc2 ) x.DisplayError( iRc2 ); + iRc += TestMethod( po, "Create Index()", (xbInt32) iRc2, XB_NO_ERROR ); +*/ + sSql = "CREATE UNIQUE INDEX ZipCode2.NDX ON ZipCode.DBF( ZIPCODE ) ASSOCIATE"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "Create Index()", (xbInt32) iRc2, XB_KEY_NOT_UNIQUE ); + -//**************** work in progress /* - sSql = "DELETE FROM AddressR.DBF WHERE BAD='EXPRESSION'"; + sSql = "DROP TABLE IF EXISTS ZipCode.DBF"; iRc2 = sql.ExecuteNonQuery( sSql ); - iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_INVALID_FIELD_NAME ); + iRc += TestMethod( po, "DropTable()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); */ -// if( iRc2 ) -// x.DisplayError( iRc2 ); +// sSql = "INSERT INTO ZipCode.DBF ( ZIPCODE, CITY, STATE ) VALUES ( 75087, 'Rockwall', 'TX' )"; +// iRc2 = sql.ExecuteNonQuery( sSql ); + + + x.DisplayTableList(); - iRc += TestMethod( po, "Close()", SqlDbf.Close(), XB_NO_ERROR ); - iRc += TestMethod( po, "Close()", SqlDbfZ.Close(), XB_NO_ERROR ); -// return 0; -// std::cout << "---------------------------------------------------------\n"; +/* + sSql = "CREATE INDEX ZipCode.NDX ON Addres.DBF( ZIPCODE )"; - xbStmt sqlQry1( &x ); -// sSql = "SELECT CITY, STATE, ZIPCODE FROM Address.DBF T LEFT JOIN LJ.DBF LJ WHERE CITY IS NOT NULL ORDER BY 2 GROUP BY STATE HAVING ZIPCODE .NOT. NULL"; -// sSql = "SELECT CITY, STATE, ZIPCODE FROM AddressR.DBF T WHERE CITY IS NOT NULL ORDER BY 2 GROUP BY STATE HAVING ZIPCODE .NOT. NULL"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); +*/ -// sSql = "SELECT CITY, STATE, ZIPCODE FROM AddressR A LEFT JOIN ZipCode Z ON A.ZIPCODE = Z.ZIPCODE WHERE CITY IS NOT NULL ORDER BY 2 GROUP BY STATE HAVING ZIPCODE .NOT. NULL"; -// sSql = "SELECT M.ID, M.LEFTFK0, L0.CFLD FROM MAIN0 M LEFT JOIN LEFT0 L0 ON M.LEFTFK0 = L0.LEFTFK0 WHERE M.ID IS NOT NULL"; - iRc += TestMethod( po, "Select()", sqlQry1.ExecuteQuery( sSql ), XB_NO_ERROR ); +// sSql = "DROP TABLE IF EXISTS AddressR.DBF"; +// iRc += TestMethod( po, "Drop Table()", sqlQry1.ExecuteQuery( sSql ), XB_NO_ERROR ); - sqlQry1.DumpStmtInternals(); - // sqlQry1.Test(); - x.DisplayTableList(); + // x.DisplayTableList(); + x.CloseAllTables(); if( po > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); diff --git a/src/tests/xb_test_string.cpp b/src/tests/xb_test_string.cpp index 2f01e51..9dd48af 100755 --- a/src/tests/xb_test_string.cpp +++ b/src/tests/xb_test_string.cpp @@ -188,6 +188,19 @@ int main( int argCnt, char **av = NULL ) s2 = "!@#"; rc += TestMethod( po, "s1.Append( '!@#' )", s1.Append( s2 ), "ABCDEFGZ999!@#", 14 ); + xbString sAppend1; + sAppend1.Append( "abc123", 6 ); + rc += TestMethod( po, "Append", sAppend1, "abc123", 6 ); + + xbString sAppend2; + sAppend2.Append( "abc123", 8 ); + rc += TestMethod( po, "Append", sAppend2, "abc123", 6 ); + + xbString sAppend3; + sAppend3.Append( "abc123", 3 ); + rc += TestMethod( po, "Append", sAppend3, "abc", 3 ); + + rc += TestMethod( po, "s1.Assign( 'ABCDE', 3, 2 )", s1.Assign( "ABCDE", 3, 2 ), "CD", 2 ); rc += TestMethod( po, "s1.Assign( 'ABCDE', 2, 7 )", s1.Assign( "ABCDE", 2, 7 ), "BCDE", 4 ); rc += TestMethod( po, "s1.Assign( 'ABCDE', 1, 4 )", s1.Assign( "ABCDE", 1, 4 ), "ABCD", 4 ); @@ -222,10 +235,24 @@ int main( int argCnt, char **av = NULL ) s1.CvtHexString( s2 ); rc += TestMethod( po, "CvtHexString() ", s2, "abcde", 5 ); - s1 = "123"; - s2 = "ABC"; - rc += TestMethod( po, "HasAlphaChars()", s1.HasAlphaChars(), 0 ); - rc += TestMethod( po, "HasAlphaChars()", s2.HasAlphaChars(), 1 ); + s1.ExtractElement( "aaaa|bbbb|cccc|dddd", '|', 2, 0 ); + rc += TestMethod( po, "ExtractElement() ", s1, "bbbb", 4 ); + + s1.ExtractElement( "aaaa|b'bb|c'ccc|dddd", '|', 3, 1 ); + rc += TestMethod( po, "ExtractElement() ", s1, "dddd", 4 ); + + s1 = "aaaa|bbbb|cccc|dddd"; + s2.ExtractElement( s1, '|', 2, 0 ); + rc += TestMethod( po, "ExtractElement() ", s2, "bbbb", 4 ); + + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'b' ), 8 ); + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'x' ), 9 ); + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( '$' ), 0 ); + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( "ab" ), 7 ); + s1 = "\\ABC\\XYZ"; rc += TestMethod( po, "GetPathSeparator()", s1.GetPathSeparator(), '\\' ); @@ -233,14 +260,36 @@ int main( int argCnt, char **av = NULL ) s1 = "/ABC/XYZ"; rc += TestMethod( po, "GetPathSeparator()", s1.GetPathSeparator(), '/' ); + + s1 = "123"; + s2 = "ABC"; + rc += TestMethod( po, "HasAlphaChars()", s1.HasAlphaChars(), 0 ); + rc += TestMethod( po, "HasAlphaChars()", s2.HasAlphaChars(), 1 ); + + s2 = ""; rc += TestMethod( po, "IsEmpty()", s2.IsEmpty(), 1 ); + + s1.SetNum( (long) 123456 ); + + s1 = "abcZZZ123"; + s1.Left( 4 ); + rc += TestMethod( po, "Left(4) ", s1, "abcZ", 4 ); + + s1.Left( 1 ); + rc += TestMethod( po, "Left(1) ", s1, "a", 1 ); + + s1.Left( 0 ); + rc += TestMethod( po, "Left(0) ", s1, "", 0 ); + // trim tests s1 = " ABC "; rc += TestMethod( po, "Ltrim()", s1.Ltrim(), "ABC ", 6 ); + s1 = " ABC "; rc += TestMethod( po, "Rtrim()", s1.Rtrim(), " ABC", 6 ); + s1 = " ABC "; rc += TestMethod( po, "Trim() ", s1.Trim(), "ABC", 3 ); @@ -253,6 +302,20 @@ int main( int argCnt, char **av = NULL ) s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; rc += TestMethod( po, "Mid(4,5) ", s1.Mid(4,5), "DEFGH", 5 ); + s1 = "123"; + s1.PadLeft( '0', 9 ); + rc += TestMethod( po, "PadLeft() ", s1, "000000123", 9 ); + + s1 = "abc"; + s1.PadRight( 'Z', 9 ); + rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + + s1.PadRight( 'Z', 4 ); + rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + + + + s1 = "DEFGHI"; rc += TestMethod( po, "Pos('G') ", (xbInt32) s1.Pos( 'G' ), 4 ); rc += TestMethod( po, "Pos(\"EFG\") ", (xbInt32) s1.Pos( "EFG" ), 2 ); @@ -269,48 +332,32 @@ int main( int argCnt, char **av = NULL ) s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; rc += TestMethod( po, "Remove(3,5) ", s1.Remove( 3, 5 ), "ABHIJKLMNOPQRSTUVWXYZ", 21 ); + s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + rc += TestMethod( po, "Remove(22,5) ", s1.Remove( 22, 5 ), "ABCDEFGHIJKLMNOPQRSTU", 21 ); + s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + rc += TestMethod( po, "Remove(24,5) ", s1.Remove( 24, 5 ), "ABCDEFGHIJKLMNOPQRSTUVW", 23 ); - s1 = "ABCABCABZ"; - s1.SwapChars( 'A', '9' ); - rc += TestMethod( po, "SwapChars() ", s1, "9BC9BC9BZ", 9 ); - - s1.ToLowerCase(); - rc += TestMethod( po, "ToLowerCase() ", s1, "9bc9bc9bz", 9 ); - - s1.ToUpperCase(); - rc += TestMethod( po, "ToUpperCase() ", s1, "9BC9BC9BZ", 9 ); - - s1.ZapChar( '9' ); - rc += TestMethod( po, "ZapChar('9') ", s1, "BCBCBZ", 6 ); - - s1.ZapLeadingChar( 'B' ); - rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCBZ", 5 ); - - s1.ZapTrailingChar( 'Z' ); - rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCB", 4 ); - - s1.ExtractElement( "aaaa|bbbb|cccc|dddd", '|', 2, 0 ); - rc += TestMethod( po, "ExtractElement() ", s1, "bbbb", 4 ); - - s1.ExtractElement( "aaaa|b'bb|c'ccc|dddd", '|', 3, 1 ); - rc += TestMethod( po, "ExtractElement() ", s1, "dddd", 4 ); - - s1 = "123"; - s1.PadLeft( '0', 9 ); - rc += TestMethod( po, "PadLeft() ", s1, "000000123", 9 ); - - s1 = "abc"; - s1.PadRight( 'Z', 9 ); - rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + s1.Set( "abcdef.dbf" ); + s1.Replace( "def", "DEF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.dbf", 10 ); + s1.Replace( ".dbf", ".DBF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.DBF", 10 ); + s1.Set( "abcdef.dbf" ); + s1.Replace( "def", "DEFG" ); + rc += TestMethod( po, "Replace", s1, "abcDEFG.dbf", 11 ); + s1.Set( "abcdefdef.dbf" ); + s1.Replace( "def", "DEFG" ); + rc += TestMethod( po, "Replace", s1, "abcDEFGDEFG.dbf", 15 ); - s1.Left( 4 ); - rc += TestMethod( po, "Left(4) ", s1, "abcZ", 4 ); - s1.Left( 1 ); - rc += TestMethod( po, "Left(1) ", s1, "a", 1 ); + s1.SetNum( (long) 123456 ); + rc += TestMethod( po, "SetNum() ", s1, "123456", 6 ); - s1.Left( 0 ); - rc += TestMethod( po, "Left(0) ", s1, "", 0 ); + xbFloat f = (xbFloat) 12.35; + // %f format varies depending on compiler + s1.Sprintf( "%6.2f", f ); + s1.Ltrim(); + rc += TestMethod( po, "s1.Sprintf()/s.Trim()", s1, "12.35", 5 ); char buf[5]; buf[0] = 'W'; @@ -319,18 +366,20 @@ int main( int argCnt, char **av = NULL ) buf[3] = 'Z'; buf[4] = 0x00; xbInt32 l = 1234567; - xbFloat f = (xbFloat) 12.35; s2 = "test string"; rc += TestMethod( po, "s1.Sprintf()", s1.Sprintf( "%s %d %s %ld", buf, 12, s2.Str(), l ), "WXYZ 12 test string 1234567", 27 ); - // %f format varies depending on compiler - s1.Sprintf( "%6.2f", f ); - s1.Ltrim(); - rc += TestMethod( po, "s1.Sprintf()/s.Trim()", s1, "12.35", 5 ); - s1.SetNum( (long) 123456 ); - rc += TestMethod( po, "SetNum() ", s1, "123456", 6 ); + s1 = "ABCABCABZ"; + s1.SwapChars( 'A', '9' ); + rc += TestMethod( po, "SwapChars() ", s1, "9BC9BC9BZ", 9 ); + + s1.ToLowerCase(); + rc += TestMethod( po, "ToLowerCase() ", s1, "9bc9bc9bz", 9 ); + + s1.ToUpperCase(); + rc += TestMethod( po, "ToUpperCase() ", s1, "9BC9BC9BZ", 9 ); s1 = "T"; rc += TestMethod( po, "ValidLogicalValue", s1.ValidLogicalValue(), 1 ); @@ -344,13 +393,19 @@ int main( int argCnt, char **av = NULL ) s1 = "ABC-123456.89"; rc += TestMethod( po, "ValidNumericValue", s1.ValidNumericValue(), 0 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'b' ), 8 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'x' ), 9 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( '$' ), 0 ); - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( "ab" ), 7 ); + + s1 = "BC9BC99BZ"; + s1.ZapChar( '9' ); + rc += TestMethod( po, "ZapChar('9') ", s1, "BCBCBZ", 6 ); + + s1.ZapLeadingChar( 'B' ); + rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCBZ", 5 ); + + s1.ZapTrailingChar( 'Z' ); + rc += TestMethod( po, "ZapTrailingChar('Z') ", s1, "CBCB", 4 ); + s1.ZapTrailingChar( 'Z' ); + rc += TestMethod( po, "ZapTrailingChar('Z') ", s1, "CBCB", 4 ); + s1 = ")"; rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( ')' ), 1 ); @@ -385,17 +440,12 @@ int main( int argCnt, char **av = NULL ) s3.Sprintf( "%s and %s", s1.Str(), s2.Str()); rc += TestMethod( po, "Sprintf", s3, "string 1 and string 2.0", 23 ); - s1.Set( "abcdef.dbf" ); - s1.Replace( "def", "DEF" ); - rc += TestMethod( po, "Replace", s1, "abcDEF.dbf", 10 ); - s1.Replace( ".dbf", ".DBF" ); - rc += TestMethod( po, "Replace", s1, "abcDEF.DBF", 10 ); - +/* xbInt16 iErrorStop = 10; xbInt16 iRc = -100; sMsg.Sprintf( "class::method() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, s3.Str() ); - +*/ if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); diff --git a/src/tests/xb_test_tblmgr.cpp b/src/tests/xb_test_tblmgr.cpp index d048594..4e177d0 100755 --- a/src/tests/xb_test_tblmgr.cpp +++ b/src/tests/xb_test_tblmgr.cpp @@ -96,39 +96,6 @@ int main( int argCnt, char **av ) } -std::cout << "cp0\n"; - x.SetDataDirectory( "/ABCDEFG/" ); - - #ifdef WIN32 - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 ); - #else - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 ); - #endif -std::cout << "cp1\n"; - x.SetDataDirectory( "/ABCDEFG" ); - #ifdef WIN32 - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 ); - #else - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 ); - #endif - - - x.SetDataDirectory( "\\ABCDEFG\\"); - #ifdef WIN32 - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 ); - #else - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 ); - #endif - - x.SetDataDirectory( "\\ABCDEFG" ); - #ifdef WIN32 - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 ); - #else - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 ); - #endif - - x.SetDataDirectory( "ABCDEFG" ); - iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "ABCDEFG", 7 ); iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableB" ), 0 ); iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableB" ), XB_NOT_FOUND ); diff --git a/src/tests/xb_test_tdx.cpp b/src/tests/xb_test_tdx.cpp new file mode 100755 index 0000000..5d79f04 --- /dev/null +++ b/src/tests/xb_test_tdx.cpp @@ -0,0 +1,162 @@ +/* xb_test_tdx.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022,2023 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 + + +#include "xbase.h" + +using namespace xb; + +#include "tstfuncs.cpp" + +int main( int argCnt, char **av ) +{ + int iRc = 0; + int iRc2; + int iPo = 1; /* print option */ + /* 0 - QUIET */ + /* 1 - NORMAL */ + /* 2 - VERBOSE */ + + xbString sMsg; + char c; + xbString s; + + if( argCnt > 1 ) { + if( av[1][0] == 'Q' ) + iPo = 0; + else if( av[1][0] == 'V' ) + iPo = 2; + } + + + xbSchema MyV4Record[] = + { + { "CITY", XB_CHAR_FLD, 100, 0 }, + { "STATE", XB_CHAR_FLD, 2, 0 }, + { "ZIP", XB_NUMERIC_FLD, 9, 0 }, + { "DATE1", XB_DATE_FLD, 8, 0 }, + { "",0,0,0 } + }; + + + + xbXBase x; + + #ifdef XB_LOGGING_SUPPORT + x.SetLogDirectory( PROJECT_LOG_DIR ); + x.EnableMsgLogging(); + if( iPo ){ + std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; + } + sMsg.Sprintf( "Program [%s] initializing...", av[0] ); + x.WriteLogMessage( sMsg ); + #endif + + x.SetDataDirectory( PROJECT_DATA_DIR ); + x.SetTempDirectory( PROJECT_TEMP_DIR ); + x.SetMultiUser( xbFalse ); + InitTime(); + + if( iPo > 0 ) + std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; + + + xbFile f( &x ); + xbIx *pIx; + void *pTag; + xbDate dt = "19890209"; + xbString sKey; + + xbDbf *V4DbfX1 = new xbDbf4( &x ); + + + iRc2 = V4DbfX1->CreateTable( "TTDXDB01.DBF", "TestMdxX2", MyV4Record, XB_OVERLAY, XB_MULTI_USER ); + iRc += TestMethod( iPo, "CreateTable(1)", iRc2, 0 ); + + iRc2 = V4DbfX1->CreateTag( "TDX", "CITY_TAGA", "CITY", "", 0, 0, XB_OVERLAY, &pIx, &pTag ); + iRc += TestMethod( iPo, "CreateTag(1)", iRc2, 0 ); + + std::cout << "Cur Tag Name = " << V4DbfX1->GetCurTagName().Str() << "\n"; + + xbString sFqFileName = pIx->GetFqFileName(); + iRc2 = V4DbfX1->DeleteTag( "TDX", V4DbfX1->GetCurTagName() ); + + iRc += TestMethod( iPo, "DeleteTag(3)", iRc2, 0 ); + + // only one tag, file should not exist anymore + iRc2 = pIx->FileExists(sFqFileName); + iRc += TestMethod( iPo, "FileExists()", iRc2, 0 ); + + iRc2 = V4DbfX1->CreateTag( "TDX", "ZIP_TAG", "ZIP", "", xbTrue, 0, XB_OVERLAY, &pIx, &pTag ); + iRc += TestMethod( iPo, "CreateTag(2)", iRc2, 0 ); + + xbInt32 uZip = 10000; + for( xbUInt16 i = 0; i < 5; i++ ){ + for( xbUInt16 j = 0; j < 4; j++ ){ + + c = j + 65; + s = c; + s.PadRight( c, (xbUInt32) i + 1 ); + //std::cout << "*********** adding s=[" << s.Str() << "] length = " << s.Len() << "\n"; + iRc2 = V4DbfX1->BlankRecord(); + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "BlankRecord()", iRc2, XB_NO_ERROR ); + + iRc2 = V4DbfX1->PutField( "CITY", s ); + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR ); + + iRc2 = V4DbfX1->PutLongField( "ZIP", uZip++ ); + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR ); + + iRc2 = V4DbfX1->PutDateField( "DATE1", dt ); + dt++; + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR ); + + iRc2 = V4DbfX1->AppendRecord(); + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "AppendRecord()", iRc2, XB_NO_ERROR ); + + iRc2 = V4DbfX1->Commit(); + if( iRc2 != XB_NO_ERROR ) + iRc += TestMethod( iPo, "Commit()", iRc2, XB_NO_ERROR ); + } + } + + + iRc += TestMethod( iPo, "CheckTagIntegrity(1)", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR ); + + + x.CloseAllTables(); + +// delete V4DbfX1; +// delete V4DbfX2; + + 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 ); +#endif + + return iRc; +} diff --git a/src/tests/xb_test_xbase.cpp b/src/tests/xb_test_xbase.cpp index 4751c25..a0affd6 100755 --- a/src/tests/xb_test_xbase.cpp +++ b/src/tests/xb_test_xbase.cpp @@ -90,6 +90,119 @@ int main( int argCnt, char **av ) std::cout << "DisplayError Test ==> "; x.DisplayError( 0 ); } + + #ifdef WIN32 + char cSep = '\\'; + iRc += TestMethod( iPo, "GetPathSeparator()", x.GetPathSeparator(), cSep ); + #else + char cSep = '/'; + iRc += TestMethod( iPo, "GetPathSeparator()", x.GetPathSeparator(), cSep ); + #endif + + + + xbString sDir = "\\dir\\path"; + xbString sFile = "myfile"; + xbString sExt = "DBF"; + xbString sFqn; + iRc += TestMethod( iPo, "CreateFQN()", x.CreateFqn( sDir, sFile, sExt, sFqn ), XB_NO_ERROR ); + //std::cout << "FQN = [" << sFqn.Str() << "]\n"; + #ifdef WIN32 + iRc += TestMethod( iPo, "CreateFQN()", sFqn.Str(), "\\dir\\path\\myfile.DBF", 20 ); + #else + iRc += TestMethod( iPo, "CreateFQN()", sFqn.Str(), "/dir/path/myfile.DBF", 20 ); + #endif + + sDir = "/dir/path"; + iRc += TestMethod( iPo, "CreateFQN()", x.CreateFqn( sDir, sFile, sExt, sFqn ), XB_NO_ERROR ); + #ifdef WIN32 + iRc += TestMethod( iPo, "CreateFQN()", sFqn.Str(), "\\dir\\path\\myfile.DBF", 20 ); + #else + iRc += TestMethod( iPo, "CreateFQN()", sFqn.Str(), "/dir/path/myfile.DBF", 20 ); + #endif + + + x.SetDataDirectory( "/ABCDEFG/" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 ); + #endif + + x.SetDataDirectory( "/ABCDEFG" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 ); + #else + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 ); + #endif + + x.SetDataDirectory( "\\ABCDEFG\\"); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 ); + #endif + + x.SetDataDirectory( "\\ABCDEFG" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 ); + #else + iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 ); + #endif + +#ifdef XB_LOGGING_SUPPORT + + x.SetLogDirectory( "ABCDEFG" ); + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "ABCDEFG", 7 ); + x.SetLogDirectory( "/ABCDEFG/" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "/ABCDEFG/", 9 ); + #endif + + x.SetLogDirectory( "/ABCDEFG" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "\\ABCDEFG", 8 ); + #else + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "/ABCDEFG", 8 ); + #endif + + x.SetLogDirectory( "\\ABCDEFG\\"); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetLogDirectory()", x.GetLogDirectory(), "/ABCDEFG/", 9 ); + #endif + + x.SetLogFileName( "LogFileNameTest" ); + iRc += TestMethod( iPo, "Set/GetLogFileName()", x.GetLogFileName(), "LogFileNameTest", 15 ); +#endif + + x.SetTempDirectory( "/ABCDEFG/" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "/ABCDEFG/", 9 ); + #endif + + x.SetTempDirectory( "/ABCDEFG" ); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "\\ABCDEFG", 8 ); + #else + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "/ABCDEFG", 8 ); + #endif + + x.SetTempDirectory( "\\ABCDEFG\\"); + #ifdef WIN32 + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "\\ABCDEFG\\", 9 ); + #else + iRc += TestMethod( iPo, "Set/GetTempDirectory()", x.GetTempDirectory(), "/ABCDEFG/", 9 ); + #endif + + +// std::cout << "path separator = [" << x.GetPathSeparator() << "]\n"; + if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); |