From caa7af253abbd22cedb25a4dc87dae4df8058889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 17 Mar 2025 08:12:33 +0100 Subject: [PATCH] tests: add tests on function util_strftimeval with microseconds < 0 or > 999999 --- tests/unit/core/test-core-util.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/core/test-core-util.cpp b/tests/unit/core/test-core-util.cpp index c77a9544b..149fd9e0e 100644 --- a/tests/unit/core/test-core-util.cpp +++ b/tests/unit/core/test-core-util.cpp @@ -252,6 +252,24 @@ TEST(CoreUtil, Strftimeval) strcpy (str_time, "test"); LONGS_EQUAL(17, util_strftimeval (str_time, sizeof (str_time), "%!.%f", &tv)); STRCMP_EQUAL("1703500149.456789", str_time); + + /* test date: 2023-12-25T10:29:09.000000Z (with microseconds < 0) */ + tv.tv_sec = 1703500149; + tv.tv_usec = -1; + + strcpy (str_time, "test"); + LONGS_EQUAL(26, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%f", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.000000", str_time); + + /* test date: 2023-12-25T10:29:09.999999Z (with microseconds > 999999) */ + tv.tv_sec = 1703500149; + tv.tv_usec = 1000000; + + strcpy (str_time, "test"); + LONGS_EQUAL(26, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%f", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.999999", str_time); } /*