summaryrefslogtreecommitdiffstats
path: root/test/timer.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:36:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:36:56 +0000
commit51de1d8436100f725f3576aefa24a2bd2057bc28 (patch)
treec6d1d5264b6d40a8d7ca34129f36b7d61e188af3 /test/timer.c
parentInitial commit. (diff)
downloadmpv-51de1d8436100f725f3576aefa24a2bd2057bc28.tar.xz
mpv-51de1d8436100f725f3576aefa24a2bd2057bc28.zip
Adding upstream version 0.37.0.upstream/0.37.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/timer.c')
-rw-r--r--test/timer.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/timer.c b/test/timer.c
new file mode 100644
index 0000000..f85009c
--- /dev/null
+++ b/test/timer.c
@@ -0,0 +1,41 @@
+#include "common/common.h"
+#include "osdep/timer.h"
+#include "test_utils.h"
+
+#include <time.h>
+#include <sys/time.h>
+#include <limits.h>
+
+int main(void)
+{
+ mp_time_init();
+
+ /* timekeeping */
+ {
+ int64_t now = mp_time_ns();
+ assert_true(now > 0);
+
+ mp_sleep_ns(MP_TIME_MS_TO_NS(10));
+
+ int64_t now2 = mp_time_ns();
+ assert_true(now2 > now);
+
+ mp_sleep_ns(MP_TIME_MS_TO_NS(10));
+
+ double now3 = mp_time_sec();
+ assert_true(now3 > MP_TIME_NS_TO_S(now2));
+ }
+
+ /* arithmetic */
+ {
+ const int64_t test = 123456;
+ assert_int_equal(mp_time_ns_add(test, 1.0), test + MP_TIME_S_TO_NS(1));
+ assert_int_equal(mp_time_ns_add(test, DBL_MAX), INT64_MAX);
+ assert_int_equal(mp_time_ns_add(test, -1e13), 1);
+
+ const int64_t test2 = INT64_MAX - MP_TIME_S_TO_NS(20);
+ assert_int_equal(mp_time_ns_add(test2, 20.44), INT64_MAX);
+ }
+
+ return 0;
+}