1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "networkd-address.h"
4 #include "tests.h"
5 #include "time-util.h"
6 
test_FORMAT_LIFETIME_one(usec_t lifetime,const char * expected)7 static void test_FORMAT_LIFETIME_one(usec_t lifetime, const char *expected) {
8         const char *t = FORMAT_LIFETIME(lifetime);
9 
10         log_debug(USEC_FMT " → \"%s\" (expected \"%s\")", lifetime, t, expected);
11         assert_se(streq(t, expected));
12 }
13 
TEST(FORMAT_LIFETIME)14 TEST(FORMAT_LIFETIME) {
15         usec_t now_usec;
16 
17         now_usec = now(CLOCK_BOOTTIME);
18 
19         test_FORMAT_LIFETIME_one(now_usec, "for 0");
20         test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), "for 1s");
21         test_FORMAT_LIFETIME_one(usec_add(now_usec, 3 * USEC_PER_WEEK + USEC_PER_SEC - 1), "for 3w");
22         test_FORMAT_LIFETIME_one(USEC_INFINITY, "forever");
23 }
24 
25 DEFINE_TEST_MAIN(LOG_DEBUG);
26