diff options
Diffstat (limited to 'toxcore/mono_time_test.cc')
-rw-r--r-- | toxcore/mono_time_test.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/toxcore/mono_time_test.cc b/toxcore/mono_time_test.cc index 4ed59406..6e81ac7e 100644 --- a/toxcore/mono_time_test.cc +++ b/toxcore/mono_time_test.cc | |||
@@ -35,4 +35,28 @@ TEST(MonoTime, IsTimeout) { | |||
35 | mono_time_free(mono_time); | 35 | mono_time_free(mono_time); |
36 | } | 36 | } |
37 | 37 | ||
38 | static uint64_t test_current_time_callback(void *user_data) { return *(uint64_t *)user_data; } | ||
39 | |||
40 | TEST(MonoTime, CustomTime) { | ||
41 | Mono_Time *mono_time = mono_time_new(); | ||
42 | |||
43 | uint64_t test_time = current_time_monotonic(mono_time) + 42137; | ||
44 | |||
45 | mono_time_set_current_time_callback(mono_time, test_current_time_callback, &test_time); | ||
46 | mono_time_update(mono_time); | ||
47 | |||
48 | EXPECT_EQ(current_time_monotonic(mono_time), test_time); | ||
49 | |||
50 | uint64_t const start = mono_time_get(mono_time); | ||
51 | |||
52 | test_time += 7000; | ||
53 | |||
54 | mono_time_update(mono_time); | ||
55 | EXPECT_EQ(mono_time_get(mono_time) - start, 7); | ||
56 | |||
57 | EXPECT_EQ(current_time_monotonic(mono_time), test_time); | ||
58 | |||
59 | mono_time_free(mono_time); | ||
60 | } | ||
61 | |||
38 | } // namespace | 62 | } // namespace |