#include "tests.h"
static void _test_one(int line, const char *input, const char *output) {
- CalendarSpec *c;
+ _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
_cleanup_free_ char *p = NULL, *q = NULL;
usec_t u;
int r;
u = now(CLOCK_REALTIME);
r = calendar_spec_next_usec(c, u, &u);
log_info("Next: %s", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP(u));
- calendar_spec_free(c);
+ c = 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));
}
#define test_one(input, output) _test_one(__LINE__, input, output)
static void _test_next(int line, const char *input, const char *new_tz, usec_t after, usec_t expect) {
- CalendarSpec *c;
+ _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
usec_t u;
char *old_tz;
int r;
else
assert_se(r == -ENOENT);
- calendar_spec_free(c);
-
assert_se(set_unset_env("TZ", old_tz, true) == 0);
tzset();
}
TEST(timestamp) {
char buf[FORMAT_TIMESTAMP_MAX];
_cleanup_free_ char *t = NULL;
- CalendarSpec *c;
+ _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
usec_t x, y;
/* Ensure that a timestamp is also a valid calendar specification. Convert forth and back */
log_info("%s", buf);
assert_se(calendar_spec_from_string(buf, &c) >= 0);
assert_se(calendar_spec_to_string(c, &t) >= 0);
- calendar_spec_free(c);
log_info("%s", t);
assert_se(parse_timestamp(t, &y) >= 0);
}
TEST(hourly_bug_4031) {
- CalendarSpec *c;
+ _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
usec_t n, u, w;
int r;
assert_se(u <= n + USEC_PER_HOUR);
assert_se(u < w);
assert_se(w <= u + USEC_PER_HOUR);
-
- calendar_spec_free(c);
}
TEST(calendar_spec_one) {