1 #include "TimeConstraint.h" 2 #include "TestResults.h" 3 #include "MemoryOutStream.h" 4 #include "CurrentTest.h" 5 6 namespace UnitTest { 7 8 TimeConstraint(int ms,TestDetails const & details)9TimeConstraint::TimeConstraint(int ms, TestDetails const& details) 10 : m_details(details) 11 , m_maxMs(ms) 12 { 13 m_timer.Start(); 14 } 15 ~TimeConstraint()16TimeConstraint::~TimeConstraint() 17 { 18 double const totalTimeInMs = m_timer.GetTimeInMs(); 19 if (totalTimeInMs > m_maxMs) 20 { 21 MemoryOutStream stream; 22 stream << "Time constraint failed. Expected to run test under " << m_maxMs << 23 "ms but took " << totalTimeInMs << "ms."; 24 25 CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); 26 } 27 } 28 29 } 30