1*2f083884Ss.makeev_local #include "UnitTest++/UnitTestPP.h"
2*2f083884Ss.makeev_local #include "UnitTest++/TimeHelpers.h"
3*2f083884Ss.makeev_local
4*2f083884Ss.makeev_local #include "RecordingReporter.h"
5*2f083884Ss.makeev_local #include "ScopedCurrentTest.h"
6*2f083884Ss.makeev_local
7*2f083884Ss.makeev_local namespace {
8*2f083884Ss.makeev_local
TEST(TimeConstraintMacroQualifiesNamespace)9*2f083884Ss.makeev_local TEST(TimeConstraintMacroQualifiesNamespace)
10*2f083884Ss.makeev_local {
11*2f083884Ss.makeev_local // If this compiles without a "using namespace UnitTest;", all is well.
12*2f083884Ss.makeev_local UNITTEST_TIME_CONSTRAINT(1);
13*2f083884Ss.makeev_local }
14*2f083884Ss.makeev_local
TEST(TimeConstraintMacroUsesCorrectInfo)15*2f083884Ss.makeev_local TEST(TimeConstraintMacroUsesCorrectInfo)
16*2f083884Ss.makeev_local {
17*2f083884Ss.makeev_local int testLine = 0;
18*2f083884Ss.makeev_local RecordingReporter reporter;
19*2f083884Ss.makeev_local
20*2f083884Ss.makeev_local {
21*2f083884Ss.makeev_local UnitTest::TestResults testResults(&reporter);
22*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults);
23*2f083884Ss.makeev_local
24*2f083884Ss.makeev_local UNITTEST_TIME_CONSTRAINT(10); testLine = __LINE__;
25*2f083884Ss.makeev_local UnitTest::TimeHelpers::SleepMs(20);
26*2f083884Ss.makeev_local }
27*2f083884Ss.makeev_local
28*2f083884Ss.makeev_local using namespace std;
29*2f083884Ss.makeev_local
30*2f083884Ss.makeev_local CHECK_EQUAL(1, reporter.testFailedCount);
31*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedFile, __FILE__));
32*2f083884Ss.makeev_local CHECK_EQUAL(testLine, reporter.lastFailedLine);
33*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroUsesCorrectInfo"));
34*2f083884Ss.makeev_local }
35*2f083884Ss.makeev_local
TEST(TimeConstraintMacroComparesAgainstPreciseActual)36*2f083884Ss.makeev_local TEST(TimeConstraintMacroComparesAgainstPreciseActual)
37*2f083884Ss.makeev_local {
38*2f083884Ss.makeev_local int testLine = 0;
39*2f083884Ss.makeev_local RecordingReporter reporter;
40*2f083884Ss.makeev_local
41*2f083884Ss.makeev_local {
42*2f083884Ss.makeev_local UnitTest::TestResults testResults(&reporter);
43*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults);
44*2f083884Ss.makeev_local
45*2f083884Ss.makeev_local UNITTEST_TIME_CONSTRAINT(1); testLine = __LINE__;
46*2f083884Ss.makeev_local
47*2f083884Ss.makeev_local // start a new timer and run until we're as little over the 1 msec
48*2f083884Ss.makeev_local // threshold as we can achieve; this should guarantee that the "test"
49*2f083884Ss.makeev_local // runs in some very small amount of time > 1 msec
50*2f083884Ss.makeev_local UnitTest::Timer myTimer;
51*2f083884Ss.makeev_local myTimer.Start();
52*2f083884Ss.makeev_local
53*2f083884Ss.makeev_local while (myTimer.GetTimeInMs() < 1.001)
54*2f083884Ss.makeev_local UnitTest::TimeHelpers::SleepMs(0);
55*2f083884Ss.makeev_local }
56*2f083884Ss.makeev_local
57*2f083884Ss.makeev_local using namespace std;
58*2f083884Ss.makeev_local
59*2f083884Ss.makeev_local CHECK_EQUAL(1, reporter.testFailedCount);
60*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedFile, __FILE__));
61*2f083884Ss.makeev_local CHECK_EQUAL(testLine, reporter.lastFailedLine);
62*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroComparesAgainstPreciseActual"));
63*2f083884Ss.makeev_local }
64*2f083884Ss.makeev_local
65*2f083884Ss.makeev_local struct EmptyFixture {};
66*2f083884Ss.makeev_local
TEST_FIXTURE(EmptyFixture,TimeConstraintMacroWorksInFixtures)67*2f083884Ss.makeev_local TEST_FIXTURE(EmptyFixture, TimeConstraintMacroWorksInFixtures)
68*2f083884Ss.makeev_local {
69*2f083884Ss.makeev_local int testLine = 0;
70*2f083884Ss.makeev_local RecordingReporter reporter;
71*2f083884Ss.makeev_local
72*2f083884Ss.makeev_local {
73*2f083884Ss.makeev_local UnitTest::TestResults testResults(&reporter);
74*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults);
75*2f083884Ss.makeev_local
76*2f083884Ss.makeev_local UNITTEST_TIME_CONSTRAINT(10); testLine = __LINE__;
77*2f083884Ss.makeev_local UnitTest::TimeHelpers::SleepMs(20);
78*2f083884Ss.makeev_local }
79*2f083884Ss.makeev_local
80*2f083884Ss.makeev_local using namespace std;
81*2f083884Ss.makeev_local
82*2f083884Ss.makeev_local CHECK_EQUAL(1, reporter.testFailedCount);
83*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedFile, __FILE__));
84*2f083884Ss.makeev_local CHECK_EQUAL(testLine, reporter.lastFailedLine);
85*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroWorksInFixtures"));
86*2f083884Ss.makeev_local }
87*2f083884Ss.makeev_local
88*2f083884Ss.makeev_local }
89