1 #include "utils/sensor_utils.hpp"
2 
3 #include <string>
4 
5 #include <gtest/gtest.h>
6 
7 namespace redfish::sensor_utils
8 {
9 namespace
10 {
11 
TEST(SplitSensorNameAndType,Type)12 TEST(SplitSensorNameAndType, Type)
13 {
14     EXPECT_EQ(splitSensorNameAndType("fantach_foo_1").first, "fan_tach");
15     EXPECT_EQ(splitSensorNameAndType("temperature_foo2").first, "temperature");
16 }
17 
TEST(SplitSensorNameAndType,Name)18 TEST(SplitSensorNameAndType, Name)
19 {
20     EXPECT_EQ(splitSensorNameAndType("fantach_foo_1").second, "foo_1");
21     EXPECT_EQ(splitSensorNameAndType("temperature_foo2").second, "foo2");
22 }
23 
TEST(SplitSensorNameAndType,Error)24 TEST(SplitSensorNameAndType, Error)
25 {
26     EXPECT_TRUE(splitSensorNameAndType("fantach").first.empty());
27     EXPECT_TRUE(splitSensorNameAndType("temperature").second.empty());
28 }
29 
TEST(GetSensorId,Success)30 TEST(GetSensorId, Success)
31 {
32     std::string sensorId;
33 
34     sensorId = getSensorId("fan0_0", "fan_tach");
35     EXPECT_EQ(sensorId, "fantach_fan0_0");
36 
37     sensorId = getSensorId("0_1", "fan_pwm");
38     EXPECT_EQ(sensorId, "fanpwm_0_1");
39 
40     sensorId = getSensorId("fan2", "fan_tach");
41     EXPECT_EQ(sensorId, "fantach_fan2");
42 
43     sensorId = getSensorId("fan_3", "fan_tach");
44     EXPECT_EQ(sensorId, "fantach_fan_3");
45 
46     sensorId = getSensorId("temp2", "temperature");
47     EXPECT_EQ(sensorId, "temperature_temp2");
48 }
49 
TEST(ChassisSubNodeToString,Success)50 TEST(ChassisSubNodeToString, Success)
51 {
52     std::string subNodeStr;
53 
54     subNodeStr = chassisSubNodeToString(ChassisSubNode::powerNode);
55     EXPECT_EQ(subNodeStr, "Power");
56 
57     subNodeStr = chassisSubNodeToString(ChassisSubNode::sensorsNode);
58     EXPECT_EQ(subNodeStr, "Sensors");
59 
60     subNodeStr = chassisSubNodeToString(ChassisSubNode::thermalNode);
61     EXPECT_EQ(subNodeStr, "Thermal");
62 
63     subNodeStr = chassisSubNodeToString(ChassisSubNode::thermalMetricsNode);
64     EXPECT_EQ(subNodeStr, "ThermalMetrics");
65 
66     subNodeStr = chassisSubNodeToString(ChassisSubNode::unknownNode);
67     EXPECT_EQ(subNodeStr, "");
68 }
69 
TEST(ChassisSubNodeFromString,Success)70 TEST(ChassisSubNodeFromString, Success)
71 {
72     ChassisSubNode subNode = ChassisSubNode::unknownNode;
73 
74     subNode = chassisSubNodeFromString("Power");
75     EXPECT_EQ(subNode, ChassisSubNode::powerNode);
76 
77     subNode = chassisSubNodeFromString("Sensors");
78     EXPECT_EQ(subNode, ChassisSubNode::sensorsNode);
79 
80     subNode = chassisSubNodeFromString("Thermal");
81     EXPECT_EQ(subNode, ChassisSubNode::thermalNode);
82 
83     subNode = chassisSubNodeFromString("ThermalMetrics");
84     EXPECT_EQ(subNode, ChassisSubNode::thermalMetricsNode);
85 
86     subNode = chassisSubNodeFromString("BadNode");
87     EXPECT_EQ(subNode, ChassisSubNode::unknownNode);
88 
89     subNode = chassisSubNodeFromString("");
90     EXPECT_EQ(subNode, ChassisSubNode::unknownNode);
91 }
92 
TEST(IsExcerptNode,True)93 TEST(IsExcerptNode, True)
94 {
95     EXPECT_TRUE(isExcerptNode(ChassisSubNode::thermalMetricsNode));
96 }
97 
TEST(IsExcerptNode,False)98 TEST(IsExcerptNode, False)
99 {
100     EXPECT_FALSE(isExcerptNode(ChassisSubNode::sensorsNode));
101     EXPECT_FALSE(isExcerptNode(ChassisSubNode::powerNode));
102     EXPECT_FALSE(isExcerptNode(ChassisSubNode::thermalNode));
103     EXPECT_FALSE(isExcerptNode(ChassisSubNode::unknownNode));
104 }
105 
106 } // namespace
107 } // namespace redfish::sensor_utils
108