Change format syntax to a simple custom %f/%#f scheme

This commit is contained in:
Vladimir Panteleev
2017-12-10 04:44:13 +00:00
parent fd8a36d3ea
commit 15b1f8d8fa
4 changed files with 18 additions and 24 deletions
+9 -10
View File
@@ -123,21 +123,20 @@ class TimeTest : public testing::TestWithParam<
TEST_P(TimeTest, FormatTime) {
timeval tv = std::get<0>(GetParam());
EXPECT_EQ(std::get<1>(GetParam()), CUtils::FormatTime(tv, "%s.%L", "UTC"));
EXPECT_EQ(std::get<2>(GetParam()), CUtils::FormatTime(tv, "%s.%N", "UTC"));
EXPECT_EQ(std::get<3>(GetParam()), CUtils::FormatTime(tv, "%s.%3N", "UTC"));
EXPECT_EQ(std::get<1>(GetParam()), CUtils::FormatTime(tv, "%s.%f", "UTC"));
EXPECT_EQ(std::get<2>(GetParam()), CUtils::FormatTime(tv, "%s.%6f", "UTC"));
EXPECT_EQ(std::get<3>(GetParam()), CUtils::FormatTime(tv, "%s.%9f", "UTC"));
}
INSTANTIATE_TEST_CASE_P(
TimeTest, TimeTest,
testing::Values(
// leading zeroes
std::make_tuple(timeval{42, 12345}, "42.012", "42.012345000", "42.012"),
std::make_tuple(timeval{42, 12345}, "42.012", "42.012345", "42.012345000"),
// (no) rounding
std::make_tuple(timeval{42, 999999}, "42.999", "42.999999000",
"42.999"),
std::make_tuple(timeval{42, 999999}, "42.999", "42.999999", "42.999999000"),
// no tv_usec part
std::make_tuple(timeval{42, 0}, "42.000", "42.000000000", "42.000")));
std::make_tuple(timeval{42, 0}, "42.000", "42.000000", "42.000000000")));
TEST(UtilsTest, FormatTime) {
// Test passthrough
@@ -151,10 +150,10 @@ TEST(UtilsTest, FormatTime) {
timeval tv2;
tv2.tv_sec = 42;
tv2.tv_usec = 123456;
CString str2 = CUtils::FormatTime(tv2, "%%L", "UTC");
EXPECT_EQ("%L", str2);
CString str2 = CUtils::FormatTime(tv2, "%%f", "UTC");
EXPECT_EQ("%f", str2);
// Test suffix
CString str3 = CUtils::FormatTime(tv2, "a%Lb", "UTC");
CString str3 = CUtils::FormatTime(tv2, "a%fb", "UTC");
EXPECT_EQ("a123b", str3);
}