diff options
Diffstat (limited to 'libs/chrono/test/io')
-rw-r--r-- | libs/chrono/test/io/duration_output.cpp | 16 | ||||
-rw-r--r-- | libs/chrono/test/io/time_point_output.cpp | 28 |
2 files changed, 43 insertions, 1 deletions
diff --git a/libs/chrono/test/io/duration_output.cpp b/libs/chrono/test/io/duration_output.cpp index e2811eec3..91494efee 100644 --- a/libs/chrono/test/io/duration_output.cpp +++ b/libs/chrono/test/io/duration_output.cpp @@ -55,6 +55,21 @@ void test_state_saver(const char* str, const char* str2, D d, boost::chrono::dur BOOST_TEST(out.str() == str2); } +template<typename D> +void test_state_saver2(const char* str, const char* str2, D d, boost::chrono::duration_style style) +{ + std::ostringstream out; + { + boost::chrono::duration_style_io_saver ios(out, style); + out << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str); + } + out << " " << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str2); +} + #endif int main() @@ -90,6 +105,7 @@ int main() test_good("5000 hours", hours(5000), duration_style::prefix); test_good("5000 h", hours(5000), duration_style::symbol); test_state_saver("5000 h", "5000 h 5000 hours", hours(5000), duration_style::symbol); + test_state_saver2("5000 h", "5000 h 5000 hours", hours(5000), duration_style::symbol); #endif return boost::report_errors(); diff --git a/libs/chrono/test/io/time_point_output.cpp b/libs/chrono/test/io/time_point_output.cpp index 7a9d81d80..0312c33d4 100644 --- a/libs/chrono/test/io/time_point_output.cpp +++ b/libs/chrono/test/io/time_point_output.cpp @@ -76,6 +76,8 @@ void test_good_utc_fmt_system_clock(const char* str, const char* fmt, D d) std::ostringstream out; boost::chrono::time_point<Clock, D> tp(d); + boost::chrono::time_fmt_io_saver<> fmts(out); + boost::chrono::timezone_io_saver tzs(out); out << time_fmt(boost::chrono::timezone::utc, fmt) << tp; BOOST_TEST(out.good()); std::cout << "Expected= " << str << std::endl; @@ -83,6 +85,22 @@ void test_good_utc_fmt_system_clock(const char* str, const char* fmt, D d) BOOST_TEST_EQ( out.str() , std::string(str) ); } +template <typename D> +void test_good_utc_fmt_system_clock2(const char* str, const char* fmt, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point<Clock, D> tp(d); + boost::chrono::time_fmt_io_saver<> fmts(out, fmt); + boost::chrono::timezone_io_saver tzs(out, boost::chrono::timezone::utc); + out << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST_EQ( out.str() , std::string(str) ); +} + template<typename Clock, typename D> void test_good(const char* str, D d, boost::chrono::duration_style style) { @@ -181,6 +199,14 @@ void check_all_system_clock() test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2)); test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2)); #endif + test_good_utc_fmt_system_clock2("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2)); + test_good_utc_fmt_system_clock2("1970-01-01 02", "%Y-%m-%d %H", hours(2)); +#if ! defined(BOOST_CHRONO_WINDOWS_API) + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2)); + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock2 ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2)); +#endif } @@ -190,7 +216,7 @@ void check_all_system_clock() void test_gmtime(std::time_t t) { std::cout << "t " << t << std::endl; - puts(ctime(&t)); + std::puts(ctime(&t)); std::tm tm; std::memset(&tm, 0, sizeof(std::tm)); if (boost::chrono::detail::internal_gmtime(&t, &tm)) |