Sebastian Jansson | 9eb3886 | 2018-06-14 16:47:42 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #include <string> |
| 11 | |
| 12 | #include "rtc_base/experiments/field_trial_parser.h" |
| 13 | #include "rtc_base/experiments/field_trial_units.h" |
| 14 | #include "rtc_base/gunit.h" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | namespace { |
| 18 | struct DummyExperiment { |
| 19 | FieldTrialParameter<DataRate> target_rate = |
| 20 | FieldTrialParameter<DataRate>("t", DataRate::kbps(100)); |
| 21 | FieldTrialParameter<TimeDelta> period = |
| 22 | FieldTrialParameter<TimeDelta>("p", TimeDelta::ms(100)); |
| 23 | FieldTrialOptional<DataSize> max_buffer = |
| 24 | FieldTrialOptional<DataSize>("b", rtc::nullopt); |
| 25 | |
| 26 | explicit DummyExperiment(std::string field_trial) { |
| 27 | ParseFieldTrial({&target_rate, &max_buffer, &period}, field_trial); |
| 28 | } |
| 29 | }; |
| 30 | } // namespace |
| 31 | |
| 32 | TEST(FieldTrialParserUnitsTest, FallsBackToDefaults) { |
| 33 | DummyExperiment exp(""); |
| 34 | EXPECT_EQ(exp.target_rate.Get(), DataRate::kbps(100)); |
| 35 | EXPECT_FALSE(exp.max_buffer.Get().has_value()); |
| 36 | EXPECT_EQ(exp.period.Get(), TimeDelta::ms(100)); |
| 37 | } |
| 38 | TEST(FieldTrialParserUnitsTest, ParsesUnitParameters) { |
| 39 | DummyExperiment exp("t:300kbps,b:5bytes,p:300ms"); |
| 40 | EXPECT_EQ(exp.target_rate.Get(), DataRate::kbps(300)); |
| 41 | EXPECT_EQ(*exp.max_buffer.Get(), DataSize::bytes(5)); |
| 42 | EXPECT_EQ(exp.period.Get(), TimeDelta::ms(300)); |
| 43 | } |
| 44 | TEST(FieldTrialParserUnitsTest, ParsesDefaultUnitParameters) { |
| 45 | DummyExperiment exp("t:300,b:5,p:300"); |
| 46 | EXPECT_EQ(exp.target_rate.Get(), DataRate::kbps(300)); |
| 47 | EXPECT_EQ(*exp.max_buffer.Get(), DataSize::bytes(5)); |
| 48 | EXPECT_EQ(exp.period.Get(), TimeDelta::ms(300)); |
| 49 | } |
| 50 | TEST(FieldTrialParserUnitsTest, ParsesInfinityParameter) { |
| 51 | DummyExperiment exp("t:inf,p:inf"); |
| 52 | EXPECT_EQ(exp.target_rate.Get(), DataRate::Infinity()); |
| 53 | EXPECT_EQ(exp.period.Get(), TimeDelta::PlusInfinity()); |
| 54 | } |
| 55 | TEST(FieldTrialParserUnitsTest, ParsesOtherUnitParameters) { |
| 56 | DummyExperiment exp("t:300bps,p:0.3 seconds,b:8 bytes"); |
| 57 | EXPECT_EQ(exp.target_rate.Get(), DataRate::bps(300)); |
| 58 | EXPECT_EQ(*exp.max_buffer.Get(), DataSize::bytes(8)); |
| 59 | EXPECT_EQ(exp.period.Get(), TimeDelta::ms(300)); |
| 60 | } |
| 61 | |
| 62 | } // namespace webrtc |