2019-02-09 18:02:53 +00:00
|
|
|
#include <gtest/gtest.h>
|
2019-02-13 19:49:05 +00:00
|
|
|
|
|
|
|
#include "msleep.hpp"
|
2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/time/timepoint.h"
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
using webfuse_test::msleep;
|
2019-02-09 18:02:53 +00:00
|
|
|
|
|
|
|
TEST(timepoint, now)
|
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_timepoint start = wf_impl_timepoint_now();
|
2019-02-13 19:49:05 +00:00
|
|
|
msleep(42);
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_timepoint end = wf_impl_timepoint_now();
|
2019-02-09 18:02:53 +00:00
|
|
|
|
|
|
|
ASSERT_LT(start, end);
|
|
|
|
ASSERT_LT(end, start + 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(timepoint, in_msec)
|
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_timepoint now = wf_impl_timepoint_now();
|
|
|
|
wf_impl_timepoint later = wf_impl_timepoint_in_msec(42);
|
2019-02-09 18:02:53 +00:00
|
|
|
|
|
|
|
ASSERT_LT(now, later);
|
|
|
|
ASSERT_LT(later, now + 500);
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
TEST(wf_impl_timepoint, elapsed)
|
2019-02-09 18:02:53 +00:00
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_timepoint now;
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
now = wf_impl_timepoint_now();
|
|
|
|
ASSERT_TRUE(wf_impl_timepoint_is_elapsed(now - 1));
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
now =wf_impl_timepoint_now();
|
|
|
|
ASSERT_FALSE(wf_impl_timepoint_is_elapsed(now + 500));
|
2019-02-09 18:02:53 +00:00
|
|
|
}
|