nucleo_f446re_playground/components/etl/test/UnitTest++/TimeConstraint.cpp
Attila Body 11c24647ea
git subrepo clone --branch=20.41.6 git@github.com:ETLCPP/etl.git components/etl
subrepo:
  subdir:   "components/etl"
  merged:   "be5537ec"
upstream:
  origin:   "git@github.com:ETLCPP/etl.git"
  branch:   "20.41.6"
  commit:   "be5537ec"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2025-06-11 11:25:49 +02:00

29 lines
721 B
C++

#include "TimeConstraint.h"
#include "TestResults.h"
#include "MemoryOutStream.h"
#include "CurrentTest.h"
namespace UnitTest {
TimeConstraint::TimeConstraint(int ms, TestDetails const& details, int lineNumber)
: m_details(details, lineNumber)
, m_maxMs(ms)
{
m_timer.Start();
}
TimeConstraint::~TimeConstraint()
{
double const totalTimeInMs = m_timer.GetTimeInMs();
if (totalTimeInMs > m_maxMs)
{
MemoryOutStream stream;
stream << "Time constraint failed. Expected to run test under " << m_maxMs <<
"ms but took " << totalTimeInMs << "ms.";
CurrentTest::Results()->OnTestFailure(m_details, stream.GetText());
}
}
}