blob: d175c5bc2541e93ada297b035c99e1b444024e8e [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
Lorenzo Colittibbeaf9a2016-07-08 18:24:26 +090019#include <deque>
20
Lorenzo Colitti0f150552016-03-28 02:30:27 +090021#include "NetdConstants.h"
22
23class IptablesBaseTest : public ::testing::Test {
24public:
25 IptablesBaseTest();
26
Lorenzo Colitti9028d912016-03-28 02:34:54 +090027 typedef std::vector<std::pair<IptablesTarget, std::string>> ExpectedIptablesCommands;
28
Lorenzo Colitti0f150552016-03-28 02:30:27 +090029 static int fake_android_fork_exec(int argc, char* argv[], int *status, bool, bool);
Lorenzo Colitti8e1cee92016-07-09 14:24:08 +090030 static int fake_android_fork_execvp(int argc, char* argv[], int *status, bool, bool);
Lorenzo Colitti9028d912016-03-28 02:34:54 +090031 static int fakeExecIptables(IptablesTarget target, ...);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090032 static int fakeExecIptablesRestore(IptablesTarget target, const std::string& commands);
Lorenzo Colittibbeaf9a2016-07-08 18:24:26 +090033 static FILE *fake_popen(const char *cmd, const char *type);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090034 void expectIptablesCommands(const std::vector<std::string>& expectedCmds);
Lorenzo Colitti9028d912016-03-28 02:34:54 +090035 void expectIptablesCommands(const ExpectedIptablesCommands& expectedCmds);
Lorenzo Colitti8e1cee92016-07-09 14:24:08 +090036 void expectIptablesCommands(const std::vector<ExpectedIptablesCommands>& snippets);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090037 void expectIptablesRestoreCommands(const std::vector<std::string>& expectedCmds);
Lorenzo Colittie60c0a52016-03-29 00:53:45 +090038 void expectIptablesRestoreCommands(const ExpectedIptablesCommands& expectedCmds);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090039
40protected:
41 static std::vector<std::string> sCmds;
Lorenzo Colittie60c0a52016-03-29 00:53:45 +090042 static ExpectedIptablesCommands sRestoreCmds;
Lorenzo Colittibbeaf9a2016-07-08 18:24:26 +090043 static std::deque<std::string> sPopenContents;
Lorenzo Colitti9028d912016-03-28 02:34:54 +090044 int expectIptablesCommand(IptablesTarget target, int pos, const std::string& cmd);
Lorenzo Colitti0f150552016-03-28 02:30:27 +090045};