mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-27 00:28:49 +03:00
Add UNITTEST_CYGWIN directive and use it to: include Posix/TimeHelpers.h for Cygwin, exclude the signal handling in SignalTranslator.h/.cpp as Cygwin does not have the necessary Posix signal handling support, i.e. sigjmp_buf or siglongjmp. Reimplement SleepMs in TimeHelpers.cpp using C++11 rather than usleep as that is not present on Cygwin. Update CMakeLists.txt to exclude SignalTranslator.h/.cpp from the build.
35 lines
693 B
C++
35 lines
693 B
C++
#include "TimeHelpers.h"
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <unistd.h>
|
|
|
|
namespace UnitTest {
|
|
|
|
Timer::Timer()
|
|
{
|
|
m_startTime.tv_sec = 0;
|
|
m_startTime.tv_usec = 0;
|
|
}
|
|
|
|
void Timer::Start()
|
|
{
|
|
gettimeofday(&m_startTime, 0);
|
|
}
|
|
|
|
double Timer::GetTimeInMs() const
|
|
{
|
|
struct timeval currentTime;
|
|
gettimeofday(¤tTime, 0);
|
|
|
|
double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
|
|
double const dus = currentTime.tv_usec - m_startTime.tv_usec;
|
|
|
|
return (dsecs * 1000.0) + (dus / 1000.0);
|
|
}
|
|
|
|
void TimeHelpers::SleepMs(int ms)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::microseconds(ms * 1000));
|
|
}
|
|
|
|
}
|