diff options
author | zugz (tox) <mbays+tox@sdf.org> | 2018-08-17 19:22:58 +0200 |
---|---|---|
committer | zugz (tox) <mbays+tox@sdf.org> | 2018-08-26 22:05:37 +0200 |
commit | 01e2cc55cbb5fd0d89d7624124674307266ef4ee (patch) | |
tree | 390fa1e029f86f266f4f017659cc78cdedfa1216 /toxcore/mono_time_test.cc | |
parent | acc19a202faad8fb6cbc576b8f4d906ee80e6e16 (diff) |
Add support for setting a custom monotonic time function in mono_time
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 |