1 #include "util.hpp"
2 
3 #include <string>
4 
5 #include <gmock/gmock.h>
6 #include <gtest/gtest.h>
7 
8 TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
9 {
10     // Verify it responds to an empty string.
11 
12     EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType(""));
13 }
14 
15 TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
16 {
17     // Verify it responds to a path of "None"
18 
19     EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType("None"));
20 }
21 
22 TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
23 {
24     // Verify the sysfs type is determined with an expected path
25 
26     std::string path = "/sys/devices/asfdadsf";
27     EXPECT_EQ(IOInterfaceType::SYSFS, getWriteInterfaceType(path));
28 }
29 
30 TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
31 {
32     // Verify it reports unknown by default.
33 
34     std::string path = "/xyz/openbmc_project";
35     EXPECT_EQ(IOInterfaceType::UNKNOWN, getWriteInterfaceType(path));
36 }
37 
38 TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
39 {
40     // Verify it responds to an empty string.
41 
42     EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType(""));
43 }
44 
45 TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
46 {
47     // Verify it responds to a path of "None"
48 
49     EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType("None"));
50 }
51 
52 TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
53 {
54     // Verify it responds to a path that represents a host sensor.
55 
56     std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
57     EXPECT_EQ(IOInterfaceType::EXTERNAL, getReadInterfaceType(path));
58 }
59 
60 TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
61 {
62     // Verify it responds to a path that represents a dbus sensor.
63 
64     std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
65     EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, getReadInterfaceType(path));
66 }
67 
68 TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
69 {
70     // Verify the sysfs type is determined with an expected path
71 
72     std::string path = "/sys/devices/asdf/asdf0";
73     EXPECT_EQ(IOInterfaceType::SYSFS, getReadInterfaceType(path));
74 }
75 
76 TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
77 {
78     // Verify it reports unknown by default.
79 
80     std::string path = "asdf09as0df9a0fd";
81     EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
82 }
83