summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2020-05-29 01:21:36 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2020-05-29 01:21:36 +0000
commit0ddcfef3792839b9c14f3078ecafe4c53557bf9e (patch)
treed4c265d58c1cf58e77b66137d5b24fd7aa2eba0a /regress
parentd6af161b33c81e1822711bd3d7feb8708835d990 (diff)
Unit test for convtime. ok djm@
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.bin/ssh/unittests/misc/tests.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/regress/usr.bin/ssh/unittests/misc/tests.c b/regress/usr.bin/ssh/unittests/misc/tests.c
index ed775ebbd9d..8fe6aedbb9f 100644
--- a/regress/usr.bin/ssh/unittests/misc/tests.c
+++ b/regress/usr.bin/ssh/unittests/misc/tests.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tests.c,v 1.1 2019/04/28 22:53:26 dtucker Exp $ */
+/* $OpenBSD: tests.c,v 1.2 2020/05/29 01:21:35 dtucker Exp $ */
/*
* Regress test for misc helper functions.
*
@@ -76,4 +76,23 @@ tests(void)
ASSERT_STRING_EQ(path, "some/path");
free(user); free(host); free(path);
TEST_DONE();
+
+ TEST_START("misc_convtime");
+ ASSERT_LONG_EQ(convtime("1"), 1);
+ ASSERT_LONG_EQ(convtime("2s"), 2);
+ ASSERT_LONG_EQ(convtime("3m"), 180);
+ ASSERT_LONG_EQ(convtime("1m30"), 90);
+ ASSERT_LONG_EQ(convtime("1m30s"), 90);
+ ASSERT_LONG_EQ(convtime("1h1s"), 3601);
+ ASSERT_LONG_EQ(convtime("1h30m"), 90 * 60);
+ ASSERT_LONG_EQ(convtime("1d"), 24 * 60 * 60);
+ ASSERT_LONG_EQ(convtime("1w"), 7 * 24 * 60 * 60);
+ ASSERT_LONG_EQ(convtime("1w2d3h4m5"), 788645);
+ ASSERT_LONG_EQ(convtime("1w2d3h4m5s"), 788645);
+ /* any negative number or error returns -1 */
+ ASSERT_LONG_EQ(convtime("-1"), -1);
+ ASSERT_LONG_EQ(convtime(""), -1);
+ ASSERT_LONG_EQ(convtime("trout"), -1);
+ ASSERT_LONG_EQ(convtime("-77"), -1);
+ TEST_DONE();
}