diff options
Diffstat (limited to 'server/IptablesBaseTest.cpp')
| -rw-r--r-- | server/IptablesBaseTest.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/server/IptablesBaseTest.cpp b/server/IptablesBaseTest.cpp index 1502c4bf3..9e75cb63f 100644 --- a/server/IptablesBaseTest.cpp +++ b/server/IptablesBaseTest.cpp @@ -16,14 +16,20 @@ * IptablesBaseTest.cpp - utility class for tests that use iptables */ +#include <deque> #include <string> #include <vector> #include <gtest/gtest.h> +#include <android-base/stringprintf.h> + #include "IptablesBaseTest.h" #include "NetdConstants.h" +#define LOG_TAG "IptablesBaseTest" +#include <cutils/log.h> + IptablesBaseTest::IptablesBaseTest() { sCmds.clear(); sRestoreCmds.clear(); @@ -63,6 +69,16 @@ int IptablesBaseTest::fakeExecIptables(IptablesTarget target, ...) { return 0; } +FILE *IptablesBaseTest::fake_popen(const char * /* cmd */, const char *type) { + if (sPopenContents.empty() || strcmp(type, "r") != 0) { + return NULL; + } + + std::string realCmd = android::base::StringPrintf("echo '%s'", sPopenContents.front().c_str()); + sPopenContents.pop_front(); + return popen(realCmd.c_str(), "r"); +} + int IptablesBaseTest::fakeExecIptablesRestore(IptablesTarget target, const std::string& commands) { sRestoreCmds.push_back({ target, commands }); return 0; @@ -131,3 +147,4 @@ void IptablesBaseTest::expectIptablesRestoreCommands(const ExpectedIptablesComma std::vector<std::string> IptablesBaseTest::sCmds = {}; IptablesBaseTest::ExpectedIptablesCommands IptablesBaseTest::sRestoreCmds = {}; +std::deque<std::string> IptablesBaseTest::sPopenContents = {}; |
