diff options
author | David Tardon <dtardon@redhat.com> | 2023-04-24 20:44:29 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2023-04-24 20:44:29 +0200 |
commit | 7a9f8b90536ec56ada20fb39aae5373a8273be9d (patch) | |
tree | 52f233c31c312a837e80e49b1e1d77e6b768180b /src/test/test-calendarspec.c | |
parent | test: use _cleanup_ for temp. files (diff) | |
download | systemd-7a9f8b90536ec56ada20fb39aae5373a8273be9d.tar.xz systemd-7a9f8b90536ec56ada20fb39aae5373a8273be9d.zip |
test-calendarspec: use _cleanup_
Diffstat (limited to '')
-rw-r--r-- | src/test/test-calendarspec.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 564983b699..db64142f01 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -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) { |