summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2020-05-29 01:21:35 +0000
committerDamien Miller <djm@mindrot.org>2020-05-29 15:48:10 +1000
commit0b15892fc47d6840eba1291a6be9be1a70bc8972 (patch)
treeacc76ea7c4dfecc503628d81311c94711fbb85f5 /regress
parent188e332d1c8f9f24e5b6659e9680bf083f837df9 (diff)
upstream: Unit test for convtime. ok djm@
OpenBSD-Regress-ID: cec4239efa2fc4c7062064f07a847e1cbdbcd5dd
Diffstat (limited to 'regress')
-rw-r--r--regress/unittests/misc/tests.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/regress/unittests/misc/tests.c b/regress/unittests/misc/tests.c
index ed775ebbd..8fe6aedbb 100644
--- a/regress/unittests/misc/tests.c
+++ b/regress/unittests/misc/tests.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tests.c,v 1.1 2019/04/28 22:53:26 dtucker Exp $ */ 1/* $OpenBSD: tests.c,v 1.2 2020/05/29 01:21:35 dtucker Exp $ */
2/* 2/*
3 * Regress test for misc helper functions. 3 * Regress test for misc helper functions.
4 * 4 *
@@ -76,4 +76,23 @@ tests(void)
76 ASSERT_STRING_EQ(path, "some/path"); 76 ASSERT_STRING_EQ(path, "some/path");
77 free(user); free(host); free(path); 77 free(user); free(host); free(path);
78 TEST_DONE(); 78 TEST_DONE();
79
80 TEST_START("misc_convtime");
81 ASSERT_LONG_EQ(convtime("1"), 1);
82 ASSERT_LONG_EQ(convtime("2s"), 2);
83 ASSERT_LONG_EQ(convtime("3m"), 180);
84 ASSERT_LONG_EQ(convtime("1m30"), 90);
85 ASSERT_LONG_EQ(convtime("1m30s"), 90);
86 ASSERT_LONG_EQ(convtime("1h1s"), 3601);
87 ASSERT_LONG_EQ(convtime("1h30m"), 90 * 60);
88 ASSERT_LONG_EQ(convtime("1d"), 24 * 60 * 60);
89 ASSERT_LONG_EQ(convtime("1w"), 7 * 24 * 60 * 60);
90 ASSERT_LONG_EQ(convtime("1w2d3h4m5"), 788645);
91 ASSERT_LONG_EQ(convtime("1w2d3h4m5s"), 788645);
92 /* any negative number or error returns -1 */
93 ASSERT_LONG_EQ(convtime("-1"), -1);
94 ASSERT_LONG_EQ(convtime(""), -1);
95 ASSERT_LONG_EQ(convtime("trout"), -1);
96 ASSERT_LONG_EQ(convtime("-77"), -1);
97 TEST_DONE();
79} 98}