aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-19 11:58:03 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-19 11:58:03 +0300
commitc499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc (patch)
tree5ec5eaeb3eb951f65715aa62a043c6ae7eac7854 /test
parentef5cc380045bba05acfcba7d0e1c03046fdc82d0 (diff)
downloadlibrin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.tar.gz
librin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.tar.bz2
librin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.zip
time: add a generalized time comparison function.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'test')
-rw-r--r--test/time.c20
-rw-r--r--test/time_test_private.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/test/time.c b/test/time.c
index 4307fd1..017597b 100644
--- a/test/time.c
+++ b/test/time.c
@@ -27,6 +27,7 @@ int time_test(char *testname)
{"add", rin_time_add_test},
{"sub", rin_time_sub_test},
{"normalize", rin_time_normalize_test},
+ {"cmp", rin_time_cmp_test},
{"cmpless", rin_time_cmpless_test},
{"cmpmore", rin_time_cmpmore_test},
{"cmplessequal", rin_time_cmplessequal_test},
@@ -111,6 +112,25 @@ static int rin_time_normalize_test(void)
return ret;
}
+static int rin_time_cmp_test(void)
+{
+ int ret;
+ size_t i;
+ static const struct timespec in_a[] = { {187, 100}, {1, 100}, {1, 200}, {1, 100}, {9, 10}, {3, 100}, {4, 101}, {0, 0} };
+ static const struct timespec in_b[] = { {187, 100}, {0, 100}, {1, 200}, {1, 200}, {10, 10}, {4, 101}, {3, 100}, {0, 0} };
+ static const long int expected[] = {0, 1, 0, -100, -1, -1, 1, 0};
+
+ for (i = 0; i < arrlen(expected); ++i) {
+ ret = ok(rin_time_cmp(in_a + i, in_b + i) != expected[i],
+ "%s: expected: %li, got: %li",
+ __func__,
+ expected[i],
+ rin_time_cmp(in_a + i, in_b + i));
+ }
+
+ return ret;
+}
+
static int rin_time_cmpless_test(void)
{
int ret;
diff --git a/test/time_test_private.h b/test/time_test_private.h
index 9afbda2..c7d505c 100644
--- a/test/time_test_private.h
+++ b/test/time_test_private.h
@@ -26,6 +26,7 @@
static int rin_time_add_test(void);
static int rin_time_sub_test(void);
static int rin_time_normalize_test(void);
+static int rin_time_cmp_test(void);
static int rin_time_cmpless_test(void);
static int rin_time_cmpmore_test(void);
static int rin_time_cmplessequal_test(void);