[openssh-commits] [openssh] 04/05: upstream commit
git+noreply at mindrot.org
git+noreply at mindrot.org
Tue Mar 14 14:20:04 AEDT 2017
This is an automated email from the git hooks/post-receive script.
dtucker pushed a commit to branch master
in repository openssh.
commit f57783f1ddfb4cdfbd612c6beb5ec01cb5b9a6b9
Author: dtucker at openbsd.org <dtucker at openbsd.org>
Date: Tue Mar 14 01:20:29 2017 +0000
upstream commit
Add unit test for convtime().
Upstream-Regress-ID: 8717bc0ca4c21120f6dd3a1d3b7a363f707c31e1
---
regress/unittests/Makefile | 7 +++---
regress/unittests/conversion/Makefile | 10 ++++++++
regress/unittests/conversion/tests.c | 47 +++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index e70b166..e975f6c 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,5 +1,6 @@
-# $OpenBSD: Makefile,v 1.7 2016/08/19 06:44:13 djm Exp $
-REGRESS_FAIL_EARLY= yes
-SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match
+# $OpenBSD: Makefile,v 1.9 2017/03/14 01:20:29 dtucker Exp $
+
+REGRESS_FAIL_EARLY?= yes
+SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match conversion
.include <bsd.subdir.mk>
diff --git a/regress/unittests/conversion/Makefile b/regress/unittests/conversion/Makefile
new file mode 100644
index 0000000..cde97dc
--- /dev/null
+++ b/regress/unittests/conversion/Makefile
@@ -0,0 +1,10 @@
+# $OpenBSD: Makefile,v 1.1 2017/03/14 01:20:29 dtucker Exp $
+
+PROG=test_conversion
+SRCS=tests.c
+REGRESS_TARGETS=run-regress-${PROG}
+
+run-regress-${PROG}: ${PROG}
+ env ${TEST_ENV} ./${PROG}
+
+.include <bsd.regress.mk>
diff --git a/regress/unittests/conversion/tests.c b/regress/unittests/conversion/tests.c
new file mode 100644
index 0000000..ebd7bde
--- /dev/null
+++ b/regress/unittests/conversion/tests.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: tests.c,v 1.1 2017/03/14 01:20:29 dtucker Exp $ */
+/*
+ * Regress test for conversions
+ *
+ * Placed in the public domain
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test_helper.h"
+
+#include "misc.h"
+
+void
+tests(void)
+{
+ char buf[1024];
+
+ TEST_START("conversion_convtime");
+ ASSERT_LONG_EQ(convtime("0"), 0);
+ ASSERT_LONG_EQ(convtime("1"), 1);
+ ASSERT_LONG_EQ(convtime("1S"), 1);
+ /* from the examples in the comment above the function */
+ ASSERT_LONG_EQ(convtime("90m"), 5400);
+ ASSERT_LONG_EQ(convtime("1h30m"), 5400);
+ ASSERT_LONG_EQ(convtime("2d"), 172800);
+ ASSERT_LONG_EQ(convtime("1w"), 604800);
+
+ /* negative time is not allowed */
+ ASSERT_LONG_EQ(convtime("-7"), -1);
+ ASSERT_LONG_EQ(convtime("-9d"), -1);
+
+ /* overflow */
+ snprintf(buf, sizeof buf, "%llu", (unsigned long long)LONG_MAX + 1);
+ ASSERT_LONG_EQ(convtime(buf), -1);
+
+ /* overflow with multiplier */
+ snprintf(buf, sizeof buf, "%lluM", (unsigned long long)LONG_MAX/60 + 1);
+ ASSERT_LONG_EQ(convtime(buf), -1);
+ ASSERT_LONG_EQ(convtime("1000000000000000000000w"), -1);
+ TEST_DONE();
+}
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list