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:
Sebastian Jansson
2018-08-07 15:29:04 +02:00
committed by Commit Bot
parent 133cff009b
commit c1c8b8e836
8 changed files with 213 additions and 76 deletions

View File

@ -15,10 +15,19 @@ namespace webrtc {
namespace test {
TEST(DataRateTest, ConstExpr) {
constexpr int64_t kValue = 12345;
constexpr DataRate kDataRateZero = DataRate::Zero();
constexpr DataRate kDataRateInf = DataRate::Infinity();
static_assert(kDataRateZero.IsZero(), "");
static_assert(kDataRateInf.IsInfinite(), "");
static_assert(kDataRateInf.bps_or(-1) == -1, "");
static_assert(kDataRateInf > kDataRateZero, "");
constexpr DataRate kDataRateBps = DataRate::BitsPerSec<kValue>();
constexpr DataRate kDataRateKbps = DataRate::KilobitsPerSec<kValue>();
static_assert(kDataRateBps.bps<double>() == kValue, "");
static_assert(kDataRateBps.bps_or(0) == kValue, "");
static_assert(kDataRateKbps.kbps_or(0) == kValue, "");
}
TEST(DataRateTest, GetBackSameValues) {