Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 1 | /* |
| 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 Colitti | bbeaf9a | 2016-07-08 18:24:26 +0900 | [diff] [blame] | 19 | #include <deque> |
| 20 | |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 21 | #include "NetdConstants.h" |
| 22 | |
| 23 | class IptablesBaseTest : public ::testing::Test { |
| 24 | public: |
| 25 | IptablesBaseTest(); |
| 26 | |
Lorenzo Colitti | 9028d91 | 2016-03-28 02:34:54 +0900 | [diff] [blame] | 27 | typedef std::vector<std::pair<IptablesTarget, std::string>> ExpectedIptablesCommands; |
| 28 | |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 29 | static int fake_android_fork_exec(int argc, char* argv[], int *status, bool, bool); |
Lorenzo Colitti | 8e1cee9 | 2016-07-09 14:24:08 +0900 | [diff] [blame] | 30 | static int fake_android_fork_execvp(int argc, char* argv[], int *status, bool, bool); |
Lorenzo Colitti | 9028d91 | 2016-03-28 02:34:54 +0900 | [diff] [blame] | 31 | static int fakeExecIptables(IptablesTarget target, ...); |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 32 | static int fakeExecIptablesRestore(IptablesTarget target, const std::string& commands); |
Lorenzo Colitti | cd28377 | 2017-01-31 19:00:49 +0900 | [diff] [blame] | 33 | static int fakeExecIptablesRestoreWithOutput(IptablesTarget target, const std::string& commands, |
| 34 | std::string *output); |
Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame^] | 35 | static int fakeExecIptablesRestoreCommand(IptablesTarget target, const std::string& table, |
| 36 | const std::string& commands, std::string *output); |
Lorenzo Colitti | bbeaf9a | 2016-07-08 18:24:26 +0900 | [diff] [blame] | 37 | static FILE *fake_popen(const char *cmd, const char *type); |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 38 | void expectIptablesCommands(const std::vector<std::string>& expectedCmds); |
Lorenzo Colitti | 9028d91 | 2016-03-28 02:34:54 +0900 | [diff] [blame] | 39 | void expectIptablesCommands(const ExpectedIptablesCommands& expectedCmds); |
Lorenzo Colitti | 8e1cee9 | 2016-07-09 14:24:08 +0900 | [diff] [blame] | 40 | void expectIptablesCommands(const std::vector<ExpectedIptablesCommands>& snippets); |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 41 | void expectIptablesRestoreCommands(const std::vector<std::string>& expectedCmds); |
Lorenzo Colitti | e60c0a5 | 2016-03-29 00:53:45 +0900 | [diff] [blame] | 42 | void expectIptablesRestoreCommands(const ExpectedIptablesCommands& expectedCmds); |
Lorenzo Colitti | 849a11c | 2017-02-27 23:01:16 +0900 | [diff] [blame] | 43 | void setReturnValues(const std::deque<int>& returnValues); |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 44 | |
| 45 | protected: |
| 46 | static std::vector<std::string> sCmds; |
Lorenzo Colitti | e60c0a5 | 2016-03-29 00:53:45 +0900 | [diff] [blame] | 47 | static ExpectedIptablesCommands sRestoreCmds; |
Lorenzo Colitti | 849a11c | 2017-02-27 23:01:16 +0900 | [diff] [blame] | 48 | static std::deque<int> sReturnValues; |
Lorenzo Colitti | bbeaf9a | 2016-07-08 18:24:26 +0900 | [diff] [blame] | 49 | static std::deque<std::string> sPopenContents; |
Lorenzo Colitti | cd28377 | 2017-01-31 19:00:49 +0900 | [diff] [blame] | 50 | static std::deque<std::string> sIptablesRestoreOutput; |
Lorenzo Colitti | 9028d91 | 2016-03-28 02:34:54 +0900 | [diff] [blame] | 51 | int expectIptablesCommand(IptablesTarget target, int pos, const std::string& cmd); |
Lorenzo Colitti | 0f15055 | 2016-03-28 02:30:27 +0900 | [diff] [blame] | 52 | }; |