Exemple #1
0
void TestSuite::run_suite(
    const IFilter&      filter,
    ITestListener&      test_listener,
    TestResult&         test_suite_result,
    TestResult&         cumulated_result) const
{
    TestResult local_cumulated_result(cumulated_result);
    local_cumulated_result.merge(test_suite_result);

    bool has_begun_suite = false;

    for (size_t i = 0; i < impl->m_factories.size(); ++i)
    {
        ITestCaseFactory& factory = *impl->m_factories[i];

        // Skip test cases that aren't let through by the filter.
        if (!filter.accepts(factory.get_name()))
            continue;

        if (!has_begun_suite)
        {
            // Tell the listener that a test suite is about to be executed.
            test_listener.begin_suite(*this);
            test_suite_result.signal_suite_execution();
            has_begun_suite = true;
        }

        // Tell the listener that a test case is about to be executed.
        test_listener.begin_case(*this, factory.get_name());

        // Instantiate and run the test case.
        TestResult test_case_result;
        run_case(factory, test_listener, test_case_result);

        // Accumulate the test results.
        test_suite_result.merge(test_case_result);
        local_cumulated_result.merge(test_case_result);

        // Tell the listener that the test case execution has ended.
        test_listener.end_case(
            *this,
            factory.get_name(),
            test_suite_result,
            test_case_result,
            local_cumulated_result);
    }

    if (has_begun_suite)
    {
        // Report a test suite failure if one or more test cases failed.
        if (test_suite_result.get_case_failure_count() > 0)
            test_suite_result.signal_suite_failure();

        // Tell the listener that the test suite execution has ended.
        test_listener.end_suite(
            *this,
            test_suite_result,
            cumulated_result);
    }
}