コード例 #1
0
int RunAllTests(TestReporter& reporter, TestList const& list, int const maxTestTimeInMs )
{
    TestResults result(&reporter);

    Timer overallTimer;
    overallTimer.Start();

    Test const* curTest = list.GetHead();
    while (curTest != 0)
    {
        Timer testTimer;
        testTimer.Start();
        result.OnTestStart(curTest->m_testName);

        curTest->Run(result);

        int const testTimeInMs = testTimer.GetTimeInMs();
        if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs)
        {
            MemoryOutStream stream;
            stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
                      "ms but took " << testTimeInMs << "ms.";
            result.OnTestFailure(curTest->m_filename, curTest->m_lineNumber,
                                 curTest->m_testName, stream.GetText());
        }
        result.OnTestFinish(curTest->m_testName, testTimeInMs/1000.0f);

        curTest = curTest->next;
    }

    float const secondsElapsed = overallTimer.GetTimeInMs() / 1000.0f;
    reporter.ReportSummary(result.GetTestCount(), result.GetFailureCount(), secondsElapsed);

    return result.GetFailureCount();
}
コード例 #2
0
ファイル: TestRunner.cpp プロジェクト: fatman2021/sharm
int RunAllTests(TestReporter& reporter, TestList const& list, char const* suiteName, int const maxTestTimeInMs )
{
    TestResults result(&reporter);

    Timer overallTimer;
    overallTimer.Start();

    Test const* curTest = list.GetHead();
    while (curTest != 0)
    {
        if (suiteName == 0 || !std::strcmp(curTest->m_details.suiteName, suiteName))
        {
            Timer testTimer;
            testTimer.Start();
            result.OnTestStart(curTest->m_details);

            curTest->Run(result);

            int const testTimeInMs = testTimer.GetTimeInMs();
            if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt)
            {
                MemoryOutStream stream;
                stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
                       "ms but took " << testTimeInMs << "ms.";
                result.OnTestFailure(curTest->m_details, stream.GetText());
            }
            result.OnTestFinish(curTest->m_details, (float)testTimeInMs);
        }

        curTest = curTest->next;
    }

    float const secondsElapsed = overallTimer.GetTimeInMs() / 1000.0f;
    reporter.ReportSummary(result.GetTotalTestCount(), result.GetFailedTestCount(), result.GetFailureCount(), secondsElapsed);

    return result.GetFailureCount();
}