Adds constexpr create functions for units.
This adds new constexpr create function for DataSize, DataRate, TimeDelta and Timestamp. The names are capitalized to mirror the naming scheme of the previously constexpr methods (Zero and Infinity create functions). They are also kept longer since they are not expected to be used in complex expressions. Bug: webrtc:9574 Change-Id: I5950548718675050fc5d66699de295455c310861 Reviewed-on: https://webrtc-review.googlesource.com/91161 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24218}
This commit is contained in:
committed by
Commit Bot
parent
133cff009b
commit
c1c8b8e836
@ -14,8 +14,24 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
TEST(TimestampTest, ConstExpr) {
|
||||
constexpr int64_t kValue = 12345;
|
||||
constexpr Timestamp kTimestampInf = Timestamp::Infinity();
|
||||
static_assert(kTimestampInf.IsInfinite(), "");
|
||||
static_assert(kTimestampInf.ms_or(-1) == -1, "");
|
||||
|
||||
constexpr Timestamp kTimestampSeconds = Timestamp::Seconds<kValue>();
|
||||
constexpr Timestamp kTimestampMs = Timestamp::Millis<kValue>();
|
||||
constexpr Timestamp kTimestampUs = Timestamp::Micros<kValue>();
|
||||
|
||||
static_assert(kTimestampSeconds.seconds_or(0) == kValue, "");
|
||||
static_assert(kTimestampMs.ms_or(0) == kValue, "");
|
||||
static_assert(kTimestampUs.us_or(0) == kValue, "");
|
||||
|
||||
static_assert(kTimestampMs > kTimestampUs, "");
|
||||
|
||||
EXPECT_EQ(kTimestampSeconds.seconds(), kValue);
|
||||
EXPECT_EQ(kTimestampMs.ms(), kValue);
|
||||
EXPECT_EQ(kTimestampUs.us(), kValue);
|
||||
}
|
||||
|
||||
TEST(TimestampTest, GetBackSameValues) {
|
||||
|
||||
Reference in New Issue
Block a user