From 79864623f0b7131f77c525aafb342d092e299611 Mon Sep 17 00:00:00 2001 From: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Date: Fri, 5 Feb 2021 16:21:24 -0800 Subject: [PATCH] Tests: DateTime: add TimeRoundtrip test (#1613) Co-authored-by: Anton Kolesnyk --- sdk/core/azure-core/test/ut/datetime.cpp | 129 ++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core/test/ut/datetime.cpp b/sdk/core/azure-core/test/ut/datetime.cpp index c458dcd7d..4ff63bd61 100644 --- a/sdk/core/azure-core/test/ut/datetime.cpp +++ b/sdk/core/azure-core/test/ut/datetime.cpp @@ -44,14 +44,19 @@ TEST(DateTime, ParseDateExtended) } namespace { +template void TestDateTimeRoundtrip(std::string const& str, std::string const& strExpected) { auto dt = DateTime::Parse(str, DateTime::DateFormat::Rfc3339); - auto const str2 = dt.GetString(DateTime::DateFormat::Rfc3339); + auto const str2 = dt.GetRfc3339String(TF); EXPECT_EQ(str2, strExpected); } -void TestDateTimeRoundtrip(std::string const& str) { TestDateTimeRoundtrip(str, str); } +template +void TestDateTimeRoundtrip(std::string const& str) +{ + TestDateTimeRoundtrip(str, str); +} } // namespace TEST(DateTime, ParseTimeRoundrip1) @@ -634,3 +639,123 @@ TEST(DateTime, ComparisonOperators) EXPECT_GE(chronoPast, azcorePast); EXPECT_GE(chronoFuture, azcoreFuture); } + +TEST(DateTime, TimeRoundtrip) +{ + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000001Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000002Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000003Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000004Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000005Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000006Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000007Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000008Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000009Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000010Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000020Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000030Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000040Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000050Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000060Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000070Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000080Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000090Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000100Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000200Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000300Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000400Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000500Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000600Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000700Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000800Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0000900Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0001000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0002000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0003000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0004000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0005000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0006000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0007000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0008000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0009000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0010000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0020000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0030000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0040000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0050000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0060000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0070000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0080000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0090000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.0100000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0200000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0300000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0400000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0500000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0600000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0700000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0800000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.0900000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:00.1000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.2000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.3000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.4000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.5000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.6000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.7000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.8000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:00.9000000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:01.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:02.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:03.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:04.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:05.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:06.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:07.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:08.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:09.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:00:10.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:20.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:30.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:40.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:00:50.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:01:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:02:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:03:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:04:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:05:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:06:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:07:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:08:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:09:00.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T00:10:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:20:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:30:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:40:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T00:50:00.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T01:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T02:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T03:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T04:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T05:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T06:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T07:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T08:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T09:00:00.0000000Z"); + + TestDateTimeRoundtrip("2021-02-05T10:00:00.0000000Z"); + TestDateTimeRoundtrip("2021-02-05T20:00:00.0000000Z"); +}