summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-12-19 07:29:43 -0800
committerPatrick Venture <venture@google.com>2019-01-02 11:56:28 -0800
commita67a947007d598ad30b322c67fba6efa338d2156 (patch)
tree8083d9fae368ce38e90224f658e7dc5a492035b3 /test
parentd0f5097c61fb3659fedda43e5ebc75b416d9bbd7 (diff)
downloadphosphor-hwmon-a67a947007d598ad30b322c67fba6efa338d2156.tar.gz
phosphor-hwmon-a67a947007d598ad30b322c67fba6efa338d2156.zip
test: add environment mock impl
Add environment mock implementation for use in testing. Change-Id: I5a8efe994692a2e4436bf7f3c0155516d92b49c6 Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/env.cpp31
-rw-r--r--test/env_mock.hpp40
2 files changed, 71 insertions, 0 deletions
diff --git a/test/env.cpp b/test/env.cpp
new file mode 100644
index 0000000..934b9a0
--- /dev/null
+++ b/test/env.cpp
@@ -0,0 +1,31 @@
+#include "env_mock.hpp"
+
+// Set this before each test that hits a call to getEnv().
+EnvInterface* envIntf = nullptr;
+
+namespace env
+{
+
+std::string getEnv(const char* key)
+{
+ return (envIntf) ? envIntf->getEnv(key) : "";
+}
+
+std::string getEnv(const char* prefix, const SensorSet::key_type& sensor)
+{
+ return (envIntf) ? envIntf->getEnv(prefix, sensor) : "";
+}
+
+std::string getEnv(const char* prefix, const std::string& type,
+ const std::string& id)
+{
+ return (envIntf) ? envIntf->getEnv(prefix, type, id) : "";
+}
+
+std::string getIndirectID(std::string path, const std::string& fileSuffix,
+ const SensorSet::key_type& sensor)
+{
+ return (envIntf) ? envIntf->getIndirectID(path, fileSuffix, sensor) : "";
+}
+
+} // namespace env
diff --git a/test/env_mock.hpp b/test/env_mock.hpp
new file mode 100644
index 0000000..4cf232f
--- /dev/null
+++ b/test/env_mock.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "sensorset.hpp"
+
+#include <string>
+
+#include <gmock/gmock.h>
+
+class EnvInterface
+{
+ public:
+ virtual ~EnvInterface() = default;
+
+ virtual std::string getEnv(const char* key) const = 0;
+ virtual std::string getEnv(const char* prefix,
+ const SensorSet::key_type& sensor) const = 0;
+ virtual std::string getEnv(const char* prefix, const std::string& type,
+ const std::string& id) const = 0;
+ virtual std::string
+ getIndirectID(std::string path, const std::string& fileSuffix,
+ const SensorSet::key_type& sensor) const = 0;
+};
+
+class EnvMock : public EnvInterface
+{
+ public:
+ virtual ~EnvMock() = default;
+
+ MOCK_CONST_METHOD1(getEnv, std::string(const char*));
+ MOCK_CONST_METHOD2(getEnv,
+ std::string(const char*, const SensorSet::key_type&));
+ MOCK_CONST_METHOD3(getEnv, std::string(const char*, const std::string&,
+ const std::string&));
+ MOCK_CONST_METHOD3(getIndirectID,
+ std::string(std::string, const std::string&,
+ const SensorSet::key_type&));
+};
+
+// Set this before each test that hits a call to getEnv().
+extern EnvInterface* envIntf;
OpenPOWER on IntegriCloud