blob: d11a3739acd78581286f1261f656a9f4c41afa26 [file] [log] [blame]
George Liu6f777cd2021-06-10 09:16:28 +08001#include <occ_dbus.hpp>
2
3#include <gtest/gtest.h>
4
5using namespace open_power::occ::dbus;
6
7TEST(OccDBusSensors, MaxValue)
8{
9 std::string tmpPath = "/abc/def";
10 double maxValue = 100.00;
11 double retMaxValue = 0;
12
13 OccDBusSensors::getOccDBus().setMaxValue(tmpPath, maxValue);
14 retMaxValue = OccDBusSensors::getOccDBus().getMaxValue(tmpPath);
15
16 EXPECT_EQ(maxValue, retMaxValue);
17 ASSERT_THROW(OccDBusSensors::getOccDBus().getMaxValue("/abcd/"),
18 std::invalid_argument);
19}
20
21TEST(OccDBusSensors, MinValue)
22{
23 std::string tmpPath = "/abc/def";
24 double minValue = 10.00;
25 double retMinValue = 0;
26
27 OccDBusSensors::getOccDBus().setMinValue(tmpPath, minValue);
28 retMinValue = OccDBusSensors::getOccDBus().getMinValue(tmpPath);
29
30 EXPECT_EQ(minValue, retMinValue);
31 ASSERT_THROW(OccDBusSensors::getOccDBus().getMinValue("/abcd/"),
32 std::invalid_argument);
33}
34
35TEST(OccDBusSensors, Value)
36{
37 std::string tmpPath = "/abc/def";
38 double value = 30.00;
39 double retValue = 0;
40
41 OccDBusSensors::getOccDBus().setValue(tmpPath, value);
42 retValue = OccDBusSensors::getOccDBus().getValue(tmpPath);
43
44 EXPECT_EQ(value, retValue);
45 ASSERT_THROW(OccDBusSensors::getOccDBus().getValue("/abcd/"),
46 std::invalid_argument);
47}
48
49TEST(OccDBusSensors, Unit)
50{
51 std::string tmpPath = "/abc/def";
52 const std::string unit = "xyz.openbmc_project.Sensor.Value.Unit.DegreesC";
53 std::string retUnit = "";
54
55 OccDBusSensors::getOccDBus().setUnit(tmpPath, unit);
56 retUnit = OccDBusSensors::getOccDBus().getUnit(tmpPath);
57
58 EXPECT_EQ(unit, retUnit);
59 ASSERT_THROW(OccDBusSensors::getOccDBus().getUnit("/abcd/"),
60 std::invalid_argument);
61}
62
63TEST(OccDBusSensors, OperationalStatus)
64{
65 std::string tmpPath = "/abc/def";
66 bool retStatus = false;
67
68 OccDBusSensors::getOccDBus().setOperationalStatus(tmpPath, true);
69 retStatus = OccDBusSensors::getOccDBus().getOperationalStatus(tmpPath);
70
71 EXPECT_EQ(true, retStatus);
72 ASSERT_THROW(OccDBusSensors::getOccDBus().getOperationalStatus("/abcd/"),
73 std::invalid_argument);
74}