summaryrefslogtreecommitdiff
path: root/regress/unittests/conversion
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2017-04-02 01:26:17 +0100
committerColin Watson <cjwatson@debian.org>2017-04-02 01:54:08 +0100
commit20adc7e0fc13ff9c7d270db250aac1fa140e3851 (patch)
tree5d9f06b0ff195db88093037d9102f0cdcf3884c6 /regress/unittests/conversion
parentaf27669f905133925224acc753067dea710881dd (diff)
parentec338656a3d6b21bb87f3b6367b232d297f601e5 (diff)
New upstream release (7.5p1)
Diffstat (limited to 'regress/unittests/conversion')
-rw-r--r--regress/unittests/conversion/Makefile10
-rw-r--r--regress/unittests/conversion/tests.c51
2 files changed, 61 insertions, 0 deletions
diff --git a/regress/unittests/conversion/Makefile b/regress/unittests/conversion/Makefile
new file mode 100644
index 000000000..cde97dc28
--- /dev/null
+++ b/regress/unittests/conversion/Makefile
@@ -0,0 +1,10 @@
1# $OpenBSD: Makefile,v 1.1 2017/03/14 01:20:29 dtucker Exp $
2
3PROG=test_conversion
4SRCS=tests.c
5REGRESS_TARGETS=run-regress-${PROG}
6
7run-regress-${PROG}: ${PROG}
8 env ${TEST_ENV} ./${PROG}
9
10.include <bsd.regress.mk>
diff --git a/regress/unittests/conversion/tests.c b/regress/unittests/conversion/tests.c
new file mode 100644
index 000000000..6dd77ef42
--- /dev/null
+++ b/regress/unittests/conversion/tests.c
@@ -0,0 +1,51 @@
1/* $OpenBSD: tests.c,v 1.1 2017/03/14 01:20:29 dtucker Exp $ */
2/*
3 * Regress test for conversions
4 *
5 * Placed in the public domain
6 */
7
8#include "includes.h"
9
10#include <sys/types.h>
11#include <sys/param.h>
12#include <stdio.h>
13#ifdef HAVE_STDINT_H
14#include <stdint.h>
15#endif
16#include <stdlib.h>
17#include <string.h>
18
19#include "../test_helper/test_helper.h"
20
21#include "misc.h"
22
23void
24tests(void)
25{
26 char buf[1024];
27
28 TEST_START("conversion_convtime");
29 ASSERT_LONG_EQ(convtime("0"), 0);
30 ASSERT_LONG_EQ(convtime("1"), 1);
31 ASSERT_LONG_EQ(convtime("1S"), 1);
32 /* from the examples in the comment above the function */
33 ASSERT_LONG_EQ(convtime("90m"), 5400);
34 ASSERT_LONG_EQ(convtime("1h30m"), 5400);
35 ASSERT_LONG_EQ(convtime("2d"), 172800);
36 ASSERT_LONG_EQ(convtime("1w"), 604800);
37
38 /* negative time is not allowed */
39 ASSERT_LONG_EQ(convtime("-7"), -1);
40 ASSERT_LONG_EQ(convtime("-9d"), -1);
41
42 /* overflow */
43 snprintf(buf, sizeof buf, "%llu", (unsigned long long)LONG_MAX + 1);
44 ASSERT_LONG_EQ(convtime(buf), -1);
45
46 /* overflow with multiplier */
47 snprintf(buf, sizeof buf, "%lluM", (unsigned long long)LONG_MAX/60 + 1);
48 ASSERT_LONG_EQ(convtime(buf), -1);
49 ASSERT_LONG_EQ(convtime("1000000000000000000000w"), -1);
50 TEST_DONE();
51}