summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2015-03-02 09:34:06 +0100
committerJohnny Willemsen <jwillemsen@remedy.nl>2015-03-02 09:34:06 +0100
commit4d7c7b9942feb3b772f3ba551e15eb5541e7aa4f (patch)
tree024b5cd1b9cdea3ffccff0fbcdbf2b45eff8d7a5
parentc9d1e750ed4b7f20ef9a15c6e001104797fb9e73 (diff)
parentaca78df9bed1a4433a33f558967d8c0002ca3dc8 (diff)
downloadATCD-4d7c7b9942feb3b772f3ba551e15eb5541e7aa4f.tar.gz
Merge pull request #18 from smitje/master
C++11 chrono support for sleep and ACE_Time_Value
-rw-r--r--ACE/NEWS8
-rw-r--r--ACE/ace/Time_Value.h127
-rw-r--r--ACE/ace/Time_Value.inl158
-rw-r--r--ACE/tests/Chrono_Test.cpp592
-rw-r--r--ACE/tests/run_test.lst1
-rw-r--r--ACE/tests/tests.mpc7
6 files changed, 890 insertions, 3 deletions
diff --git a/ACE/NEWS b/ACE/NEWS
index ca95cd212f7..ead8d8db44f 100644
--- a/ACE/NEWS
+++ b/ACE/NEWS
@@ -1,6 +1,14 @@
USER VISIBLE CHANGES BETWEEN ACE-6.3.1 and ACE-6.3.2
====================================================
+. Added support for std::chrono to ACE_Time_Value. It's
+ now possible to construct an ACE_Time_Value with a
+ std::duration. Also streaming, adding and substracting
+ an ACE_Time_Value to and from a std::duration is
+ supported. Please see tests/Chrono_Test.cpp for more
+ details.
+
+
USER VISIBLE CHANGES BETWEEN ACE-6.3.0 and ACE-6.3.1
====================================================
diff --git a/ACE/ace/Time_Value.h b/ACE/ace/Time_Value.h
index bb0351c97be..4f7b011a3b0 100644
--- a/ACE/ace/Time_Value.h
+++ b/ACE/ace/Time_Value.h
@@ -21,6 +21,10 @@
# include "ace/os_include/os_time.h"
+#if defined (ACE_HAS_CPP11)
+#include <chrono>
+#endif /* ACE_HAS_CPP11 */
+
// Define some helpful constants.
// Not type-safe, and signed. For backward compatibility.
#define ACE_ONE_SECOND_IN_MSECS 1000L
@@ -78,6 +82,15 @@ public:
/// Construct the ACE_Time_Value object from a timespec_t.
explicit ACE_Time_Value (const timespec_t &t);
+#if defined (ACE_HAS_CPP11)
+ /// Construct the ACE_Time_Value object from a chrono duration.
+ template< class Rep, class Period >
+ explicit ACE_Time_Value (const std::chrono::duration<Rep, Period>& duration)
+ {
+ this->set (duration);
+ }
+#endif /* ACE_HAS_CPP11 */
+
/// Destructor
virtual ~ACE_Time_Value ();
@@ -100,10 +113,25 @@ public:
void set (const timespec_t &t);
# if defined (ACE_WIN32)
- /// Initializes the ACE_Time_Value object from a Win32 FILETIME.
+ /// Initializes the ACE_Time_Value object from a Win32 FILETIME.
void set (const FILETIME &ft);
# endif /* ACE_WIN32 */
+#if defined (ACE_HAS_CPP11)
+ /// Initializes the ACE_Time_Value object from a std::duration.
+ template< class Rep, class Period >
+ void set (const std::chrono::duration<Rep, Period>& duration)
+ {
+ std::chrono::seconds const s {
+ std::chrono::duration_cast<std::chrono::seconds> (duration)};
+
+ std::chrono::microseconds const usec {
+ std::chrono::duration_cast<std::chrono::microseconds>(
+ duration % std::chrono::seconds (1))};
+ this->set (s.count (), usec.count ());
+ }
+#endif /* ACE_HAS_CPP11 */
+
/// Converts from ACE_Time_Value format into milliseconds format.
/**
* @return Sum of second field (in milliseconds) and microsecond field
@@ -232,10 +260,10 @@ public:
/// Add @a tv to this.
ACE_Time_Value &operator += (time_t tv);
- /// Assign @ tv to this
+ /// Assign @a tv to this
ACE_Time_Value &operator = (const ACE_Time_Value &tv);
- /// Assign @ tv to this
+ /// Assign @a tv to this
ACE_Time_Value &operator = (time_t tv);
/// Subtract @a tv to this.
@@ -244,6 +272,39 @@ public:
/// Subtract @a tv to this.
ACE_Time_Value &operator -= (time_t tv);
+#if defined (ACE_HAS_CPP11)
+ /// Add @a std::duration to this.
+ template< class Rep, class Period >
+ ACE_Time_Value &operator += (const std::chrono::duration<Rep, Period>& duration)
+ {
+ const ACE_Time_Value tv (duration);
+ this->sec (this->sec () + tv.sec ());
+ this->usec (this->usec () + tv.usec ());
+ this->normalize ();
+ return *this;
+ }
+
+ /// Assign @a std::duration to this
+ template< class Rep, class Period >
+ ACE_Time_Value &operator = (const std::chrono::duration<Rep, Period>& duration)
+ {
+ this->set (duration);
+ return *this;
+ }
+
+ /// Subtract @a std::duration to this.
+ template< class Rep, class Period >
+ ACE_Time_Value &operator -= (const std::chrono::duration<Rep, Period>& duration)
+ {
+ const ACE_Time_Value tv (duration);
+ this->sec (this->sec () - tv.sec ());
+ this->usec (this->usec () - tv.usec ());
+ this->normalize ();
+ return *this;
+ }
+#endif /* ACE_HAS_CPP11 */
+
+
/**
\brief Multiply the time value by the @a d factor.
\note The result of the operator is valid for results from range
@@ -410,6 +471,66 @@ extern ACE_Export ostream &operator<<( ostream &o, const ACE_Time_Value &v );
ACE_END_VERSIONED_NAMESPACE_DECL
+#if defined (ACE_HAS_CPP11)
+
+// Additional chrono operators.
+
+namespace std
+{
+ namespace chrono
+ {
+ /**
+ * @name Streaming ACE_Time_Value to chrono
+ *
+ * Streaming an ACE_Time_Value into one of the chrono types (nanoseconds,
+ * microseconds, milliseconds, seconds, minutes, or hours).
+ *
+ */
+ //@{
+ nanoseconds& operator <<(nanoseconds &ns, ACE_Time_Value const &tv);
+ microseconds& operator <<(microseconds &us, ACE_Time_Value const &tv);
+ milliseconds& operator <<(milliseconds &ms, ACE_Time_Value const &tv);
+ seconds& operator <<(seconds &s, ACE_Time_Value const &tv);
+ minutes& operator <<(minutes &m, ACE_Time_Value const &tv);
+ hours& operator <<(hours &h, ACE_Time_Value const &tv);
+ //@}
+
+ /**
+ * @name Adding ACE_Time_Value to chrono
+ *
+ * Adding an ACE_Time_Value to one of the chrono types (nanoseconds,
+ * microseconds, milliseconds, seconds, minutes, or hours).
+ *
+ */
+ //@{
+ nanoseconds& operator +=(nanoseconds &ns, ACE_Time_Value const &tv);
+ microseconds& operator +=(microseconds &us, ACE_Time_Value const &tv);
+ milliseconds& operator +=(milliseconds &ms, ACE_Time_Value const &tv);
+ seconds& operator +=(seconds &s, ACE_Time_Value const &tv);
+ minutes& operator +=(minutes &m, ACE_Time_Value const &tv);
+ hours& operator +=(hours &h, ACE_Time_Value const &tv);
+ //@}
+
+ /**
+ * @name Substracting ACE_Time_Value from chrono
+ *
+ * Substracting an ACE_Time_Value from one of the chrono types (nanoseconds,
+ * microseconds, milliseconds, seconds, minutes, or hours).
+ *
+ */
+ //@{
+ nanoseconds& operator -=(nanoseconds &ns, ACE_Time_Value const &tv);
+ microseconds& operator -=(microseconds &us, ACE_Time_Value const &tv);
+ milliseconds& operator -=(milliseconds &ms, ACE_Time_Value const &tv);
+ seconds& operator -=(seconds &s, ACE_Time_Value const &tv);
+ minutes& operator -=(minutes &m, ACE_Time_Value const &tv);
+ hours& operator -=(hours &h, ACE_Time_Value const &tv);
+ //@}
+ }
+}
+
+#endif /* ACE_HAS_CPP11 */
+
#if defined (__ACE_INLINE__)
#include "ace/Time_Value.inl"
#endif /* __ACE_INLINE__ */
diff --git a/ACE/ace/Time_Value.inl b/ACE/ace/Time_Value.inl
index eaed073f45d..a4b095033e7 100644
--- a/ACE/ace/Time_Value.inl
+++ b/ACE/ace/Time_Value.inl
@@ -393,3 +393,161 @@ operator - (const ACE_Time_Value &tv1,
}
ACE_END_VERSIONED_NAMESPACE_DECL
+
+#if defined (ACE_HAS_CPP11)
+
+// Additional chrono streaming operators.
+
+namespace std
+{
+ namespace chrono
+ {
+ ACE_INLINE nanoseconds&
+ operator <<(nanoseconds &ns, ACE_Time_Value const &tv)
+ {
+ ns = duration_cast<nanoseconds>(seconds{tv.sec ()}) +
+ duration_cast<nanoseconds>(microseconds{tv.usec()});
+ return ns;
+ }
+
+ ACE_INLINE microseconds&
+ operator <<(microseconds &us, ACE_Time_Value const &tv)
+ {
+ us= duration_cast<microseconds>(seconds{tv.sec ()}) +
+ microseconds{tv.usec()};
+ return us;
+ }
+
+ ACE_INLINE milliseconds&
+ operator <<(milliseconds &ms, ACE_Time_Value const &tv)
+ {
+ ms = duration_cast<milliseconds>(seconds{tv.sec ()}) +
+ duration_cast<milliseconds>(microseconds{tv.usec()});
+ return ms;
+ }
+
+ ACE_INLINE seconds&
+ operator <<(seconds &s, ACE_Time_Value const &tv)
+ {
+ s = seconds{tv.sec ()} +
+ duration_cast<seconds>(microseconds{tv.usec()});
+ return s;
+ }
+
+ ACE_INLINE minutes&
+ operator <<(minutes &m, ACE_Time_Value const &tv)
+ {
+ m = duration_cast<minutes>(seconds{tv.sec ()}) +
+ duration_cast<minutes>(microseconds{tv.usec()});
+ return m;
+ }
+
+ ACE_INLINE hours&
+ operator <<(hours &h, ACE_Time_Value const &tv)
+ {
+ h = duration_cast<hours>(seconds{tv.sec ()}) +
+ duration_cast<hours>(microseconds{tv.usec()});
+ return h;
+ }
+
+
+ ACE_INLINE nanoseconds&
+ operator +=(nanoseconds &ns, ACE_Time_Value const &tv)
+ {
+ ns += duration_cast<nanoseconds>(seconds{tv.sec ()}) +
+ duration_cast<nanoseconds>(microseconds{tv.usec()});
+ return ns;
+ }
+
+ ACE_INLINE microseconds&
+ operator +=(microseconds &us, ACE_Time_Value const &tv)
+ {
+ us += duration_cast<microseconds>(seconds{tv.sec ()}) +
+ microseconds{tv.usec()};
+ return us;
+ }
+
+ ACE_INLINE milliseconds&
+ operator +=(milliseconds &ms, ACE_Time_Value const &tv)
+ {
+ ms += duration_cast<milliseconds>(seconds{tv.sec ()}) +
+ duration_cast<milliseconds>(microseconds{tv.usec()});
+ return ms;
+ }
+
+ ACE_INLINE seconds&
+ operator +=(seconds &s, ACE_Time_Value const &tv)
+ {
+ s += seconds{tv.sec ()} +
+ duration_cast<seconds>(microseconds{tv.usec()});
+ return s;
+ }
+
+ ACE_INLINE minutes&
+ operator +=(minutes &m, ACE_Time_Value const &tv)
+ {
+ m += duration_cast<minutes>(seconds{tv.sec ()}) +
+ duration_cast<minutes>(microseconds{tv.usec()});
+ return m;
+ }
+
+ ACE_INLINE hours&
+ operator +=(hours &h, ACE_Time_Value const &tv)
+ {
+ h += duration_cast<hours>(seconds{tv.sec ()}) +
+ duration_cast<hours>(microseconds{tv.usec()});
+ return h;
+ }
+
+
+ ACE_INLINE nanoseconds&
+ operator -=(nanoseconds &ns, ACE_Time_Value const &tv)
+ {
+ ns -= duration_cast<nanoseconds>(seconds{tv.sec ()}) +
+ duration_cast<nanoseconds>(microseconds{tv.usec()});
+ return ns;
+ }
+
+ ACE_INLINE microseconds&
+ operator -=(microseconds &us, ACE_Time_Value const &tv)
+ {
+ us -= duration_cast<microseconds>(seconds{tv.sec ()}) +
+ microseconds{tv.usec()};
+ return us;
+ }
+
+ ACE_INLINE milliseconds&
+ operator -=(milliseconds &ms, ACE_Time_Value const &tv)
+ {
+ ms -= duration_cast<milliseconds>(seconds{tv.sec ()}) +
+ duration_cast<milliseconds>(microseconds{tv.usec()});
+ return ms;
+ }
+
+ ACE_INLINE seconds&
+ operator -=(seconds &s, ACE_Time_Value const &tv)
+ {
+ s -= seconds{tv.sec ()} +
+ duration_cast<seconds>(microseconds{tv.usec()});
+ return s;
+ }
+
+ ACE_INLINE minutes&
+ operator -=(minutes &m, ACE_Time_Value const &tv)
+ {
+ m -= duration_cast<minutes>(seconds{tv.sec ()}) +
+ duration_cast<minutes>(microseconds{tv.usec()});
+ return m;
+ }
+
+ ACE_INLINE hours&
+ operator -=(hours &h, ACE_Time_Value const &tv)
+ {
+ h -= duration_cast<hours>(seconds{tv.sec ()}) +
+ duration_cast<hours>(microseconds{tv.usec()});
+ return h;
+ }
+ }
+}
+
+#endif /* ACE_HAS_CPP11 */
diff --git a/ACE/tests/Chrono_Test.cpp b/ACE/tests/Chrono_Test.cpp
new file mode 100644
index 00000000000..1963fce7824
--- /dev/null
+++ b/ACE/tests/Chrono_Test.cpp
@@ -0,0 +1,592 @@
+
+//=============================================================================
+/**
+ * @file Chrono_Test.cpp
+ *
+ * This is a test of the usage of 'std::chrono' throughout ACE
+ * The following items are tested:
+ * - ACE_OS::sleep
+ * - ACE_Time_Value
+ *
+ *
+ * @author Marcel Smit <msmit@remedy.nl>
+ */
+//=============================================================================
+
+
+#include "test_config.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/Time_Value.h"
+
+#if defined (ACE_HAS_CPP11)
+
+int
+test_assignments ()
+{
+ int errors {};
+ ACE_Time_Value tv { std::chrono::nanoseconds {100} };
+ if (tv.sec () != 0 || tv.usec () != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::nanoseconds (100) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=0,usec=0> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::nanoseconds {10005} };
+ if (tv.sec () != 0 || tv.usec () != 10)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::nanoseconds (10005) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=0,usec=10> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::microseconds {1} };
+ if (tv.sec () != 0 || tv.usec () != 1)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::microseconds (1) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=0,usec=1> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::microseconds {10005} };
+ if (tv.sec () != 0 || tv.usec () != 10005)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::microseconds (10005) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=0,usec=10005> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ std::chrono::milliseconds ms_test { tv.msec () };
+ if (ms_test.count () != 10)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after get_chrono_msec. ")
+ ACE_TEXT ("Expected <10> - got <%q>\n"),
+ ms_test.count ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::milliseconds {1} };
+ if (tv.sec () != 0 || tv.usec () != 1000)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::milliseconds (1) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=0,usec=1000> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::milliseconds {10005} };
+ if (tv.sec () != 10 || tv.usec () != 5000)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::milliseconds (10005) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=10,usec=5000> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::seconds {1} };
+ if (tv.sec () != 1 || tv.usec () != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::seconds (1) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=1,usec=0> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::seconds {10005} };
+ if (tv.sec () != 10005 || tv.usec () != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::seconds (10005) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=10005,usec=0> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::hours {1} };
+ if (tv.sec () != 3600 || tv.usec () != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::hours (1) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=3600,usec=0> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv = ACE_Time_Value { std::chrono::hours {10005} };
+ if (tv.sec () != 3600*10005 || tv.usec () != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("std::chrono::hours (10005) to an ACE_Time_Value. ")
+ ACE_TEXT ("<sec=%d,usec=0> - got <sec=%d,usec=%d>\n"),
+ 3600*10005, tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ // Two times half a day, 3 hours, 24 minutes, 54 seconds, 238 milliseconds,
+ // 754 microseconds and 342 nanoseconds.
+ std::chrono::duration<double, std::ratio<(24*3600)>> half_day {0.5};
+ std::chrono::microseconds const usec {
+ 2 * (
+ std::chrono::duration_cast<std::chrono::microseconds> (
+ half_day +
+ std::chrono::hours {3} + std::chrono::minutes {24} +
+ std::chrono::seconds {54} + std::chrono::milliseconds {238} +
+ std::chrono::microseconds {754} + std::chrono::nanoseconds {342}))
+ };
+
+
+ tv = ACE_Time_Value {usec};
+
+ // half a day 3 hours 24 minutes 54 seconds
+ time_t expected_sec = { ((12*3600) + (3*3600) + (24*60) + 54 ) * 2 };
+ // 238 milli usec 342 nano
+ suseconds_t expected_usec = { ((238*1000) + 754 + 0) * 2 };
+
+ if (tv.sec () != expected_sec || tv.usec () != expected_usec)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("two times half a day, 3 hours, 24 minutes, 54 seconds, ")
+ ACE_TEXT ("238 milliseconds, 754 microseconds and 342 nanoseconds ")
+ ACE_TEXT ("to an ACE_Time_Value. Expected <sec=%d,usec=%d> - ")
+ ACE_TEXT ("got <sec=%d,usec=%d>\n"),
+ expected_sec, expected_usec, tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ tv.set (std::chrono::milliseconds {1120});
+ if (tv.sec () != 1 || tv.usec () != 120 * std::kilo::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after converting ")
+ ACE_TEXT ("a std::chrono::milliseconds of 1120 to an ACE_Time_Value ")
+ ACE_TEXT ("Expected <sec=1,usec=120000> - got <sec=%d,usec=%d>\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+
+ return errors;
+}
+
+int
+test_streamers ()
+{
+ int errors {};
+
+ // Three days, 13 hours, 54 seconds, 25 milliseconds and 132 microseconds
+ constexpr int nr_hours { (3*24) + 13 };
+
+ std::chrono::hours day_test_h {nr_hours};
+ std::chrono::seconds day_test_s {54};
+ std::chrono::milliseconds day_test_ms {25};
+ std::chrono::microseconds day_test_us {132};
+
+ std::chrono::seconds day_test_ts { day_test_h+day_test_s };
+ std::chrono::microseconds day_test_tus { day_test_ms+day_test_us };
+ ACE_Time_Value const test_day {
+ ACE_Time_Value { day_test_ts.count (), day_test_tus.count () }};
+
+ constexpr int expected_min {nr_hours * 60};
+ constexpr int64_t expected_sec { expected_min * 60 + 54 };
+ constexpr int64_t expected_msec { (expected_sec * std::kilo::num) + 25 };
+ constexpr int64_t expected_usec { (expected_msec * std::kilo::num) + 132 };
+ constexpr int64_t expected_nsec { (expected_usec * std::kilo::num) };
+
+ std::chrono::hours h;
+ h << test_day;
+ if (h.count () != nr_hours)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::hours. Expected <%d> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), nr_hours, h.count ()));
+ ++errors;
+ }
+
+ std::chrono::minutes m;
+ m << test_day;
+ if (m.count () != expected_min)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::minutes. Expected <%d> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), expected_min, m.count ()));
+ ++errors;
+ }
+
+ std::chrono::seconds s;
+ s << test_day;
+ if (s.count () != expected_sec)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::seconds. Expected <%q> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), expected_sec, s.count ()));
+ ++errors;
+ }
+
+ std::chrono::milliseconds ms;
+ ms << test_day;
+ if (ms.count () != expected_msec)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::milliseconds. Expected <%q> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), expected_msec, ms.count ()));
+ ++errors;
+ }
+
+ std::chrono::microseconds us;
+ us << test_day;
+ if (us.count () != expected_usec)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::microseconds. Expected <%q> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), expected_usec, us.count ()));
+ ++errors;
+ }
+
+ std::chrono::nanoseconds ns;
+ ns << test_day;
+ if (ns.count () != expected_nsec)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::nanoseconds. Expected <%q> - got <%q>.\n"),
+ test_day.sec (), test_day.usec (), expected_nsec, ns.count ()));
+ ++errors;
+ }
+
+
+
+ ACE_Time_Value const test_sec {12, 132};
+ // Seconds
+ s << test_sec;
+ if (s.count () != 12)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::seconds. Expected <%d> - got <%q>.\n"),
+ test_sec.sec (), test_sec.usec (), test_sec.sec (), s.count ()));
+ ++errors;
+ }
+
+ ACE_Time_Value const test_sec2 { ACE_Time_Value {12, 6 * std::mega::num} };
+ std::chrono::seconds s2;
+ s2 << test_sec2;
+ if (s2.count () != 18)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::seconds. Expected <%d> - got <%q>.\n"),
+ test_sec2.sec (), test_sec2.usec (), test_sec2.sec (), s2.count ()));
+ ++errors;
+ }
+
+ // Milliseconds
+ ms << test_sec;
+ if (ms.count () != 12 * std::kilo::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::milliseconds. Expected <%d> - got <%q>.\n"),
+ test_sec.sec (), test_sec.usec (), 12000, ms.count ()));
+ ++errors;
+ }
+
+ std::chrono::milliseconds ms2;
+ ms2 << test_sec2;
+ if (ms2.count () != 18 * std::kilo::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::milliseconds. Expected <%d> - got <%q>.\n"),
+ test_sec2.sec (), test_sec2.usec (), 18000, ms2.count ()));
+ ++errors;
+ }
+
+ // Microseconds
+ us << test_sec;
+ if (us.count () != (12 * std::mega::num) + 132)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::microseconds. Expected <%d> - got <%q>.\n"),
+ test_sec.sec (), test_sec.usec (), test_sec.sec (), us.count ()));
+ ++errors;
+ }
+
+ std::chrono::microseconds us2;
+ us2 << test_sec2;
+ if (us2.count () != 18 * std::mega::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after streaming an ")
+ ACE_TEXT ("ACE_Time_Value <sec=%d,usec=%d> into ")
+ ACE_TEXT ("std::chrono::microseconds. Expected <%d> - got <%q>.\n"),
+ test_sec2.sec (), test_sec2.usec (), test_sec2.sec (), us2.count ()));
+ ++errors;
+ }
+
+ return errors;
+}
+
+int
+test_ace_time_value_operators ()
+{
+ int errors {};
+
+ std::chrono::seconds const sec {2};
+ std::chrono::microseconds const usec {3000};
+
+ std::chrono::milliseconds const msec {
+ std::chrono::duration_cast<std::chrono::milliseconds>(sec) +
+ std::chrono::duration_cast<std::chrono::milliseconds>(usec) };
+
+
+ ACE_Time_Value tv;
+ tv = msec;
+ tv += std::chrono::milliseconds {300};
+ if (tv.sec () != 2 || tv.usec () != 303 * std::kilo::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding a duration ")
+ ACE_TEXT ("of 300 ms. Expected <sec=2,usec=3300> - got <sec=%d,")
+ ACE_TEXT ("usec=%d>.\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+ tv -= std::chrono::microseconds {400};
+ if (tv.sec () != 2 || tv.usec () != 302600)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting a duration ")
+ ACE_TEXT ("of 400 us. Expected <sec=2,usec=3300> - got <sec=%d,")
+ ACE_TEXT ("usec=%d>.\n"),
+ tv.sec (), tv.usec ()));
+ ++errors;
+ }
+ return errors;
+}
+
+int
+test_chrono_operators ()
+{
+ int errors {};
+
+ std::chrono::hours hr {1};
+ ACE_Time_Value const tv_hr {3645, 0};
+ hr += tv_hr;
+ if (hr.count () != 2)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::hours of 1. ")
+ ACE_TEXT ("Expected <2> - got <%d>.\n"),
+ tv_hr.sec (), tv_hr.usec (), hr.count ()));
+ ++errors;
+ }
+
+ hr -= tv_hr;
+ if (hr.count () != 1)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::hours of 2. ")
+ ACE_TEXT ("Expected <1> - got <%d>.\n"),
+ tv_hr.sec (), tv_hr.usec (), hr.count ()));
+ ++errors;
+ }
+
+
+ std::chrono::minutes mn {1};
+ ACE_Time_Value const tv_min {75, 0};
+ mn += tv_min;
+ if (mn.count () != 2)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::minutes of 1. ")
+ ACE_TEXT ("Expected <2> - got <%d>.\n"),
+ tv_min.sec (), tv_min.usec (), mn.count ()));
+ ++errors;
+ }
+
+ mn -= tv_min;
+ if (mn.count () != 1)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::minutes of 2. ")
+ ACE_TEXT ("Expected <1> - got <%d>.\n"),
+ tv_min.sec (), tv_min.usec (), mn.count ()));
+ ++errors;
+ }
+
+ std::chrono::seconds sec {1};
+ ACE_Time_Value const tv_sec {1, std::mega::num};
+ sec += tv_sec;
+ if (sec.count () != 3)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::seconds of 1. ")
+ ACE_TEXT ("Expected <3> - got <%d>.\n"),
+ tv_sec.sec (), tv_sec.usec (), sec.count ()));
+ ++errors;
+ }
+
+ sec -= tv_sec;
+ if (sec.count () != 1)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::seconds of 3. ")
+ ACE_TEXT ("Expected <1> - got <%d>.\n"),
+ tv_sec.sec (), tv_sec.usec (), sec.count ()));
+ ++errors;
+ }
+
+ std::chrono::milliseconds msec {400};
+ ACE_Time_Value const tv_msec {1, 3000};
+ msec += tv_msec;
+ if (msec.count () != 1403)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::milliseconds of 400. ")
+ ACE_TEXT ("Expected <1403> - got <%d>.\n"),
+ tv_msec.sec (), tv_msec.usec (), msec.count ()));
+ ++errors;
+ }
+
+ msec -= tv_msec;
+ if (msec.count () != 400)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::milliseconds of 1403. ")
+ ACE_TEXT ("Expected <400> - got <%d>.\n"),
+ tv_msec.sec (), tv_msec.usec (), msec.count ()));
+ ++errors;
+ }
+
+ std::chrono::microseconds usec {400};
+ ACE_Time_Value const tv_usec {0, 3000};
+ usec += tv_usec;
+ if (usec.count () != 3400)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::microseconds of 400. ")
+ ACE_TEXT ("Expected <3400> - got <%d>.\n"),
+ tv_usec.sec (), tv_usec.usec (), usec.count ()));
+ ++errors;
+ }
+
+ usec -= tv_usec;
+ if (usec.count () != 400)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::microseconds of 3400. ")
+ ACE_TEXT ("Expected <400> - got <%d>.\n"),
+ tv_usec.sec (), tv_usec.usec (), usec.count ()));
+ ++errors;
+ }
+
+ std::chrono::nanoseconds nsec {4000};
+ nsec += tv_usec;
+ if (nsec.count () != 3004 * std::kilo::num)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after adding an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::nanoseconds of 4000. ")
+ ACE_TEXT ("Expected <3004000> - got <%d>.\n"),
+ tv_usec.sec (), tv_usec.usec (), nsec.count ()));
+ ++errors;
+ }
+
+ nsec -= tv_usec;
+ if (nsec.count () != 4000)
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) unexpected value after substracting an ACE_Time_Value ")
+ ACE_TEXT ("of <sec=%d,usec=%d> to a std::chrono::nanoseconds of 3004000. ")
+ ACE_TEXT ("Expected <4000> - got <%d>.\n"),
+ tv_usec.sec (), tv_usec.usec (), nsec.count ()));
+ ++errors;
+ }
+
+ return errors;
+}
+
+int
+test_chrono ()
+{
+ int errors = test_assignments ();
+ errors += test_streamers ();
+ errors += test_ace_time_value_operators ();
+ errors += test_chrono_operators ();
+ return errors;
+}
+
+int
+run_main (int, ACE_TCHAR *[])
+{
+ ACE_START_TEST (ACE_TEXT ("Chrono_Test"));
+
+ int errors = test_chrono ();
+
+ ACE_END_TEST;
+ return errors;
+}
+
+#else
+
+int
+run_main (int, ACE_TCHAR *[])
+{
+ ACE_START_TEST (ACE_TEXT ("Chrono_Test"));
+
+ ACE_ERROR ((LM_INFO, ACE_TEXT ("std::chrono is not supported on this platform\n")));
+
+ ACE_END_TEST;
+ return 0;
+}
+
+#endif /* ACE_HAS_CPP11 */
diff --git a/ACE/tests/run_test.lst b/ACE/tests/run_test.lst
index 3a376fe34c5..8e4bb4a230d 100644
--- a/ACE/tests/run_test.lst
+++ b/ACE/tests/run_test.lst
@@ -70,6 +70,7 @@ Bug_4189_Regression_Test: !ST
CDR_Array_Test: !ACE_FOR_TAO
CDR_File_Test: !ACE_FOR_TAO
CDR_Test
+Chrono_Test
Cache_Map_Manager_Test
Cached_Accept_Conn_Test: !ACE_FOR_TAO !LabVIEW_RT
Cached_Allocator_Test: !ACE_FOR_TAO
diff --git a/ACE/tests/tests.mpc b/ACE/tests/tests.mpc
index e45e143ccc4..adb95592aa6 100644
--- a/ACE/tests/tests.mpc
+++ b/ACE/tests/tests.mpc
@@ -544,6 +544,13 @@ project(CDR Test) : acetest {
}
}
+project(Chrono Test) : acetest {
+ exename = Chrono_Test
+ Source_Files {
+ Chrono_Test.cpp
+ }
+}
+
project(Collection Test) : acetest {
exename = Collection_Test
Source_Files {