]> jfr.im git - solanum.git/commitdiff
Add tests for valid_temp_time
authorEd Kellett <redacted>
Sun, 6 Mar 2022 16:44:32 +0000 (16:44 +0000)
committerEd Kellett <redacted>
Sun, 6 Mar 2022 22:51:19 +0000 (22:51 +0000)
tests/Makefile.am
tests/misc.c [new file with mode: 0644]

index 71a70dc792d1a7d800b91f95166e7823605f43e7..2c958e6f81a0516c7eb021f4b81b4508d0e8431f 100644 (file)
@@ -1,6 +1,7 @@
 check_PROGRAMS = runtests \
        chmode1 \
        match1 \
+       misc \
        msgbuf_parse1 \
        msgbuf_unparse1 \
        hostmask1 \
diff --git a/tests/misc.c b/tests/misc.c
new file mode 100644 (file)
index 0000000..4a0e714
--- /dev/null
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "tap/basic.h"
+
+#include "s_newconf.h"
+
+#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
+
+#define MINUTE (60)
+#define HOUR (MINUTE * 60)
+#define DAY (HOUR * 24)
+#define WEEK (DAY * 7)
+
+static void valid_temp_time1(void)
+{
+       time_t t;
+       t = valid_temp_time("1");
+       is_int(MINUTE, t, MSG);
+       t = valid_temp_time("1m");
+       is_int(MINUTE, t, MSG);
+       t = valid_temp_time("1h");
+       is_int(HOUR, t, MSG);
+       t = valid_temp_time("1d");
+       is_int(DAY, t, MSG);
+       t = valid_temp_time("1w");
+       is_int(WEEK, t, MSG);
+
+       t = valid_temp_time("2d");
+       is_int(2 * DAY, t, MSG);
+
+       t = valid_temp_time("1w2d3h4m");
+       is_int(1 * WEEK + 2 * DAY + 3 * HOUR + 4 * MINUTE, t, MSG);
+       t = valid_temp_time("1w2d3h4");
+       is_int(1 * WEEK + 2 * DAY + 3 * HOUR + 4 * MINUTE, t, MSG);
+
+       t = valid_temp_time("4m3h2d1w");
+       is_int(1 * WEEK + 2 * DAY + 3 * HOUR + 4 * MINUTE, t, MSG);
+
+       t = valid_temp_time("7000w");
+       is_int(52 * WEEK, t, MSG);
+}
+
+int main(int argc, char *argv[])
+{
+       plan_lazy();
+
+       valid_temp_time1();
+
+       return 0;
+}