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-24 00:15:29 +00:00
|
|
|
#include "wsfs/adapter/impl/time/timepoint.h"
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-02-13 19:49:05 +00:00
|
|
|
using wsfs_test::msleep;
|
2019-02-09 18:02:53 +00:00
|
|
|
|
|
|
|
TEST(timepoint, now)
|
|
|
|
{
|
2019-03-24 02:25:29 +00:00
|
|
|
timepoint start = timepoint_now();
|
2019-02-13 19:49:05 +00:00
|
|
|
msleep(42);
|
2019-03-24 02:25:29 +00:00
|
|
|
timepoint end = 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-24 02:25:29 +00:00
|
|
|
timepoint now = timepoint_now();
|
|
|
|
timepoint later = timepoint_in_msec(42);
|
2019-02-09 18:02:53 +00:00
|
|
|
|
|
|
|
ASSERT_LT(now, later);
|
|
|
|
ASSERT_LT(later, now + 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(timepoint, elapsed)
|
|
|
|
{
|
2019-03-24 02:25:29 +00:00
|
|
|
timepoint now;
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-03-24 02:25:29 +00:00
|
|
|
now = timepoint_now();
|
|
|
|
ASSERT_TRUE(timepoint_is_elapsed(now - 1));
|
2019-02-09 18:02:53 +00:00
|
|
|
|
2019-03-24 02:25:29 +00:00
|
|
|
now = timepoint_now();
|
|
|
|
ASSERT_FALSE(timepoint_is_elapsed(now + 500));
|
2019-02-09 18:02:53 +00:00
|
|
|
}
|