2020-03-29 15:40:33 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/timer/timepoint.h"
|
2020-03-29 15:40:33 +00:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
TEST(wf_timer_timepoint, now)
|
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_timer_timepoint start = wf_impl_timer_timepoint_now();
|
2020-03-29 15:40:33 +00:00
|
|
|
std::this_thread::sleep_for(42ms);
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_timer_timepoint end = wf_impl_timer_timepoint_now();
|
2020-03-29 15:40:33 +00:00
|
|
|
|
|
|
|
ASSERT_LT(start, end);
|
|
|
|
ASSERT_LT(end, start + 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_timer_timepoint, in_msec)
|
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_timer_timepoint now = wf_impl_timer_timepoint_now();
|
|
|
|
wf_timer_timepoint later = wf_impl_timer_timepoint_in_msec(42);
|
2020-03-29 15:40:33 +00:00
|
|
|
|
|
|
|
ASSERT_LT(now, later);
|
|
|
|
ASSERT_LT(later, now + 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_timer_timepoint, elapsed)
|
|
|
|
{
|
|
|
|
wf_timer_timepoint now;
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
now = wf_impl_timer_timepoint_now();
|
|
|
|
ASSERT_TRUE(wf_impl_timer_timepoint_is_elapsed(now - 1));
|
2020-03-29 15:40:33 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
now = wf_impl_timer_timepoint_now();
|
|
|
|
ASSERT_FALSE(wf_impl_timer_timepoint_is_elapsed(now + 500));
|
2020-03-29 15:40:33 +00:00
|
|
|
}
|