view ext/UnitTest++/src/tests/TestTimeConstraint.cpp @ 214:a18f09b604f2

Added svn:eol-style on files that didn't already have that property. Affected file types: c, cpp, h, txt, py and xml.
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 17 Mar 2009 21:24:54 +0000
parents 0d325e9d5953
children
line wrap: on
line source

#include "../UnitTest++.h"
#include "../TestResults.h"
#include "../TimeHelpers.h"
#include "RecordingReporter.h"

using namespace UnitTest;

namespace
{

TEST(TimeConstraintSucceedsWithFastTest)
{
    TestResults result;
    {
        TimeConstraint t(200, result, TestDetails("", "", "", 0));
        TimeHelpers::SleepMs(5);
    }
    CHECK_EQUAL(0, result.GetFailureCount());
}

TEST(TimeConstraintFailsWithSlowTest)
{
    TestResults result;
    {
        TimeConstraint t(10, result, TestDetails("", "", "", 0));
        TimeHelpers::SleepMs(20);
    }
    CHECK_EQUAL(1, result.GetFailureCount());
}

TEST(TimeConstraintFailureIncludesCorrectData)
{
    RecordingReporter reporter;
    TestResults result(&reporter);
    {
        TestDetails const details("testname", "suitename", "filename", 10);
        TimeConstraint t(10, result, details);
        TimeHelpers::SleepMs(20);
    }
    CHECK(std::strstr(reporter.lastFailedFile, "filename"));
    CHECK_EQUAL(10, reporter.lastFailedLine);
    CHECK(std::strstr(reporter.lastFailedTest, "testname"));
}

TEST(TimeConstraintFailureIncludesTimeoutInformation)
{
    RecordingReporter reporter;
    TestResults result(&reporter);
    {
        TimeConstraint t(10, result, TestDetails("", "", "", 0));
        TimeHelpers::SleepMs(20);
    }
    CHECK(std::strstr(reporter.lastFailedMessage, "ime constraint"));
    CHECK(std::strstr(reporter.lastFailedMessage, "under 10ms"));
}

}