summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetr Špaček <petr.spacek@nic.cz>2019-01-02 14:56:53 +0100
committerPetr Špaček <petr.spacek@nic.cz>2019-01-09 15:14:53 +0100
commitc487ecb5a3469b46e08e97c22d5eab749057da27 (patch)
tree0d12f53c38456d69d015c1c54ff5ba2667501776 /tests
parentgen-cdef: compatibility with GDB 8.2+ (diff)
downloadknot-resolver-c487ecb5a3469b46e08e97c22d5eab749057da27.tar.xz
knot-resolver-c487ecb5a3469b46e08e97c22d5eab749057da27.zip
utils: diff between two calendar times in strings
Diffstat (limited to 'tests')
-rw-r--r--tests/test_utils.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_utils.c b/tests/test_utils.c
index 07856560..e6371c30 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -79,11 +79,44 @@ static void test_straddr(void **state)
assert_int_not_equal(test_bitcmp(ip6_sub, ip6_out, 4), 0);
}
+static void test_strptime_diff(void **state)
+{
+ char *format = "%Y-%m-%dT%H:%M:%S";
+ const char *errmsg = NULL;
+ double output;
+
+ errmsg = kr_strptime_diff(format,
+ "2019-01-09T12:06:04",
+ "2019-01-09T12:06:04", &output);
+ assert_true(errmsg == NULL);
+ /* double type -> equality is not reliable */
+ assert_true(output > -0.01 && output < 0.01);
+
+ errmsg = kr_strptime_diff(format,
+ "2019-01-09T12:06:04",
+ "2019-01-09T11:06:04", &output);
+ assert_true(errmsg == NULL);
+ /* double type -> equality is not reliable */
+ assert_true(output > -3600.01 && output < 3600.01);
+
+ /* invalid inputs */
+ errmsg = kr_strptime_diff(format,
+ "2019-01-09T25:06:04",
+ "2019-01-09T11:06:04", &output);
+ assert_true(errmsg != NULL);
+
+ errmsg = kr_strptime_diff("fail",
+ "2019-01-09T23:06:04",
+ "2019-01-09T11:06:04", &output);
+ assert_true(errmsg != NULL);
+}
+
int main(void)
{
const UnitTest tests[] = {
unit_test(test_strcatdup),
unit_test(test_straddr),
+ unit_test(test_strptime_diff),
};
return run_tests(tests);