42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include "TestCommon.h"
|
|
#include <thread>
|
|
std::shared_ptr<ITestCommon> &ITestCommon::GetInstance(std::shared_ptr<ITestCommon> *impl)
|
|
{
|
|
static auto instance = std::make_shared<ITestCommon>();
|
|
if (impl)
|
|
{
|
|
/**
|
|
* @brief
|
|
* The non-thread-safe changing is only for gtest.
|
|
*/
|
|
instance = *impl;
|
|
}
|
|
return instance;
|
|
}
|
|
void ITestCommon::IUsleep(unsigned long timeMs)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(timeMs));
|
|
}
|
|
void ITestCommon::WaitForTestFinish(unsigned int waitingTimeOut, bool (*ifFinished)(void *ctx), void *ctx)
|
|
{
|
|
if (!ifFinished)
|
|
{
|
|
LogError("ifFinished is nullptr.\n");
|
|
return;
|
|
}
|
|
unsigned long int waitingTime = 0;
|
|
while (1)
|
|
{
|
|
constexpr int WAITING_FOR_GET_DATA = 100;
|
|
if (ifFinished(ctx))
|
|
{
|
|
break;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(WAITING_FOR_GET_DATA));
|
|
waitingTime += WAITING_FOR_GET_DATA;
|
|
if (waitingTime >= waitingTimeOut)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
} |