blob: 333e4e7e05ebd8a5891e0c30b997acbbfa3a2330 [file] [log] [blame]
Ady Abraham529bd9f2023-10-05 14:55:30 -07001/*
2 * Copyright 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
Ady Abrahamd6d80162023-10-23 12:57:41 -070019#include "FlagManager.h"
20
Ady Abraham529bd9f2023-10-05 14:55:30 -070021#define SET_FLAG_FOR_TEST(name, value) TestFlagSetter _testflag_((name), (name), (value))
22
23namespace android {
24class TestFlagSetter {
25public:
26 TestFlagSetter(bool (*getter)(), void((*setter)(bool)), bool flagValue) {
Ady Abrahamd6d80162023-10-23 12:57:41 -070027 FlagManager::getMutableInstance().setUnitTestMode();
28
Ady Abraham529bd9f2023-10-05 14:55:30 -070029 const bool initialValue = getter();
30 setter(flagValue);
31 mResetFlagValue = [=] { setter(initialValue); };
32 }
33
34 ~TestFlagSetter() { mResetFlagValue(); }
35
36private:
37 std::function<void()> mResetFlagValue;
38};
39
40} // namespace android