Add a test for getTetherStats.
Bug: 9580643
Change-Id: I26f7adb9639f1ddf4eda0c98bcc6cd3a83d3ba0b
diff --git a/server/IptablesBaseTest.cpp b/server/IptablesBaseTest.cpp
index 1502c4b..9e75cb6 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 @@
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 @@
std::vector<std::string> IptablesBaseTest::sCmds = {};
IptablesBaseTest::ExpectedIptablesCommands IptablesBaseTest::sRestoreCmds = {};
+std::deque<std::string> IptablesBaseTest::sPopenContents = {};