blob: 0780cb1ef1f3a57790f9f5c2283a2a44df07e6f5 [file] [log] [blame]
Patrick Venture8b4478c2020-10-06 08:30:27 -07001#include "dbus/dbusutil.hpp"
2
3#include <string>
4#include <tuple>
Patrick Venture1a7c49f2020-10-06 15:49:27 -07005#include <unordered_map>
6#include <utility>
7#include <vector>
Patrick Venture8b4478c2020-10-06 08:30:27 -07008
9#include <gmock/gmock.h>
10#include <gtest/gtest.h>
11
12namespace pid_control
13{
14namespace
15{
16
17using ::testing::StrEq;
Patrick Venture1a7c49f2020-10-06 15:49:27 -070018using ::testing::UnorderedElementsAreArray;
Patrick Venture8b4478c2020-10-06 08:30:27 -070019
20class GetSensorPathTest :
21 public ::testing::TestWithParam<
22 std::tuple<std::string, std::string, std::string>>
23{};
24
25TEST_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
33INSTANTIATE_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 Venture1a7c49f2020-10-06 15:49:27 -070043class 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
55TEST_F(FindSensorsTest, NoMatches)
56{
57 const std::string target = "abcd";
58
59 EXPECT_FALSE(findSensors(sensors, target, results));
60}
61
62TEST_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
75TEST_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 Venture8b4478c2020-10-06 08:30:27 -070088} // namespace
89} // namespace pid_control