blob: 55167881d8e98c5ed89be682b703ccb498dba30e [file] [log] [blame]
Lorenzo Colitti0f150552016-03-28 02:30:27 +09001/*
2 * Copyright 2016 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 * IptablesBaseTest.h - utility class for tests that use iptables
17 */
18
19#include "NetdConstants.h"
20
21class IptablesBaseTest : public ::testing::Test {
22public:
23 IptablesBaseTest();
24
Lorenzo Colitti9028d912016-03-28 02:34:54 +090025 typedef std::vector<std::pair<IptablesTarget, std::string>> ExpectedIptablesCommands;
26
Lorenzo Colitti0f150552016-03-28 02:30:27 +090027 static int fake_android_fork_exec(int argc, char* argv[], int *status, bool, bool);
Lorenzo Colitti9028d912016-03-28 02:34:54 +090028 static int fakeExecIptables(IptablesTarget target, ...);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090029 static int fakeExecIptablesRestore(IptablesTarget target, const std::string& commands);
30 void expectIptablesCommands(const std::vector<std::string>& expectedCmds);
Lorenzo Colitti9028d912016-03-28 02:34:54 +090031 void expectIptablesCommands(const ExpectedIptablesCommands& expectedCmds);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090032 void expectIptablesRestoreCommands(const std::vector<std::string>& expectedCmds);
33
34protected:
35 static std::vector<std::string> sCmds;
36 static std::vector<std::string> sRestoreCmds;
Lorenzo Colitti9028d912016-03-28 02:34:54 +090037 int expectIptablesCommand(IptablesTarget target, int pos, const std::string& cmd);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090038};
39