From 0430b1a5da8b28e69c65304e0f5bc3e849ab17bd Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 1 Mar 2010 16:52:37 +0100 Subject: [PATCH] [Positioning] Redesign Timestamp Use almost only operators for the public interface. --- owlps-positioning/TODO | 7 +- owlps-positioning/src/inputlogcsv.cc | 2 +- owlps-positioning/src/request.cc | 2 +- owlps-positioning/src/request.hh | 2 +- owlps-positioning/src/timestamp.cc | 127 +++++++----- owlps-positioning/src/timestamp.hh | 193 ++++++++++++++---- .../tests/calibrationrequest_test.hh | 2 +- owlps-positioning/tests/request_test.hh | 2 +- owlps-positioning/tests/testutil.cc | 6 +- owlps-positioning/tests/timestamp_test.hh | 143 ++++++++++--- 10 files changed, 351 insertions(+), 135 deletions(-) diff --git a/owlps-positioning/TODO b/owlps-positioning/TODO index 41f1500..3d28104 100644 --- a/owlps-positioning/TODO +++ b/owlps-positioning/TODO @@ -44,10 +44,9 @@ principes exposés dans le chapitre 6 (p. 103) : implanter systématiquement des accesseurs pour tous les attributs d'une classe expose l'implantation de la classe et rend ses attributs - publics. La classe Direction tend à respecter ce principe en - utilisant mieux les opérateurs et en ne proposant pas d'accesseur - direct. La classe Timestamp serait facile à modifier de cette - manière. + publics. La classe Direction (et maintenant Timestamp) tend à + respecter ce principe en utilisant mieux les opérateurs et en ne + proposant pas d'accesseur direct. - Divers ° Passage de pointeurs en argument : const * const diff --git a/owlps-positioning/src/inputlogcsv.cc b/owlps-positioning/src/inputlogcsv.cc index 2643459..7b85a59 100644 --- a/owlps-positioning/src/inputlogcsv.cc +++ b/owlps-positioning/src/inputlogcsv.cc @@ -58,7 +58,7 @@ const string InputLogCSV::request_to_csv(const Request &request) const ostringstream csv_line ; if (request.get_mobile() != NULL) csv_line << request.get_mobile()->get_mac_addr() ; - csv_line << ';' << request.get_timestamp().get_timestamp_ms() << ';' ; + csv_line << ';' << request.get_timestamp() << ';' ; const CalibrationRequest *calibration_request = dynamic_cast(&request) ; diff --git a/owlps-positioning/src/request.cc b/owlps-positioning/src/request.cc index 077934a..87d15b0 100644 --- a/owlps-positioning/src/request.cc +++ b/owlps-positioning/src/request.cc @@ -64,7 +64,7 @@ Request::~Request() void Request::clear() { mobile = NULL ; - timestamp.set_timestamp_ms(0) ; + timestamp.clear() ; measurements.clear() ; } diff --git a/owlps-positioning/src/request.hh b/owlps-positioning/src/request.hh index 40e867d..c0861d3 100644 --- a/owlps-positioning/src/request.hh +++ b/owlps-positioning/src/request.hh @@ -145,7 +145,7 @@ inline Request::operator bool() const { return mobile != NULL || - timestamp.get_timestamp_ms() != 0 || + timestamp || measurements.size() > 0 ; } diff --git a/owlps-positioning/src/timestamp.cc b/owlps-positioning/src/timestamp.cc index 7d17e9b..3fb8974 100644 --- a/owlps-positioning/src/timestamp.cc +++ b/owlps-positioning/src/timestamp.cc @@ -7,46 +7,40 @@ Timestamp::Timestamp() { - timestamp.tv_sec = 0 ; - timestamp.tv_nsec = 0 ; + clear() ; } Timestamp::Timestamp(const struct timespec &source) { - set_timestamp(source) ; + set(source) ; round_to_ms() ; } -Timestamp::Timestamp(const uint64_t source_ms) +Timestamp::Timestamp(const uint64_t source) { - set_timestamp_ms(source_ms) ; + set(source) ; } Timestamp::Timestamp(const Timestamp &source) { - timestamp.tv_sec = source.timestamp.tv_sec ; - timestamp.tv_nsec = source.timestamp.tv_nsec ; + set(source.timestamp) ; } -/* *** Read accessors *** */ +/* *** Internal accessors *** */ -uint64_t Timestamp::get_timestamp_ms(void) const +inline void Timestamp::set(const struct timespec &source) { - return timestamp.tv_sec * 1000 + timestamp.tv_nsec / 1000000 ; + timestamp = source ; } - -/* *** Write accessors *** */ - - -void Timestamp::set_timestamp_ms(const uint64_t source_ms) +inline void Timestamp::set(const uint64_t source_ms) { timestamp.tv_sec = source_ms / 1000 ; timestamp.tv_nsec = (source_ms - timestamp.tv_sec * 1000) * 1000000 ; @@ -57,24 +51,6 @@ void Timestamp::set_timestamp_ms(const uint64_t source_ms) /* *** Operations *** */ -bool Timestamp::now_ns() -{ - if (clock_gettime(CLOCK_REALTIME, ×tamp)) - return false ; - return true ; -} - - -/** - * #timestamp nanosecond field precision is set to ms, but the value - * is still in ns. - */ -void Timestamp::round_to_ms() -{ - timestamp.tv_nsec = timestamp.tv_nsec / 1000000 * 1000000 ; -} - - bool Timestamp::now() { if (! now_ns()) @@ -85,6 +61,65 @@ bool Timestamp::now() } +inline bool Timestamp::now_ns() +{ + return clock_gettime(CLOCK_REALTIME, ×tamp) == 0 ; +} + + +/** + * #timestamp nanosecond field precision is set to ms, but the value + * is still in ns. + */ +inline void Timestamp::round_to_ms() +{ + timestamp.tv_nsec = timestamp.tv_nsec / 1000000 * 1000000 ; +} + + + +/* *** Internal comparison functions *** */ + + +bool Timestamp::equals(const struct timespec &source) const +{ + return + timestamp.tv_sec == source.tv_sec && + timestamp.tv_nsec == source.tv_nsec ; +} + + +bool Timestamp::equals(const uint64_t source) const +{ + Timestamp tmp(source) ; + return equals(tmp.timestamp) ; +} + + +bool Timestamp::less_than(const struct timespec &source) const +{ + if (timestamp.tv_sec < source.tv_sec) + return true ; + + if (timestamp.tv_sec > source.tv_sec) + return false ; + + // Second values are equal + if (timestamp.tv_nsec < source.tv_nsec) + return true ; + + return false ; +} + + +bool Timestamp::greater_than(const struct timespec &source) const +{ + if (equals(source)) + return false ; + return ! less_than(source) ; +} + + /* *** Operators *** */ @@ -94,8 +129,7 @@ const Timestamp& Timestamp::operator=(const Timestamp &source) if (this == &source) return *this ; - timestamp.tv_sec = source.timestamp.tv_sec ; - timestamp.tv_nsec = source.timestamp.tv_nsec ; + set(source.timestamp) ; return *this ; } @@ -105,32 +139,13 @@ bool Timestamp::operator==(const Timestamp &source) const { if (this == &source) return true ; - - return - timestamp.tv_sec == source.timestamp.tv_sec && - timestamp.tv_nsec == source.timestamp.tv_nsec ; -} - - -bool Timestamp::operator<(const Timestamp &source) const -{ - if (timestamp.tv_sec < source.timestamp.tv_sec) - return true ; - - if (timestamp.tv_sec > source.timestamp.tv_sec) - return false ; - - // Second values are equal - if (timestamp.tv_nsec < source.timestamp.tv_nsec) - return true ; - - return false ; + return equals(source.timestamp) ; } std::ostream& operator<<(std::ostream &os, const Timestamp &t) { - os << t.get_timestamp_ms() ; + os << static_cast(t) ; return os ; } diff --git a/owlps-positioning/src/timestamp.hh b/owlps-positioning/src/timestamp.hh index 177d7bd..1dc1706 100644 --- a/owlps-positioning/src/timestamp.hh +++ b/owlps-positioning/src/timestamp.hh @@ -16,6 +16,21 @@ protected: /// Time data struct timespec timestamp ; + /** @name Internal accessors */ + //@{ + void set(const struct timespec &source) ; + /// Initialises the Timestamp with a value in milliseconds + void set(const uint64_t source_ms) ; + //@} + + /** @name Comparison functions */ + //@{ + bool equals(const struct timespec &source) const ; + bool equals(const uint64_t source) const ; + bool less_than(const struct timespec &source) const ; + bool greater_than(const struct timespec &source) const ; + //@} + /** @name Operations */ //@{ /// \brief Initialises #timestamp at the current time whith a @@ -27,49 +42,47 @@ protected: public: - /// Default constructor Timestamp(void) ; - /// Constructs a Timestamp from a struct timespec Timestamp(const struct timespec &source) ; /// Constructs a Timsestamp from a value in milliseconds - Timestamp(const uint64_t source_ms) ; - /// Copy constructor + Timestamp(const uint64_t source) ; Timestamp(const Timestamp &source) ; - ~Timestamp(void) {} ///< Destructor (do nothing) + ~Timestamp(void) {} - /** @name Read accessors */ - //@{ - /// #timestamp read accessor - const struct timespec& get_timestamp(void) const ; - /// Get the #timestamp in milliseconds - uint64_t get_timestamp_ms(void) const ; - //@} - - /** @name Write accessors */ - //@{ - /// #timestamp write accessor - void set_timestamp(const struct timespec &source) ; - /// #timestamp write accessor with a value in milliseconds - void set_timestamp_ms(const uint64_t source_ms) ; - //@} - - /** @name Operations */ - //@{ /// \brief Initialises #timestamp to the current time with a /// millisecond precision bool now(void) ; - //@} + + void clear(void) ; /** @name Operators */ //@{ const Timestamp& operator=(const Timestamp &source) ; + const Timestamp& operator=(const struct timespec &source) ; + const Timestamp& operator=(const uint64_t source) ; bool operator==(const Timestamp &source) const ; + bool operator==(const struct timespec &source) const ; + bool operator==(const uint64_t source) const ; bool operator!=(const Timestamp &source) const ; + bool operator!=(const struct timespec &source) const ; + bool operator!=(const uint64_t source) const ; bool operator<(const Timestamp &source) const ; + bool operator<(const struct timespec &source) const ; + bool operator<(const uint64_t source) const ; bool operator>(const Timestamp &source) const ; + bool operator>(const struct timespec &source) const ; + bool operator>(const uint64_t source) const ; bool operator<=(const Timestamp &source) const ; + bool operator<=(const struct timespec &source) const ; + bool operator<=(const uint64_t source) const ; bool operator>=(const Timestamp &source) const ; + bool operator>=(const struct timespec &source) const ; + bool operator>=(const uint64_t source) const ; + operator bool(void) const ; + operator const struct timespec&(void) const ; + /// Cast to milliseconds + operator uint64_t(void) const ; //@} /// Display a Timestamp @@ -78,22 +91,10 @@ public: -/* *** Read accessors *** */ - - -inline const struct timespec& Timestamp::get_timestamp() const +inline void Timestamp::clear(void) { - return timestamp ; -} - - - -/* *** Write accessors *** */ - - -inline void Timestamp::set_timestamp(const struct timespec &source) -{ - timestamp = source ; + timestamp.tv_sec = 0 ; + timestamp.tv_nsec = 0 ; } @@ -101,15 +102,84 @@ inline void Timestamp::set_timestamp(const struct timespec &source) /* *** Operators *** */ +inline const Timestamp& Timestamp:: +operator=(const struct timespec &source) +{ + set(source) ; + return *this ; +} + + +inline const Timestamp& Timestamp::operator=(const uint64_t source) +{ + set(source) ; + return *this ; +} + + +inline bool Timestamp::operator==(const struct timespec &source) const +{ + return equals(source) ; +} + + +inline bool Timestamp::operator==(const uint64_t source) const +{ + return equals(source) ; +} + + inline bool Timestamp::operator!=(const Timestamp &source) const { return !(*this == source) ; } +inline bool Timestamp::operator!=(const struct timespec &source) const +{ + return !(*this == source) ; +} + + +inline bool Timestamp::operator!=(const uint64_t source) const +{ + return !(*this == source) ; +} + + +inline bool Timestamp::operator<(const Timestamp &source) const +{ + return less_than(source.timestamp) ; +} + + +inline bool Timestamp::operator<(const struct timespec &source) const +{ + return less_than(source) ; +} + + +inline bool Timestamp::operator<(const uint64_t source) const +{ + return static_cast(*this) < source ; +} + + inline bool Timestamp::operator>(const Timestamp &source) const { - return source < *this ; + return greater_than(source.timestamp) ; +} + + +inline bool Timestamp::operator>(const struct timespec &source) const +{ + return greater_than(source) ; +} + + +inline bool Timestamp::operator>(const uint64_t source) const +{ + return static_cast(*this) > source ; } @@ -119,10 +189,53 @@ inline bool Timestamp::operator<=(const Timestamp &source) const } +inline bool Timestamp::operator<=(const struct timespec &source) const +{ + return *this == source || *this < source ; +} + + +inline bool Timestamp::operator<=(const uint64_t source) const +{ + return *this == source || *this < source ; +} + + inline bool Timestamp::operator>=(const Timestamp &source) const { return source <= *this ; } +inline bool Timestamp::operator>=(const struct timespec &source) const +{ + return *this == source || !(*this < source) ; +} + + +inline bool Timestamp::operator>=(const uint64_t source) const +{ + return *this == source || !(*this < source) ; +} + + +inline Timestamp::operator bool() const +{ + return static_cast(*this) > 0 ; +} + + +inline Timestamp::operator const struct timespec&() const +{ + return timestamp ; +} + + +inline Timestamp::operator uint64_t(void) const +{ + return timestamp.tv_sec * 1000 + timestamp.tv_nsec / 1000000 ; +} + + + #endif // _OWLPS_POSITIONING_TIMESTAMP_HH_ diff --git a/owlps-positioning/tests/calibrationrequest_test.hh b/owlps-positioning/tests/calibrationrequest_test.hh index 40fff7e..ac78a93 100644 --- a/owlps-positioning/tests/calibrationrequest_test.hh +++ b/owlps-positioning/tests/calibrationrequest_test.hh @@ -52,7 +52,7 @@ public: calibrationrequest1.set_mobile(&mobile2) ; TS_ASSERT_EQUALS(calibrationrequest1.get_mobile(), &mobile2) ; - timestamp1.set_timestamp_ms(42) ; + timestamp1 = 42 ; calibrationrequest1.set_timestamp(timestamp1) ; TS_ASSERT_EQUALS(calibrationrequest1.get_timestamp(), timestamp1) ; diff --git a/owlps-positioning/tests/request_test.hh b/owlps-positioning/tests/request_test.hh index be19eaa..dd8dbd9 100644 --- a/owlps-positioning/tests/request_test.hh +++ b/owlps-positioning/tests/request_test.hh @@ -47,7 +47,7 @@ public: r1.set_mobile(&mob2) ; TS_ASSERT_EQUALS(r1.get_mobile(), &mob2) ; - current_time.set_timestamp_ms(current_time.get_timestamp_ms() + 10) ; + current_time = static_cast(current_time) + 10 ; r1.set_timestamp(current_time) ; TS_ASSERT_EQUALS(r1.get_timestamp(), current_time) ; diff --git a/owlps-positioning/tests/testutil.cc b/owlps-positioning/tests/testutil.cc index f97bc46..149239c 100644 --- a/owlps-positioning/tests/testutil.cc +++ b/owlps-positioning/tests/testutil.cc @@ -161,7 +161,7 @@ create_test_csv_file(const string &file_name, bool with_spaces) if (with_spaces) line << "\n \n " ; line << mobiles[0].get_mac_addr() ; - line << ';' << requests.at(0)->get_timestamp().get_timestamp_ms() ; + line << ';' << requests.at(0)->get_timestamp() ; line << ";0;0;0;0;" ; line << aps[0].get_mac_addr() ; line << ';' << requests.at(0)->get_measurements() @@ -186,7 +186,7 @@ create_test_csv_file(const string &file_name, bool with_spaces) CalibrationRequest *calibration_request = dynamic_cast(requests.at(1)) ; assert(calibration_request) ; - line << ';' << calibration_request->get_timestamp().get_timestamp_ms() ; + line << ';' << calibration_request->get_timestamp() ; line << ';' << reference_points.at(0).get_x() ; line << ';' << reference_points.at(0).get_y() ; line << ';' << reference_points.at(0).get_z() ; @@ -218,7 +218,7 @@ create_test_csv_file(const string &file_name, bool with_spaces) if (with_spaces) line << '\t' ; line << mobiles[0].get_mac_addr() ; - line << ';' << requests.at(2)->get_timestamp().get_timestamp_ms() ; + line << ';' << requests.at(2)->get_timestamp() ; line << ";0;0;0;0;" ; line << aps[2].get_mac_addr() ; line << ';' << requests.at(2)->get_measurements() diff --git a/owlps-positioning/tests/timestamp_test.hh b/owlps-positioning/tests/timestamp_test.hh index d05c80a..39ea69e 100644 --- a/owlps-positioning/tests/timestamp_test.hh +++ b/owlps-positioning/tests/timestamp_test.hh @@ -34,9 +34,15 @@ public: Timestamp timestamp3(msec) ; TS_ASSERT_EQUALS(timestamp1, timestamp3) ; - // Read accessors - TS_ASSERT_EQUALS(timestamp1.get_timestamp(), timespec1) ; - TS_ASSERT_EQUALS(timestamp1.get_timestamp_ms(), msec) ; + // Copy constructor + Timestamp timestamp4(timestamp1) ; + TS_ASSERT_EQUALS(timestamp1, timestamp4) ; + + // Equality + TS_ASSERT_EQUALS(static_cast(timestamp1), timespec1) ; + TS_ASSERT_EQUALS(timestamp1, timespec1) ; + TS_ASSERT_EQUALS(static_cast(timestamp1), msec) ; + TS_ASSERT_EQUALS(timestamp1, msec) ; } void test_non_zero(void) @@ -51,14 +57,22 @@ public: // struct timespec constructor Timestamp timestamp1(timespec1) ; timespec1.tv_nsec = nsec / 1000000 * 1000000 ; // Round to ms - TS_ASSERT_EQUALS(timestamp1.get_timestamp(), timespec1) ; - TS_ASSERT_EQUALS(timestamp1.get_timestamp_ms(), msec) ; + TS_ASSERT_EQUALS(static_cast(timestamp1), timespec1) ; + TS_ASSERT_EQUALS(timestamp1, timespec1) ; + TS_ASSERT_EQUALS(static_cast(timestamp1), msec) ; + TS_ASSERT_EQUALS(timestamp1, msec) ; // ms constructor Timestamp timestamp2(msec) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp(), timespec1) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp_ms(), msec) ; + TS_ASSERT_EQUALS(static_cast(timestamp2), timespec1) ; + TS_ASSERT_EQUALS(timestamp2, timespec1) ; + TS_ASSERT_EQUALS(static_cast(timestamp2), msec) ; + TS_ASSERT_EQUALS(timestamp2, msec) ; TS_ASSERT_EQUALS(timestamp1, timestamp2) ; + + // Copy constructor + Timestamp timestamp3(timestamp1) ; + TS_ASSERT_EQUALS(timestamp1, timestamp3) ; } void test_current_time(void) @@ -66,8 +80,8 @@ public: Timestamp timestamp1 ; struct timespec current_time ; - if (! timestamp1.now() || - clock_gettime(CLOCK_REALTIME, ¤t_time)) + TS_ASSERT(timestamp1.now()) ; + if (clock_gettime(CLOCK_REALTIME, ¤t_time)) { TS_FAIL("Error getting current time!") ; return ; @@ -75,16 +89,18 @@ public: Timestamp timestamp2(current_time) ; - TS_ASSERT_DELTA(timestamp1.get_timestamp_ms(), - timestamp2.get_timestamp_ms(), + TS_ASSERT_DELTA(static_cast(timestamp1), + static_cast(timestamp2), 100) ; // The following tests may fail if the ns value is a ms - TS_ASSERT_DIFFERS(timestamp1.get_timestamp(), current_time) ; - TS_ASSERT_DIFFERS(timestamp2.get_timestamp(), current_time) ; + TS_ASSERT_DIFFERS(static_cast(timestamp1), current_time) ; + TS_ASSERT_DIFFERS(timestamp1, current_time) ; + TS_ASSERT_DIFFERS(static_cast(timestamp2), current_time) ; + TS_ASSERT_DIFFERS(timestamp2, current_time) ; } - void test_accessors(void) + void test_affectation(void) { struct timespec current_time ; if (clock_gettime(CLOCK_REALTIME, ¤t_time)) @@ -95,28 +111,101 @@ public: // struct timespec constructor Timestamp timestamp1(current_time) ; - TS_ASSERT_DIFFERS(timestamp1.get_timestamp(), current_time) ; + TS_ASSERT_DIFFERS(static_cast(timestamp1), current_time) ; + TS_ASSERT_DIFFERS(timestamp1, current_time) ; // ms constructor current_time.tv_nsec = current_time.tv_nsec / 1000000 * 1000000 ; - uint64_t msec = timestamp1.get_timestamp_ms() ; + uint64_t msec = timestamp1 ; Timestamp timestamp2(msec) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp_ms(), msec) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp(), current_time) ; + TS_ASSERT_EQUALS(static_cast(timestamp2), msec) ; + TS_ASSERT_EQUALS(timestamp2, msec) ; + TS_ASSERT_EQUALS(static_cast(timestamp2), current_time) ; + TS_ASSERT_EQUALS(timestamp2, current_time) ; - // Accessors + // Affectation ++current_time.tv_sec ; - timestamp2.set_timestamp(current_time) ; + timestamp2 = current_time ; TS_ASSERT_DIFFERS(timestamp1, timestamp2) ; - msec = timestamp2.get_timestamp_ms() ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp_ms(), msec) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp(), current_time) ; + msec = timestamp2 ; + TS_ASSERT_EQUALS(static_cast(timestamp2), msec) ; + TS_ASSERT_EQUALS(timestamp2, msec) ; + TS_ASSERT_EQUALS(static_cast(timestamp2), current_time) ; + TS_ASSERT_EQUALS(timestamp2, current_time) ; msec = 1234567891234567ull ; - timestamp2.set_timestamp_ms(msec) ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp_ms(), msec) ; - current_time = timestamp2.get_timestamp() ; - TS_ASSERT_EQUALS(timestamp2.get_timestamp(), current_time) ; + timestamp2 = msec ; + TS_ASSERT_EQUALS(static_cast(timestamp2), msec) ; + TS_ASSERT_EQUALS(timestamp2, msec) ; + current_time = timestamp2 ; + TS_ASSERT_EQUALS(static_cast(timestamp2), current_time) ; + TS_ASSERT_EQUALS(timestamp2, current_time) ; + } + + void test_comparison(void) + { + Timestamp today ; + today.now() ; + Timestamp today2(today) ; + struct timespec today_timespec = today ; + uint64_t today_int = today ; + + uint64_t yesterday_int = today_int - 3600*24 ; + Timestamp yesterday(yesterday_int) ; + struct timespec yesterday_timespec = yesterday ; + + TS_ASSERT_EQUALS(today, today2) ; + TS_ASSERT_LESS_THAN_EQUALS(today, today2) ; + TS_ASSERT(today >= today2) ; + TS_ASSERT(! (today > today2)) ; + TS_ASSERT(! (today < today2)) ; + TS_ASSERT_EQUALS(today, today_int) ; + TS_ASSERT_LESS_THAN_EQUALS(today, today_int) ; + TS_ASSERT(today >= today_int) ; + TS_ASSERT(! (today > today_int)) ; + TS_ASSERT(! (today < today_int)) ; + TS_ASSERT_EQUALS(today, today_timespec) ; + TS_ASSERT_LESS_THAN_EQUALS(today, today_timespec) ; + TS_ASSERT(today >= today_timespec) ; + TS_ASSERT(! (today > today_timespec)) ; + TS_ASSERT(! (today < today_timespec)) ; + + TS_ASSERT_DIFFERS(today, yesterday) ; + TS_ASSERT_LESS_THAN(yesterday, today) ; + TS_ASSERT_LESS_THAN_EQUALS(yesterday, today) ; + TS_ASSERT(! (yesterday > today)) ; + TS_ASSERT(! (yesterday >= today)) ; + TS_ASSERT_DIFFERS(today, yesterday_int) ; + TS_ASSERT_LESS_THAN(yesterday, today_int) ; + TS_ASSERT_LESS_THAN_EQUALS(yesterday, today_int) ; + TS_ASSERT(! (yesterday > today_int)) ; + TS_ASSERT(! (yesterday >= today_int)) ; + TS_ASSERT_DIFFERS(today, yesterday_timespec) ; + TS_ASSERT_LESS_THAN(yesterday, today_timespec) ; + TS_ASSERT_LESS_THAN_EQUALS(yesterday, today_timespec) ; + TS_ASSERT(! (yesterday > today_timespec)) ; + TS_ASSERT(! (yesterday >= today_timespec)) ; + } + + void test_clear(void) + { + uint64_t zero = 0 ; + struct timespec zero_timespec ; + zero_timespec.tv_sec = 0 ; + zero_timespec.tv_nsec = 0 ; + Timestamp zero_timestamp ; + + Timestamp today ; + today.now() ; + + TS_ASSERT_DIFFERS(today, zero) ; + TS_ASSERT_DIFFERS(today, zero_timespec) ; + TS_ASSERT_DIFFERS(today, zero_timestamp) ; + + today.clear() ; + TS_ASSERT_EQUALS(today, zero) ; + TS_ASSERT_EQUALS(today, zero_timespec) ; + TS_ASSERT_EQUALS(today, zero_timestamp) ; } } ;