Add tests for valid_temp_time

This commit is contained in:
Ed Kellett 2022-03-06 16:44:32 +00:00
parent 7a246575e5
commit 2644dcd166
2 changed files with 53 additions and 0 deletions

View file

@ -1,6 +1,7 @@
check_PROGRAMS = runtests \
chmode1 \
match1 \
misc \
msgbuf_parse1 \
msgbuf_unparse1 \
hostmask1 \

52
tests/misc.c Normal file
View file

@ -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;
}