diff options
Diffstat (limited to 'libs/chrono/test')
-rw-r--r-- | libs/chrono/test/Jamfile.v2 | 3 | ||||
-rw-r--r-- | libs/chrono/test/io/duration_output.cpp | 16 | ||||
-rw-r--r-- | libs/chrono/test/io/time_point_output.cpp | 28 | ||||
-rw-r--r-- | libs/chrono/test/test_10778.cpp | 19 | ||||
-rw-r--r-- | libs/chrono/test/test_11006.cpp | 21 | ||||
-rw-r--r-- | libs/chrono/test/test_11012.cpp | 27 | ||||
-rw-r--r-- | libs/chrono/test/test_7868.cpp | 2 |
7 files changed, 114 insertions, 2 deletions
diff --git a/libs/chrono/test/Jamfile.v2 b/libs/chrono/test/Jamfile.v2 index af08eb978..d227bb820 100644 --- a/libs/chrono/test/Jamfile.v2 +++ b/libs/chrono/test/Jamfile.v2 @@ -438,6 +438,8 @@ rule chrono-compile2 ( sources : name ) [ chrono-v1-v2-run-header io/time_point_input.cpp ] [ chrono-v1-v2-run-header io/time_point_output.cpp ] [ chrono-run test_7868.cpp ] + [ chrono-run test_11006.cpp ] + [ chrono-run test_11012.cpp ] ; test-suite "win32" @@ -450,5 +452,6 @@ rule chrono-compile2 ( sources : name ) : #[ chrono-run test_7868.cpp ] #[ chrono-run test_9337.cpp ] + #[ chrono-run test_10778.cpp ] ; 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)) diff --git a/libs/chrono/test/test_10778.cpp b/libs/chrono/test/test_10778.cpp new file mode 100644 index 000000000..7693cd3fe --- /dev/null +++ b/libs/chrono/test/test_10778.cpp @@ -0,0 +1,19 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#include <boost/chrono.hpp> +#include <boost/chrono/chrono_io.hpp> +#include <atomic> + +void test() +{ + std::atomic<boost::chrono::milliseconds> ms; // error C2338: atomic<T> requires T to be trivially copyable. +} + +int main() { + test(); + return 1; +} diff --git a/libs/chrono/test/test_11006.cpp b/libs/chrono/test/test_11006.cpp new file mode 100644 index 000000000..cf40fc051 --- /dev/null +++ b/libs/chrono/test/test_11006.cpp @@ -0,0 +1,21 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#define BOOST_CHRONO_VERSION 2 +#include <iostream> +#include <boost/chrono/io/time_point_io.hpp> + + +int main() { + { + boost::chrono::time_fmt_io_saver<> tmp(std::cout); + } + { + boost::chrono::time_fmt_io_saver<> tmp(std::cout, "%Y-%m-%d %H:%M:%S"); + } + return 0; +} + diff --git a/libs/chrono/test/test_11012.cpp b/libs/chrono/test/test_11012.cpp new file mode 100644 index 000000000..249b9b891 --- /dev/null +++ b/libs/chrono/test/test_11012.cpp @@ -0,0 +1,27 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_VERSION 1 +#define BOOST_CHRONO_VERSION 2 +#include <iostream> +#include <boost/rational.hpp> +#include <boost/chrono/chrono.hpp> +//#define BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#include <boost/chrono/chrono_io.hpp> + +int main() +{ + { + typedef boost::chrono::duration<float> RationalSeconds; + RationalSeconds d(0.5); + std::cout << d << std::endl; + } + { + typedef boost::chrono::duration<boost::rational<int> > RationalSeconds; + RationalSeconds d; + std::cout << d << std::endl; + } + return 0; +} diff --git a/libs/chrono/test/test_7868.cpp b/libs/chrono/test/test_7868.cpp index 8e0136add..38f658b8c 100644 --- a/libs/chrono/test/test_7868.cpp +++ b/libs/chrono/test/test_7868.cpp @@ -29,7 +29,7 @@ int main() strm<<atnow<<std::endl; time_t t = boost::chrono::system_clock::to_time_t(atnow); std::cout << "A:" << std::endl; - puts(ctime(&t)); + std::puts(ctime(&t)); std::cout << "A:" << std::endl; std::cout << "A:" << strm.str()<< std::endl; std::cout << "A:" << atnow.time_since_epoch().count() << std::endl; |