2 * timestructs.cpp -- test bed adaptors for time structs.
4 * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
5 * The contents of 'html/copyright.html' apply.
7 #include "g_libntptest.h"
8 #include "g_timestructs.h"
12 #include "timevalops.h"
13 #include "timespecops.h"
16 namespace timeStruct {
19 operator << (std::ostream& os, const timeStruct::l_fp_wrap& val)
21 // raw data formatting
22 os << "0x" << std::hex << val.V.l_ui << ':'
23 << std::setfill('0') << std::setw(8) << val.V.l_uf
25 // human-readable format
26 os << '[' << lfptoa(&val.V, 10) << ']';
31 operator << (std::ostream& os, const timeStruct::timeval_wrap& val)
33 // raw data formatting
34 os << val.V.tv_sec << ':' << val.V.tv_usec;
35 // human-readable format
37 << format_time_fraction(val.V.tv_sec, val.V.tv_usec, 6)
43 operator << (std::ostream& os, const timeStruct::timespec_wrap& val)
45 // raw data formatting
46 os << val.V.tv_sec << ':' << val.V.tv_nsec;
47 // human-readable format
49 << format_time_fraction(val.V.tv_sec, val.V.tv_nsec, 9)
54 // Implementation of the l_fp closeness predicate
56 AssertFpClose::AssertFpClose(
65 ::testing::AssertionResult
66 AssertFpClose::operator()(
75 if (L_ISGEQ(&m, &n)) {
82 if (L_ISGEQ(&limit, &diff))
83 return ::testing::AssertionSuccess();
85 return ::testing::AssertionFailure()
86 << m_expr << " which is " << l_fp_wrap(m)
88 << n_expr << " which is " << l_fp_wrap(n)
89 << "\nare not close; diff=" << l_fp_wrap(diff);
92 // Implementation of the timeval closeness predicate
94 AssertTimevalClose::AssertTimevalClose(
103 ::testing::AssertionResult
104 AssertTimevalClose::operator()(
107 const struct timeval & m,
108 const struct timeval & n
113 diff = abs_tval(sub_tval(m, n));
114 if (cmp_tval(limit, diff) >= 0)
115 return ::testing::AssertionSuccess();
117 return ::testing::AssertionFailure()
118 << m_expr << " which is " << timeval_wrap(m)
120 << n_expr << " which is " << timeval_wrap(n)
121 << "\nare not close; diff=" << timeval_wrap(diff);
124 // Implementation of the timespec closeness predicate
126 AssertTimespecClose::AssertTimespecClose(
135 ::testing::AssertionResult
136 AssertTimespecClose::operator()(
139 const struct timespec & m,
140 const struct timespec & n
143 struct timespec diff;
145 diff = abs_tspec(sub_tspec(m, n));
146 if (cmp_tspec(limit, diff) >= 0)
147 return ::testing::AssertionSuccess();
149 return ::testing::AssertionFailure()
150 << m_expr << " which is " << timespec_wrap(m)
152 << n_expr << " which is " << timespec_wrap(n)
153 << "\nare not close; diff=" << timespec_wrap(diff);
156 } // namespace timeStruct