static void test_one(const char *input, const char *output) {
CalendarSpec *c;
- char *p;
+ _cleanup_free_ char *p = NULL, *q = NULL;
usec_t u;
char buf[FORMAT_TIMESTAMP_MAX];
int r;
printf("\"%s\" → \"%s\"\n", input, p);
assert_se(streq(p, output));
- free(p);
u = now(CLOCK_REALTIME);
r = calendar_spec_next_usec(c, u, &u);
printf("Next: %s\n", r < 0 ? strerror(-r) : format_timestamp(buf, sizeof(buf), u));
+ calendar_spec_free(c);
+ assert_se(calendar_spec_from_string(p, &c) >= 0);
+ assert_se(calendar_spec_to_string(c, &q) >= 0);
calendar_spec_free(c);
+
+ assert_se(streq(q, p));
}
int main(int argc, char* argv[]) {
test_one("daily", "*-*-* 00:00:00");
test_one("monthly", "*-*-01 00:00:00");
test_one("weekly", "Mon *-*-* 00:00:00");
+ test_one("minutely", "*-*-* *:*:00");
+ test_one("quarterly", "*-01,04,07,10-01 00:00:00");
+ test_one("semi-annually", "*-01,07-01 00:00:00");
+ test_one("annually", "*-01-01 00:00:00");
test_one("*:2/3", "*-*-* *:02/3:00");
assert_se(calendar_spec_from_string("test", &c) < 0);