xref: /aosp_15_r20/external/webrtc/test/field_trial.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2014 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 
11 #include "test/field_trial.h"
12 
13 #include <string>
14 
15 #include "absl/strings/string_view.h"
16 #include "rtc_base/checks.h"
17 #include "system_wrappers/include/field_trial.h"
18 
19 namespace webrtc {
20 namespace test {
21 
ScopedFieldTrials(absl::string_view config)22 ScopedFieldTrials::ScopedFieldTrials(absl::string_view config)
23     : current_field_trials_(config),
24       previous_field_trials_(webrtc::field_trial::GetFieldTrialString()) {
25   RTC_CHECK(webrtc::field_trial::FieldTrialsStringIsValid(
26       current_field_trials_.c_str()))
27       << "Invalid field trials string: " << current_field_trials_;
28   webrtc::field_trial::InitFieldTrialsFromString(current_field_trials_.c_str());
29 }
30 
~ScopedFieldTrials()31 ScopedFieldTrials::~ScopedFieldTrials() {
32   RTC_CHECK(
33       webrtc::field_trial::FieldTrialsStringIsValid(previous_field_trials_))
34       << "Invalid field trials string: " << previous_field_trials_;
35   webrtc::field_trial::InitFieldTrialsFromString(previous_field_trials_);
36 }
37 
38 }  // namespace test
39 }  // namespace webrtc
40