summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-01-11 21:50:23 +0300
committerNan Zhou <nanzhoumails@gmail.com>2022-01-25 05:22:38 +0300
commit8d4c4875dd530064319bbee9e2b7ad08fcde099a (patch)
tree428a64f762232bf69465a9987af4ed3e5164ab82
parent35fb5311303730c90395d1a7fb34bc710dfa5421 (diff)
downloadbmcweb-8d4c4875dd530064319bbee9e2b7ad08fcde099a.tar.xz
Update unit tests for getDateTime
the GetDateTime series needs more unit tests to ensure that we don't get bad behavior when we hit the extremes. This commit does include one tests, for getDateTimeUint that currently throws an exception that shouldn't, which is currently commented out. This needs looked at by someone. Tested: Unit tests pass Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7f45e5d84d644780832112dca14bdb9c768903ff
-rw-r--r--http/ut/utility_test.cpp47
1 files changed, 40 insertions, 7 deletions
diff --git a/http/ut/utility_test.cpp b/http/ut/utility_test.cpp
index cb914d5cf0..4748c25712 100644
--- a/http/ut/utility_test.cpp
+++ b/http/ut/utility_test.cpp
@@ -57,21 +57,54 @@ TEST(Utility, Base64EncodeDecodeString)
EXPECT_EQ(data, decoded);
}
-TEST(Utility, GetDateTime)
+TEST(Utility, GetDateTimeStdtime)
{
+ using crow::utility::getDateTimeStdtime;
+
// some time before the epoch
- EXPECT_EQ(crow::utility::getDateTimeStdtime(std::time_t{-1234567}),
+ EXPECT_EQ(getDateTimeStdtime(std::time_t{-1234567}),
"1969-12-17T17:03:53+00:00");
+
// epoch
- EXPECT_EQ(crow::utility::getDateTimeStdtime(std::time_t{0}),
- "1970-01-01T00:00:00+00:00");
+ EXPECT_EQ(getDateTimeStdtime(std::time_t{0}), "1970-01-01T00:00:00+00:00");
// some time in the past after the epoch
- EXPECT_EQ(crow::utility::getDateTimeUint(uint64_t{1638312095}),
+
+ // Limits
+ EXPECT_EQ(getDateTimeStdtime(std::numeric_limits<std::time_t>::max()),
+ "1969-12-31T23:59:59+00:00");
+ EXPECT_EQ(getDateTimeStdtime(std::numeric_limits<std::time_t>::min()),
+ "1970-01-01T00:00:00+00:00");
+}
+
+TEST(Utility, getDateTimeUint)
+{
+ using crow::utility::getDateTimeUint;
+
+ EXPECT_EQ(getDateTimeUint(uint64_t{1638312095}),
"2021-11-30T22:41:35+00:00");
// some time in the future, beyond 2038
- EXPECT_EQ(crow::utility::getDateTimeUint(uint64_t{41638312095}),
+ EXPECT_EQ(getDateTimeUint(uint64_t{41638312095}),
"3289-06-18T21:48:15+00:00");
// the maximum time we support
- EXPECT_EQ(crow::utility::getDateTimeUint(uint64_t{253402300799}),
+ EXPECT_EQ(getDateTimeUint(uint64_t{253402300799}),
"9999-12-31T23:59:59+00:00");
+
+ // This test currently throws an exception
+ // EXPECT_EQ(getDateTimeUint(std::numeric_limits<uint64_t>::max()), "");
+
+ EXPECT_EQ(getDateTimeUint(std::numeric_limits<uint64_t>::min()),
+ "1970-01-01T00:00:00+00:00");
+}
+
+TEST(Utility, getDateTimeUintMs)
+{
+ using crow::utility::getDateTimeUintMs;
+
+ // Note, this is the wrong result, but is here to make sure that we don't
+ // have worse behavior (ie seg faults, exceptions) when this happens
+ EXPECT_EQ(getDateTimeUintMs(std::numeric_limits<uint64_t>::max()),
+ "1969-12-31T23:59:59.999000+00:00");
+
+ EXPECT_EQ(getDateTimeUintMs(std::numeric_limits<uint64_t>::min()),
+ "1970-01-01T00:00:00+00:00");
}