From abc17b0f8997ab07ae66130edd5dc8c43e72c886 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 8 Jul 2018 08:43:42 +0000 Subject: Factor out time keeping code into its own module: mono_time.c. It turns out, `unix_time` is also monotonic, and is used as such, so I've renamed the new functions to `mono_time_*`. 2018-07-08: ``` 00:01 <@irungentoo> the idea used to be that the unix_time() function could go backward in time but I think I might have started using it like if it could not after I changed it so that it would never go back in time ``` --- toxcore/mono_time_test.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 toxcore/mono_time_test.cc (limited to 'toxcore/mono_time_test.cc') diff --git a/toxcore/mono_time_test.cc b/toxcore/mono_time_test.cc new file mode 100644 index 00000000..5ad91322 --- /dev/null +++ b/toxcore/mono_time_test.cc @@ -0,0 +1,30 @@ +#include "mono_time.h" + +#include + +namespace { + +TEST(Util, UnixTimeIncreasesOverTime) { + unix_time_update(); + uint64_t const start = unix_time(); + + while (start == unix_time()) { + unix_time_update(); + } + + uint64_t const end = unix_time(); + EXPECT_GT(end, start); +} + +TEST(Util, IsTimeout) { + uint64_t const start = unix_time(); + EXPECT_FALSE(is_timeout(start, 1)); + + while (start == unix_time()) { + unix_time_update(); + } + + EXPECT_TRUE(is_timeout(start, 1)); +} + +} // namespace -- cgit v1.2.3