mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
test-calendarspec: use _cleanup_
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#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;
|
||||
@@ -28,18 +28,17 @@ static void _test_one(int line, const char *input, const char *output) {
|
||||
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;
|
||||
@@ -66,8 +65,6 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
|
||||
else
|
||||
assert_se(r == -ENOENT);
|
||||
|
||||
calendar_spec_free(c);
|
||||
|
||||
assert_se(set_unset_env("TZ", old_tz, true) == 0);
|
||||
tzset();
|
||||
}
|
||||
@@ -76,7 +73,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
|
||||
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 */
|
||||
@@ -87,7 +84,6 @@ TEST(timestamp) {
|
||||
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);
|
||||
@@ -95,7 +91,7 @@ TEST(timestamp) {
|
||||
}
|
||||
|
||||
TEST(hourly_bug_4031) {
|
||||
CalendarSpec *c;
|
||||
_cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
|
||||
usec_t n, u, w;
|
||||
int r;
|
||||
|
||||
@@ -113,8 +109,6 @@ TEST(hourly_bug_4031) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user