//------------------------------------------------------------------------- // // Microsoft OLE // Copyright (C) Microsoft Corporation, 1994 - 1995. // // File: init.cxx // // Contents: OLE storage base tests // // Functions: main // ProcessCmdLine // RunAllTests // RunSingleTest // RunAllCOMTests // RunSingleCOMTest // RunAllDFTests // RunSingleDFTest // RunAllAPITests // RunSingleAPITest // RunAllROOTTests // RunSingleROOTTest // RunAllSTMTests // RunSingleSTMTest // RunAllSTGTests // RunSingleSTGTest // RunAllVCPYTests // RunSingleVCPYTest // RunAllIVCPYTests // RunSingleIVCPYTest // RunAllENUMTests // RunSingleENUMTest // RunAllIROOTSTGTests // RunSingleIROOTSTGTest // RunAllHGLOBALTests // RunSingleHGLOBALTest // RunAllSNBTests // RunSingleSNBTest // RunAllMISCTests // RunSingleMISCTest // RunAllILKBTests // RunSingleILKBTest // RunAllFlatTests // RunSingleFlatTest // // History: 20-May-1996 NarindK Created. // //-------------------------------------------------------------------------- #include #pragma hdrstop #include "init.hxx" void CheckCurrentDirectory (int argc, char *argv[]); HRESULT ProcessCmdLine(int argc, char *argv[]) ; HRESULT RunSingleTest(char *pszTestName, int argc, char *argv[]) ; HRESULT RunAllTests(int argc, char *argv[]) ; HRESULT RunAllCOMTests(int argc, char *argv[]); HRESULT RunAllDFTests(int argc, char *argv[]); HRESULT RunAllAPITests(int argc, char *argv[]); HRESULT RunAllROOTTests(int argc, char *argv[]); HRESULT RunAllSTMTests(int argc, char *argv[]); HRESULT RunAllSTGTests(int argc, char *argv[]); HRESULT RunAllVCPYTests(int argc, char *argv[]); HRESULT RunAllIVCPYTests(int argc, char *argv[]); HRESULT RunAllENUMTests(int argc, char *argv[]); HRESULT RunAllIROOTSTGTests(int argc, char *argv[]); HRESULT RunAllHGLOBALTests(int argc, char *argv[]); HRESULT RunAllSNBTests(int argc, char *argv[]); HRESULT RunAllMISCTests(int argc, char *argv[]); HRESULT RunAllILKBTests(int argc, char *argv[]); HRESULT RunAllFlatTests(int argc, char *argv[]); HRESULT RunSingleCOMTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleDFTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleAPITest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleROOTTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleSTMTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleSTGTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleVCPYTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleIVCPYTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleENUMTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleIROOTSTGTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleHGLOBALTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleSNBTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleMISCTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleILKBTest(LONG lTestNum, int argc, char *argv[]); HRESULT RunSingleFlatTest(LONG lTestNum, int argc, char *argv[]); // Debug object DH_DEFINE ; // Logs: The log file would be stgbase.log #define LOG_FILE_NAME "/t:stgbase" // Misc BOOL g_fDebugMode = FALSE ; BOOL g_fFirstFailureExits = FALSE ; BOOL g_fDebugBreakAtTestStart = FALSE ; BOOL g_fRunAllMode = FALSE ; BOOL g_fDoLargeSeekAndWrite = FALSE; BOOL g_fUseStdBlk = FALSE ; BOOL g_fRevert = FALSE; BOOL g_fDeleteTestDF = TRUE; UINT g_uOpenCreateDF = FL_DISTRIB_NONE; // Help text LPCTSTR lptszStgbaseUsage = { TEXT("StgBase command line options:\n") TEXT(" /t:{testname} - Run {testname} Test\n") TEXT(" /FFX - First Failure Exits\n") TEXT(" /BTS - Break at Test Start\n") TEXT(" /DM - Debug Mode\n") TEXT(" /stdblock - Use std block sizes\n") TEXT(" /lgseekwrite - Do large seek and write\n") TEXT(" /revert - Do revert instead of commit\n") TEXT(" /CWD:cwd - Make cwd Current Directory\n") }; //+------------------------------------------------------------------- // Function: main // // Synopsis: main for stgbase test suite // // Arguments: [argc] // [argv] // // Returns: -1 if main fails // // History: 20-May-1996 NarindK Created //-------------------------------------------------------------------- #ifdef _MAC int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc; char **argv; // the pointer is used for retrieving the command line // from the Arguments file on Mac LPSTR lpszCmdLine = NULL; int count; #else int __cdecl main(int argc, char *argv[]) { #endif // _MAC HRESULT hr = S_OK; // Check if we should change CurrentDirectory, before creating the logfile CheckCurrentDirectory (argc, argv); // Initialize our log object DH_CREATELOGCMDLINE( LOG_FILE_NAME ); hr = InitializeDebugObject(); DH_ASSERT( S_OK == hr); if (DH_GETLOGLOC == DH_LOC_TERM) { DH_SETLOGLOC( DH_LOC_TERM | DH_LOC_LOG) ; } if (DH_GETTRACELOC == DH_LOC_TERM) { DH_SETTRACELOC( DH_LOC_TERM | DH_LOC_LOG) ; } // ProcessCmdLine() will run all the tests we // need to run... if (S_OK == hr) { #ifdef _MAC lpszCmdLine = GetCommandLine(); if(lpszCmdLine == NULL) { hr = E_FAIL; DH_LOG((LOG_INFO, TEXT("Failed to get the command line.\r")) ) ; } if(S_OK == hr) { hr = CmdlineToArgs(lpszCmdLine, &argc, &argv); } #endif //_MAC // init our StgAPI wrapper - to determine whether we want to call // StgAPIs or StgExAPIs for open/create. StgInitStgFormatWrapper (argc, argv); if(S_OK == hr) { hr = ProcessCmdLine(argc, argv) ; } } // Log our stats regarding how many tests passed, failed // aborted, etc, etc. DH_LOGSTATS ; // BUGBUG: The following code that has been commented out reads from a // test.ini file and runs different tests as specified there. /* { int targc = 0; char **targv = NULL; ULONG i = 0; char buffer[256]; char testName[20]; for (;;) { sprintf (testName, "Test%lu", i); i++; GetPrivateProfileStringA( "MyTests", testName, "Fail", buffer, sizeof(buffer), "test.ini" ); if(0 == strcmp(buffer, "EndTest")) { break; } hr = CmdlineToArgs(buffer, &targc, &targv) ; if(S_OK == hr) { hr = RunTest(targc, targv); } // CmdlineToArgs allocates a bunch of strings and a table of // pointers to them, so we need to free them. if (NULL != targv) { for (i=0; i= TCHAR('A') && *ptr <= TCHAR('Z')) { // c: -> 0x4, d: -> 0x8, e: -> 0x10 ulDriveMap = ulDriveMap | (0x01 << (*ptr-TCHAR('C'))); DH_TRACE ((DH_LVL_TRACE4, TEXT("Processed drive %C:"), *ptr)); } ptr = _tcstok (NULL, TEXT(";,")); } } // if /altpath: not found, enum local disks and use them all. if (0 == ulDriveMap) { DH_TRACE ((DH_LVL_TRACE4, TEXT("Enumerating local drives"))); ulDriveMap = EnumLocalDrives()>>2; //ignore A:, B: } DH_TRACE ((DH_LVL_TRACE4, TEXT("Drive map : %#x"), ulDriveMap)); while (ulDriveMap) { if (ulDriveMap & 0x01) { DH_TRACE ((DH_LVL_TRACE4, TEXT("Testing to:%s"), szDrive)); hrTest = (*pfnTestFunc)(argc, argv, szDrive); hr = FirstError (hr, hrTest); } ++*szDrive; ulDriveMap = ulDriveMap>>1; } // cleanup delete []ptAltPath; // return an error if any of the tests failed. return hr; } //+------------------------------------------------------------------- // Function: ProcessCmdLine // // Synopsis: Analyzes the command line and takes appropriate action // depending on what is there. // // Arguments: [argc] // [argv] - The command line argument list. Valid switches // are: // // 1. /T:{string defining test num} // // For test num strings, see // %ctolestg%\docs // // If no /T: switches are on the command // line, all the tests are run. // // An unlimited number of tests can be // specified on the command line using // the /t: switches // // 2. /BTS - Break when each test starts // // 3. /DM - Debug mode. In debug mode, the // test DLL provides more debugging // information than normal about the // state of the tests. // // 4. /FFX - First test failure exits the test // suite // // 5. /stdblock - If standard block sizes from // array ausSIZE_ARRAY needs to be // used for test. // // 6. /lgseekwrite - if large seek and write needs // to be done in test. // // 7. /revert - Do revert operation in tests // instead of commit, if flag set. // // NOTE: For OTHER valid switches, please // see documentation. // // Returns: S_OK if the function succeeds, another HRESULT otherwise // // History: 20-May-1996 NarindK Enhanced for stgbase test suite // //-------------------------------------------------------------------- HRESULT ProcessCmdLine(int argc, char *argv[]) { HRESULT hr = S_OK ; INT i = 0; INT cTestsRun = 0 ; INT cParseErrors= 0 ; int targc = 0; char **targv = NULL; // // If we are running on DEBUG OLE, set the debug flag to TRUE // if (S_OK == RunningDebugOle()) { g_fDebugMode = TRUE ; } // // First, check for any switches // if (S_OK == hr) { CBoolCmdlineObj Cbts (OLESTR("BTS"), OLESTR(""), OLESTR("FALSE")) ; CBoolCmdlineObj Cffx (OLESTR("FFX"), OLESTR(""), OLESTR("FALSE")) ; CBoolCmdlineObj Cdm (OLESTR("DM"), OLESTR(""), OLESTR("FALSE")) ; CBoolCmdlineObj Chlp (OLESTR("HELP"), OLESTR("get help"), OLESTR("FALSE")) ; CBoolCmdlineObj Chelp (OLESTR("?"), OLESTR("get help"), OLESTR("FALSE")) ; CBoolCmdlineObj Cstdblk (OLESTR("stdblock"), OLESTR(""), OLESTR("FALSE")) ; CBoolCmdlineObj Clgseekwrite(OLESTR("lgseekwrite"),OLESTR(""), OLESTR("FALSE")) ; CBoolCmdlineObj Crevert (OLESTR("revert"), OLESTR(""), OLESTR("FALSE")) ; CBaseCmdlineObj COpenDF (OLESTR("Distrib"), OLESTR("Distributed tests. Create/Open docfile"), OLESTR("none")); // these are checked and dealt with in chancedf. look here so we can // put some meaningful useful information into the log CBaseCmdlineObj Cmode (OLESTR("dfRootMode"), OLESTR("Direct, Transacted modes"), OLESTR("none")); CBaseCmdlineObj Ctest (OLESTR("t"), OLESTR("Test name"), OLESTR("none")); CBaseCmdlineObj *CArgList[] = { &Cmode, // just for spewage &Ctest, // just for spewage &COpenDF, // 2 phase testing (conversion over redirector) &Cbts, // Break at test start &Cffx, // Break at first failure &Cdm, // Debug mode &Chlp, // Help &Chelp, // display help? &Cstdblk, // Standard block size &Clgseekwrite, // Do large seek and write &Crevert // Revert instead of committing } ; CCmdline CCmdlineArgs(argc, argv); if (CMDLINE_NO_ERROR != CCmdlineArgs.QueryError()) { hr = E_FAIL ; } if (S_OK == hr) { if (CMDLINE_NO_ERROR != CCmdlineArgs.Parse( CArgList, ( sizeof(CArgList) / sizeof(CArgList[0]) ), FALSE)) { hr = E_FAIL ; } if (S_OK == hr) { g_fDebugBreakAtTestStart = *(Cbts.GetValue()) ; g_fFirstFailureExits = *(Cffx.GetValue()) ; g_fDebugMode = FALSE; if (FALSE != *(Cdm.GetValue())) { g_fDebugMode = TRUE ; } if (TRUE == Chelp.IsFound() || TRUE == Chlp.IsFound()) { // Help switch // We are a console app. Dump to stdout. // and debug window for good measure. _tprintf (TEXT("%s\r\n"), lptszStgbaseUsage); OutputDebugString ((LPTSTR)lptszStgbaseUsage); _tprintf (TEXT("%s"), GetDebugHelperUsage()); OutputDebugString ((LPTSTR)GetDebugHelperUsage()); // // If someone asked for help, don't run any // of the tests // hr = S_FALSE ; } g_fUseStdBlk = FALSE; if (FALSE != *(Cstdblk.GetValue())) { g_fUseStdBlk = TRUE ; } g_fDoLargeSeekAndWrite = FALSE; if (FALSE != *(Clgseekwrite.GetValue())) { g_fDoLargeSeekAndWrite = TRUE ; } g_fRevert = FALSE; if (FALSE != *(Crevert.GetValue())) { g_fRevert = TRUE ; } g_uOpenCreateDF = FL_DISTRIB_NONE; g_fDeleteTestDF = TRUE; if (TRUE == COpenDF.IsFound ()) { if (NULL == _olestricmp (COpenDF.GetValue (), OLESTR(SZ_DISTRIB_OPEN))) { g_uOpenCreateDF = FL_DISTRIB_OPEN; } else if (NULL == _olestricmp (COpenDF.GetValue (), OLESTR(SZ_DISTRIB_OPENNODELETE))) { g_uOpenCreateDF = FL_DISTRIB_OPEN; g_fDeleteTestDF = FALSE; } else if (NULL ==_olestricmp (COpenDF.GetValue (), OLESTR(SZ_DISTRIB_CREATE))) { g_uOpenCreateDF = FL_DISTRIB_CREATE; } } #ifdef UNICODE //dont bother with OleStringToTString if TString is ansi. // for spewage only if (TRUE == Ctest.IsFound () && TRUE == Cmode.IsFound ()) { DH_TRACE ((DH_LVL_ALWAYS, TEXT("Running %s in %s mode"), Ctest.GetValue(), Cmode.GetValue())); } #endif } } } // // Start up the tests // targc = argc; targv = argv; if (S_OK == hr) { for (i=0; i