Patrick Venture | 8b4478c | 2020-10-06 08:30:27 -0700 | [diff] [blame] | 1 | #include "dbus/dbusutil.hpp" |
| 2 | |
| 3 | #include <string> |
| 4 | #include <tuple> |
Patrick Venture | 1a7c49f | 2020-10-06 15:49:27 -0700 | [diff] [blame^] | 5 | #include <unordered_map> |
| 6 | #include <utility> |
| 7 | #include <vector> |
Patrick Venture | 8b4478c | 2020-10-06 08:30:27 -0700 | [diff] [blame] | 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | namespace pid_control |
| 13 | { |
| 14 | namespace |
| 15 | { |
| 16 | |
| 17 | using ::testing::StrEq; |
Patrick Venture | 1a7c49f | 2020-10-06 15:49:27 -0700 | [diff] [blame^] | 18 | using ::testing::UnorderedElementsAreArray; |
Patrick Venture | 8b4478c | 2020-10-06 08:30:27 -0700 | [diff] [blame] | 19 | |
| 20 | class GetSensorPathTest : |
| 21 | public ::testing::TestWithParam< |
| 22 | std::tuple<std::string, std::string, std::string>> |
| 23 | {}; |
| 24 | |
| 25 | TEST_P(GetSensorPathTest, ReturnsExpectedValue) |
| 26 | { |
| 27 | // type, id, output |
| 28 | const auto& params = GetParam(); |
| 29 | EXPECT_THAT(getSensorPath(std::get<0>(params), std::get<1>(params)), |
| 30 | StrEq(std::get<2>(params))); |
| 31 | } |
| 32 | |
| 33 | INSTANTIATE_TEST_CASE_P( |
| 34 | GetSensorPathTests, GetSensorPathTest, |
| 35 | ::testing::Values( |
| 36 | std::make_tuple("fan", "0", "/xyz/openbmc_project/sensors/fan_tach/0"), |
| 37 | std::make_tuple("as", "we", "/xyz/openbmc_project/sensors/unknown/we"), |
| 38 | std::make_tuple("margin", "9", |
| 39 | "/xyz/openbmc_project/sensors/temperature/9"), |
| 40 | std::make_tuple("temp", "123", |
| 41 | "/xyz/openbmc_project/sensors/temperature/123"))); |
| 42 | |
Patrick Venture | 1a7c49f | 2020-10-06 15:49:27 -0700 | [diff] [blame^] | 43 | class FindSensorsTest : public ::testing::Test |
| 44 | { |
| 45 | protected: |
| 46 | const std::unordered_map<std::string, std::string> sensors = { |
| 47 | {"path_a", "b"}, |
| 48 | {"apple", "juice"}, |
| 49 | {"other_le", "thing"}, |
| 50 | }; |
| 51 | |
| 52 | std::vector<std::pair<std::string, std::string>> results; |
| 53 | }; |
| 54 | |
| 55 | TEST_F(FindSensorsTest, NoMatches) |
| 56 | { |
| 57 | const std::string target = "abcd"; |
| 58 | |
| 59 | EXPECT_FALSE(findSensors(sensors, target, results)); |
| 60 | } |
| 61 | |
| 62 | TEST_F(FindSensorsTest, OneMatches) |
| 63 | { |
| 64 | const std::string target = "a"; |
| 65 | |
| 66 | EXPECT_TRUE(findSensors(sensors, target, results)); |
| 67 | |
| 68 | std::vector<std::pair<std::string, std::string>> expected_results = { |
| 69 | {"path_a", "b"}, |
| 70 | }; |
| 71 | |
| 72 | EXPECT_THAT(results, UnorderedElementsAreArray(expected_results)); |
| 73 | } |
| 74 | |
| 75 | TEST_F(FindSensorsTest, MultipleMatches) |
| 76 | { |
| 77 | const std::string target = "le"; |
| 78 | EXPECT_TRUE(findSensors(sensors, target, results)); |
| 79 | |
| 80 | std::vector<std::pair<std::string, std::string>> expected_results = { |
| 81 | {"apple", "juice"}, |
| 82 | {"other_le", "thing"}, |
| 83 | }; |
| 84 | |
| 85 | EXPECT_THAT(results, UnorderedElementsAreArray(expected_results)); |
| 86 | } |
| 87 | |
Patrick Venture | 8b4478c | 2020-10-06 08:30:27 -0700 | [diff] [blame] | 88 | } // namespace |
| 89 | } // namespace pid_control |