diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-08 08:43:42 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-09 21:04:50 +0000 |
commit | abc17b0f8997ab07ae66130edd5dc8c43e72c886 (patch) | |
tree | 88056839c808a9f7f8c58f55ebe273aa7b5facdb /toxcore/util_test.cc | |
parent | 4e21c065517d6e125cb1d1b9a13e886b3046b0d8 (diff) |
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
```
Diffstat (limited to 'toxcore/util_test.cc')
-rw-r--r-- | toxcore/util_test.cc | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/toxcore/util_test.cc b/toxcore/util_test.cc index 541aa61f..ff57f3fb 100644 --- a/toxcore/util_test.cc +++ b/toxcore/util_test.cc | |||
@@ -4,28 +4,7 @@ | |||
4 | 4 | ||
5 | #include <gtest/gtest.h> | 5 | #include <gtest/gtest.h> |
6 | 6 | ||
7 | TEST(Util, UnixTimeIncreasesOverTime) { | 7 | namespace { |
8 | unix_time_update(); | ||
9 | uint64_t const start = unix_time(); | ||
10 | |||
11 | while (start == unix_time()) { | ||
12 | unix_time_update(); | ||
13 | } | ||
14 | |||
15 | uint64_t const end = unix_time(); | ||
16 | EXPECT_GT(end, start); | ||
17 | } | ||
18 | |||
19 | TEST(Util, IsTimeout) { | ||
20 | uint64_t const start = unix_time(); | ||
21 | EXPECT_FALSE(is_timeout(start, 1)); | ||
22 | |||
23 | while (start == unix_time()) { | ||
24 | unix_time_update(); | ||
25 | } | ||
26 | |||
27 | EXPECT_TRUE(is_timeout(start, 1)); | ||
28 | } | ||
29 | 8 | ||
30 | TEST(Util, TwoRandomIdsAreNotEqual) { | 9 | TEST(Util, TwoRandomIdsAreNotEqual) { |
31 | uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE]; | 10 | uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE]; |
@@ -49,3 +28,5 @@ TEST(Util, IdCopyMakesKeysEqual) { | |||
49 | 28 | ||
50 | EXPECT_TRUE(id_equal(pk1, pk2)); | 29 | EXPECT_TRUE(id_equal(pk1, pk2)); |
51 | } | 30 | } |
31 | |||
32 | } // namespace | ||