From 7b4ed1a4a2e051c499e1d36978c6d8bc2ccd0ca7 Mon Sep 17 00:00:00 2001 From: hz Date: Sun, 8 Sep 2024 22:10:11 +0800 Subject: [PATCH] fixed some test cases --- tests/chrono_test.cc | 19 +++++++++++------- tests/compiler.cc | 34 ++++++++++++++++++++++++++++++++- tests/mem_test_for_singleton.cc | 2 +- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/tests/chrono_test.cc b/tests/chrono_test.cc index dda53fa..59cdc53 100755 --- a/tests/chrono_test.cc +++ b/tests/chrono_test.cc @@ -2,6 +2,8 @@ // Created by Hedzr Yeh on 2021/1/21. // +#include +#include #include #include "cmdr11/cmdr_chrono.hh" @@ -133,10 +135,12 @@ void test_cpp_style(std::chrono::system_clock::time_point &now, std::tm &now_tm) // std::cout << "date command: " << date_cmd << '\n'; - using iom = cmdr::chrono::iom; - std::cout << iom::fmtflags::gmt << iom::fmtflags::ns << "time_point (ns): os << " << now << '\n'; - std::cout << iom::fmtflags::gmt << iom::fmtflags::us << "time_point (us): os << " << now << '\n'; - std::cout << iom::fmtflags::gmt << iom::fmtflags::ms << "time_point (ms): os << " << now << '\n'; + using iom = cmdr::chrono::iom; + using fmtflags = iom::fmtflags; + std::cout << fmtflags::gmt << fmtflags::ns << "time_point (ns): os << " << now << '\n'; + std::cout << fmtflags::gmt << fmtflags::us << "time_point (us): os << " << now << '\n'; + std::cout << fmtflags::gmt << fmtflags::ms << "time_point (ms): os << " << now << '\n'; + std::cout << "time_point (ns): os << " << cmdr::chrono::format_time_point(now) << '\n'; std::cout << "std::tm: os << " << now_tm << '\n'; // { @@ -147,6 +151,7 @@ void test_cpp_style(std::chrono::system_clock::time_point &now, std::tm &now_tm) std::chrono::system_clock::time_point now2 = std::chrono::system_clock::now(); auto d = now2 - now; std::cout << "duration: os << " << d << '\n'; + std::cout << "duration: os << " << cmdr::chrono::format_duration(d) << '\n'; } void test_cpp_style(std::chrono::system_clock::time_point &now) { @@ -210,11 +215,11 @@ void test_try_parse_by() { using Clock = std::chrono::system_clock; for (auto &time_str: { - "11:01:37", + "11:01:37", #if OS_WIN - "1973-1-29 3:59:59", // MSVC: time point before 1970-1-1 is invalid + "1973-1-29 3:59:59", // MSVC: time point before 1970-1-1 is invalid #else - "1937-1-29 3:59:59", + "1937-1-29 3:59:59", #endif }) { std::tm tm = cmdr::chrono::time_point_2_tm(Clock::now()); diff --git a/tests/compiler.cc b/tests/compiler.cc index 494a6ef..d4bb210 100644 --- a/tests/compiler.cc +++ b/tests/compiler.cc @@ -1,14 +1,46 @@ // #include "cmdr11/cmdr-all.hh" -#include "cmdr11/cmdr_common.hh" +#include "cmdr11/cmdr_chrono.hh" // +#include "cmdr11/cmdr_common.hh" // #include "cmdr11/cmdr_string.hh" // to_string<>() #include #include +//inline std::ostream &operator<<(std::ostream &os, std::chrono::system_clock::time_point const &time) { +// // std::size_t ns = cmdr::chrono::time_point_get_ns(time); +// return cmdr::chrono::serialize_time_point(os, time, "%F %T"); +// //return os << time; +//} +// +//template +//inline std::ostream &operator<<(std::ostream &os, std::chrono::time_point<_Clock, _Duration> const &time) { +// // std::size_t ns = cmdr::chrono::time_point_get_ns(time); +// // return cmdr::chrono::serialize_time_point(os, time, "%F %T"); +// return os << time; +//} + int main() { std::cout << "Hello, World!" << '\n' << "I was built by " << cmdr::cross::compiler_name() << '\n' << "__cplusplus = 0x" << std::hex << std::setfill('0') << std::setw(8) << __cplusplus << ' ' << '(' << std::dec << __cplusplus << ')' << '\n'; + + { + //std::chrono::steady_clock::time_point tp; + std::chrono::system_clock::time_point now2 = std::chrono::system_clock::now(); + using iom = cmdr::chrono::iom; + using fmtflags = iom::fmtflags; + std::cout << fmtflags::gmt << fmtflags::ns << "time_point (ns): os << " << now2 << '\n'; + std::cout << fmtflags::gmt << fmtflags::us << "time_point (us): os << " << now2 << '\n'; + std::cout << fmtflags::gmt << fmtflags::ms << "time_point (ms): os << " << now2 << '\n'; + std::cout << "time point of now: "; + std::cout << now2; + //operator<<(std::cout, now2); + std::cout << '\n'; + + auto duration = now2.time_since_epoch(); + std::cout << "duration: os << " << duration << '\n'; + std::cout << "duration: os << " << cmdr::chrono::format_duration(duration) << '\n'; + } } \ No newline at end of file diff --git a/tests/mem_test_for_singleton.cc b/tests/mem_test_for_singleton.cc index 35ba3d6..f47651c 100755 --- a/tests/mem_test_for_singleton.cc +++ b/tests/mem_test_for_singleton.cc @@ -14,10 +14,10 @@ #include #include #include +#include #include #include - #include #include #include