TimeConstraint.cpp 665 B

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