blob: 6fe77b2c6daffdb1dd15ecc7595d5e1d1aa5215f [file] [log] [blame]
Patrick Ventureda064282018-06-12 19:33:47 -07001#include "util.hpp"
2
Patrick Ventureda064282018-06-12 19:33:47 -07003#include <string>
4
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <gmock/gmock.h>
6#include <gtest/gtest.h>
7
8TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
9{
Patrick Ventureda064282018-06-12 19:33:47 -070010 // Verify it responds to an empty string.
11
12 EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType(""));
13}
14
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070015TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
16{
Patrick Ventureda064282018-06-12 19:33:47 -070017 // Verify it responds to a path of "None"
18
19 EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("None"));
20}
21
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
23{
Patrick Ventureda064282018-06-12 19:33:47 -070024 // 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
31{
Patrick Ventureda064282018-06-12 19:33:47 -070032 // Verify it reports unknown by default.
33
34 std::string path = "/xyz/openbmc_project";
35 EXPECT_EQ(IOInterfaceType::UNKNOWN, GetWriteInterfaceType(path));
36}
37
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070038TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
39{
Patrick Ventureda064282018-06-12 19:33:47 -070040 // Verify it responds to an empty string.
41
42 EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType(""));
43}
44
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070045TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
46{
Patrick Ventureda064282018-06-12 19:33:47 -070047 // Verify it responds to a path of "None"
48
49 EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("None"));
50}
51
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
53{
Patrick Ventureda064282018-06-12 19:33:47 -070054 // 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
61{
Patrick Ventureda064282018-06-12 19:33:47 -070062 // 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070068TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
69{
Patrick Ventureda064282018-06-12 19:33:47 -070070 // 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070076TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
77{
Patrick Ventureda064282018-06-12 19:33:47 -070078 // Verify it reports unknown by default.
79
80 std::string path = "asdf09as0df9a0fd";
81 EXPECT_EQ(IOInterfaceType::UNKNOWN, GetReadInterfaceType(path));
82}