Skip to content

Commit

Permalink
fixed some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Sep 8, 2024
1 parent b41c83f commit 7b4ed1a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
19 changes: 12 additions & 7 deletions tests/chrono_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Created by Hedzr Yeh on 2021/1/21.
//

#include <iomanip>
#include <iostream>
#include <thread>

#include "cmdr11/cmdr_chrono.hh"
Expand Down Expand Up @@ -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';

// {
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
34 changes: 33 additions & 1 deletion tests/compiler.cc
Original file line number Diff line number Diff line change
@@ -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 <iomanip>
#include <iostream>

//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<class _Clock, class _Duration = typename _Clock::duration>
//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';
}
}
2 changes: 1 addition & 1 deletion tests/mem_test_for_singleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <memory>
#include <new>
#include <string>


#include <cstdio>
#include <functional>
#include <iomanip>
Expand Down

0 comments on commit 7b4ed1a

Please sign in to comment.