Exemplo n.º 1
0
std::vector<std::string> CTestSuite::GetErrorList(bool bIncludeChildren)
{
    std::vector<std::string> asErrors = m_asErrorMsg;

    if(bIncludeChildren)
    {
        UINT i;
        for(i=0; i<GetChildSuiteCount(); i++)
        {
            CTestSuite* pChildSuite = GetChildSuite(i);
            std::vector<std::string> asChildErrors = pChildSuite->GetErrorList(bIncludeChildren);

            UINT j;
            for(j=0; j<asChildErrors.size(); j++)
            {
                asErrors.push_back(asChildErrors[j]);
            }
        }
    }

    return asErrors;
}
Exemplo n.º 2
0
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;
}