std::vector<std::string> CTestSuite::GetTestList(std::set<std::string>& SuitesToRun, bool bIncludeChildren) { std::vector<std::string> test_list; if(GetParentSuite()!=NULL && SuitesToRun.size()!=0) { std::string sSuiteName; std::string sSuiteDescription; GetSuiteInfo(sSuiteName, sSuiteDescription); // Check if this suite's name is in list std::set<std::string>::iterator it = SuitesToRun.find(sSuiteName); if(it==SuitesToRun.end()) return test_list; // This suite is not in list } test_list.push_back("SetUp"); DoWithMyTests(GET_NAMES, test_list); if(bIncludeChildren) { UINT i; for(i=0; i<GetChildSuiteCount(); i++) { CTestSuite* pChildSuite = GetChildSuite(i); std::vector<std::string> child_test_list = pChildSuite->GetTestList(SuitesToRun, bIncludeChildren); UINT j; for(j=0; j<child_test_list.size(); j++) { test_list.push_back(child_test_list[j]); } } } test_list.push_back("TearDown"); return test_list; }
int _tmain(int argc, TCHAR** argv) { if(argc==1) { _tprintf(_T("\nDo you want to run tests from a folder containing Chinese characters to test UNICODE compatibility (y/n)?\n")); _tprintf(_T("Your choice > ")); TCHAR szAnswer[1024]=_T(""); #if _MSC_VER>=1400 _getts_s(szAnswer, 1024); #else _getts(szAnswer); #endif if(_tcscmp(szAnswer, _T("y"))==0 || _tcscmp(szAnswer, _T("Y"))==0) { // Relaunch this process from another working directory containing UNICODE symbols in path. // This is needed to test all functionality on UNICODE compatibility. g_bRunningFromUNICODEFolder = TRUE; } if(g_bRunningFromUNICODEFolder) { _tprintf(_T("Launching tests in another process:\n")); if(g_bRunningFromUNICODEFolder) _tprintf(_T(" - with working directory having UNICODE symbols in path\n")); return fork(); } } else { int argnum; for(argnum=1; argnum<argc; argnum++) { TCHAR* szArg = argv[argnum]; if(_tcscmp(szArg, _T("/unicode"))==0) g_bRunningFromUNICODEFolder = TRUE; } } printf("\n=== Automated tests for CrashRpt v.%d.%d.%d ===\n\n", CRASHRPT_VER/1000, (CRASHRPT_VER%1000)/100, (CRASHRPT_VER%1000)%100); CTestRegistry* pRegistry = CTestRegistry::GetRegistry(); CTestSuite* pTopSuite = pRegistry->GetTopSuite(); // Print the list of test suites printf("The list of avaliable test suites:\n"); UINT nSuiteCount = pTopSuite->GetChildSuiteCount(); UINT i; for(i=0; i<nSuiteCount; i++) { CTestSuite* pSuite = pTopSuite->GetChildSuite(i); std::string sSuiteName; std::string sDescription; pSuite->GetSuiteInfo(sSuiteName, sDescription); printf(" - %s : %s\n", sSuiteName.c_str(), sDescription.c_str()); } printf("\nEnter which test suites to run (separate names by space) or enter empty line to run all test suites.\n"); printf("Your choice > "); char szSuiteList[1024]=""; #if _MSC_VER>=1400 gets_s(szSuiteList, 1024); #else gets(szSuiteList); #endif // Create the list of test suites to run std::string sSuiteList = szSuiteList; std::vector<std::string> aTokens = explode(sSuiteList); std::set<std::string> aTestSuitesToRun; for(i=0; i<aTokens.size(); i++) aTestSuitesToRun.insert(aTokens[i]); // Determine how many tests to run std::vector<std::string> test_list = pTopSuite->GetTestList(aTestSuitesToRun, true); size_t nTestsToRun = test_list.size(); printf("\nRunning tests...\n"); DWORD dwStartTicks = GetTickCount(); pTopSuite->Run(aTestSuitesToRun); DWORD dwFinishTicks = GetTickCount(); double dTimeElapsed = (dwFinishTicks-dwStartTicks)/1000.0; printf("\n=== Summary ===\n\n"); // Print all errors (if exist) std::vector<std::string> error_list = pTopSuite->GetErrorList(true); if(error_list.size()>0) { printf("Error list:\n"); for(i=0; i<error_list.size(); i++) { printf("%d: %s\n", i+1, error_list[i].c_str()); } } printf("\n Time elapsed: %0.2f sec.\n", dTimeElapsed); printf(" Test count: %d\n", nTestsToRun); size_t nErrorCount = error_list.size(); printf(" Tests passed: %d\n", nTestsToRun-nErrorCount); printf(" Tests failed: %d\n", nErrorCount); // Wait for key press _getch(); // Return non-zero value if there were errors return nErrorCount==0?0:1; }