Jonas Olsson | 5b2eda4 | 2019-06-11 12:29:40 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 "system_wrappers/include/field_trial.h" |
| 11 | |
| 12 | #include "rtc_base/checks.h" |
| 13 | #include "test/gtest.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace field_trial { |
| 17 | #if GTEST_HAS_DEATH_TEST && RTC_DCHECK_IS_ON && !defined(WEBRTC_ANDROID) && \ |
| 18 | !defined(WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT) |
| 19 | TEST(FieldTrialValidationTest, AcceptsValidInputs) { |
| 20 | InitFieldTrialsFromString(""); |
| 21 | InitFieldTrialsFromString("Audio/Enabled/"); |
| 22 | InitFieldTrialsFromString("Audio/Enabled/Video/Disabled/"); |
| 23 | |
| 24 | // Duplicate trials with the same value is fine |
| 25 | InitFieldTrialsFromString("Audio/Enabled/Audio/Enabled/"); |
| 26 | InitFieldTrialsFromString("Audio/Enabled/B/C/Audio/Enabled/"); |
| 27 | } |
| 28 | |
| 29 | TEST(FieldTrialValidationTest, RejectsBadInputs) { |
| 30 | // Bad delimiters |
| 31 | EXPECT_DEATH(InitFieldTrialsFromString("Audio/EnabledVideo/Disabled/"), |
| 32 | "Invalid field trials string:"); |
| 33 | EXPECT_DEATH(InitFieldTrialsFromString("Audio/Enabled//Video/Disabled/"), |
| 34 | "Invalid field trials string:"); |
| 35 | EXPECT_DEATH(InitFieldTrialsFromString("/Audio/Enabled/Video/Disabled/"), |
| 36 | "Invalid field trials string:"); |
| 37 | EXPECT_DEATH(InitFieldTrialsFromString("Audio/Enabled/Video/Disabled"), |
| 38 | "Invalid field trials string:"); |
| 39 | EXPECT_DEATH( |
| 40 | InitFieldTrialsFromString("Audio/Enabled/Video/Disabled/garbage"), |
| 41 | "Invalid field trials string:"); |
| 42 | |
| 43 | // Duplicate trials with different values is not fine |
| 44 | EXPECT_DEATH(InitFieldTrialsFromString("Audio/Enabled/Audio/Disabled/"), |
| 45 | "Invalid field trials string:"); |
| 46 | EXPECT_DEATH(InitFieldTrialsFromString("Audio/Enabled/B/C/Audio/Disabled/"), |
| 47 | "Invalid field trials string:"); |
| 48 | } |
| 49 | #endif // GTEST_HAS_DEATH_TEST && RTC_DCHECK_IS_ON && !defined(WEBRTC_ANDROID) |
| 50 | // && !defined(WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT) |
| 51 | |
| 52 | } // namespace field_trial |
| 53 | } // namespace webrtc |