Enables comparison with infinite timestamps.

Bug: webrtc:8415
Change-Id: Ia96c7a537d994c281d8b24e648dbb2e17de3ed4a
Reviewed-on: https://webrtc-review.googlesource.com/78182
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23383}
This commit is contained in:
Sebastian Jansson 2018-05-24 12:32:05 +02:00 committed by Commit Bot
parent a927ed576a
commit ec2eb2218f
2 changed files with 14 additions and 4 deletions

View file

@ -78,10 +78,18 @@ class Timestamp {
bool operator!=(const Timestamp& other) const { bool operator!=(const Timestamp& other) const {
return microseconds_ != other.microseconds_; return microseconds_ != other.microseconds_;
} }
bool operator<=(const Timestamp& other) const { return us() <= other.us(); } bool operator<=(const Timestamp& other) const {
bool operator>=(const Timestamp& other) const { return us() >= other.us(); } 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 microseconds_ >= other.microseconds_;
}
bool operator>(const Timestamp& other) const {
return microseconds_ > other.microseconds_;
}
bool operator<(const Timestamp& other) const {
return microseconds_ < other.microseconds_;
}
private: private:
explicit Timestamp(int64_t us) : microseconds_(us) {} explicit Timestamp(int64_t us) : microseconds_(us) {}

View file

@ -46,6 +46,8 @@ TEST(TimestampTest, ComparisonOperators) {
const int64_t kLarge = 451; const int64_t kLarge = 451;
EXPECT_EQ(Timestamp::Infinity(), Timestamp::Infinity()); 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_EQ(Timestamp::ms(kSmall), Timestamp::ms(kSmall));
EXPECT_LE(Timestamp::ms(kSmall), Timestamp::ms(kSmall)); EXPECT_LE(Timestamp::ms(kSmall), Timestamp::ms(kSmall));
EXPECT_GE(Timestamp::ms(kSmall), Timestamp::ms(kSmall)); EXPECT_GE(Timestamp::ms(kSmall), Timestamp::ms(kSmall));