diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
commit | b750101eb236130cf056c675997decbac904cc49 (patch) | |
tree | a5df1a06754bdd014cb975c051c83b01c9a97532 /src/network/test-networkd-address.c | |
parent | Initial commit. (diff) | |
download | systemd-upstream.tar.xz systemd-upstream.zip |
Adding upstream version 252.22.upstream/252.22upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/network/test-networkd-address.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/network/test-networkd-address.c b/src/network/test-networkd-address.c new file mode 100644 index 0000000..a40c571 --- /dev/null +++ b/src/network/test-networkd-address.c @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "networkd-address.h" +#include "tests.h" +#include "time-util.h" + +static void test_FORMAT_LIFETIME_one(usec_t lifetime, const char *expected) { + const char *t = FORMAT_LIFETIME(lifetime); + + log_debug(USEC_FMT " → \"%s\" (expected \"%s\")", lifetime, t, expected); + assert_se(streq(t, expected)); +} + +TEST(FORMAT_LIFETIME) { + usec_t now_usec; + + now_usec = now(CLOCK_BOOTTIME); + + test_FORMAT_LIFETIME_one(now_usec, "for 0"); + test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), "for 1s"); + test_FORMAT_LIFETIME_one(usec_add(now_usec, 3 * USEC_PER_WEEK + USEC_PER_SEC - 1), "for 3w"); + test_FORMAT_LIFETIME_one(USEC_INFINITY, "forever"); +} + +DEFINE_TEST_MAIN(LOG_DEBUG); |