diff options
Diffstat (limited to 'src/tests/xb_test_lock.cpp')
-rwxr-xr-x | src/tests/xb_test_lock.cpp | 318 |
1 files changed, 255 insertions, 63 deletions
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 |