From ec2eb2218f1e19ef8a675d494f565b2a9975a7d3 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Thu, 24 May 2018 12:32:05 +0200 Subject: [PATCH] Enables comparison with infinite timestamps. Bug: webrtc:8415 Change-Id: Ia96c7a537d994c281d8b24e648dbb2e17de3ed4a Reviewed-on: https://webrtc-review.googlesource.com/78182 Reviewed-by: Karl Wiberg Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#23383} --- api/units/timestamp.h | 16 ++++++++++++---- api/units/timestamp_unittest.cc | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/units/timestamp.h b/api/units/timestamp.h index af62b3b490..40f3e922ef 100644 --- a/api/units/timestamp.h +++ b/api/units/timestamp.h @@ -78,10 +78,18 @@ class Timestamp { bool operator!=(const Timestamp& other) const { return microseconds_ != other.microseconds_; } - bool operator<=(const Timestamp& other) const { return us() <= other.us(); } - bool operator>=(const Timestamp& other) const { return us() >= other.us(); } - bool operator>(const Timestamp& other) const { return us() > other.us(); } - bool operator<(const Timestamp& other) const { return us() < other.us(); } + bool operator<=(const Timestamp& other) const { + return microseconds_ <= other.microseconds_; + } + bool operator>=(const Timestamp& other) const { + return microseconds_ >= other.microseconds_; + } + bool operator>(const Timestamp& other) const { + return microseconds_ > other.microseconds_; + } + bool operator<(const Timestamp& other) const { + return microseconds_ < other.microseconds_; + } private: explicit Timestamp(int64_t us) : microseconds_(us) {} diff --git a/api/units/timestamp_unittest.cc b/api/units/timestamp_unittest.cc index 549a9c8e23..3b2770ceb3 100644 --- a/api/units/timestamp_unittest.cc +++ b/api/units/timestamp_unittest.cc @@ -46,6 +46,8 @@ TEST(TimestampTest, ComparisonOperators) { const int64_t kLarge = 451; EXPECT_EQ(Timestamp::Infinity(), Timestamp::Infinity()); + EXPECT_GE(Timestamp::Infinity(), Timestamp::Infinity()); + EXPECT_GT(Timestamp::Infinity(), Timestamp::ms(kLarge)); EXPECT_EQ(Timestamp::ms(kSmall), Timestamp::ms(kSmall)); EXPECT_LE(Timestamp::ms(kSmall), Timestamp::ms(kSmall)); EXPECT_GE(Timestamp::ms(kSmall), Timestamp::ms(kSmall));