7e4a718ba3
Some checks failed
rpcrypto-build / build (Debug, hisiv500.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, host-afl.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, host.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, mips64el-linux-gnuabi64.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, mipsel-openwrt-linux.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, hisiv500.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, host-afl.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, host.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, mips64el-linux-gnuabi64.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Release, mipsel-openwrt-linux.toolchain.cmake) (push) Waiting to run
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Failing after 39s
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
/*
|
|
Time formatting tests
|
|
|
|
Copyright (c) 2012 - 2016, Victor Zverovich
|
|
All rights reserved.
|
|
|
|
For the license information refer to format.h.
|
|
*/
|
|
#ifdef WIN32
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
#endif
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "fmt/time.h"
|
|
|
|
TEST(TimeTest, Format) {
|
|
std::tm tm = std::tm();
|
|
tm.tm_year = 116;
|
|
tm.tm_mon = 3;
|
|
tm.tm_mday = 25;
|
|
EXPECT_EQ("The date is 2016-04-25.",
|
|
fmt::format("The date is {:%Y-%m-%d}.", tm));
|
|
}
|
|
|
|
TEST(TimeTest, GrowBuffer) {
|
|
std::string s = "{:";
|
|
for (int i = 0; i < 30; ++i)
|
|
s += "%c";
|
|
s += "}\n";
|
|
std::time_t t = std::time(0);
|
|
fmt::format(s, *std::localtime(&t));
|
|
}
|
|
|
|
TEST(TimeTest, EmptyResult) {
|
|
EXPECT_EQ("", fmt::format("{}", std::tm()));
|
|
}
|
|
|
|
bool EqualTime(const std::tm &lhs, const std::tm &rhs) {
|
|
return lhs.tm_sec == rhs.tm_sec &&
|
|
lhs.tm_min == rhs.tm_min &&
|
|
lhs.tm_hour == rhs.tm_hour &&
|
|
lhs.tm_mday == rhs.tm_mday &&
|
|
lhs.tm_mon == rhs.tm_mon &&
|
|
lhs.tm_year == rhs.tm_year &&
|
|
lhs.tm_wday == rhs.tm_wday &&
|
|
lhs.tm_yday == rhs.tm_yday &&
|
|
lhs.tm_isdst == rhs.tm_isdst;
|
|
}
|
|
|
|
TEST(TimeTest, LocalTime) {
|
|
std::time_t t = std::time(0);
|
|
std::tm tm = *std::localtime(&t);
|
|
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
|
|
}
|
|
|
|
TEST(TimeTest, GMTime) {
|
|
std::time_t t = std::time(0);
|
|
std::tm tm = *std::gmtime(&t);
|
|
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
|
}
|