Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 1 | #include "util.hpp" |
| 2 | |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 3 | #include <string> |
| 4 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 5 | #include <gmock/gmock.h> |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE) |
| 9 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 10 | // Verify it responds to an empty string. |
| 11 | |
| 12 | EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("")); |
| 13 | } |
| 14 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 15 | TEST(UtilTest, WriteTypeNonePath_ReturnsNONE) |
| 16 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 17 | // Verify it responds to a path of "None" |
| 18 | |
| 19 | EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("None")); |
| 20 | } |
| 21 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 22 | TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS) |
| 23 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 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 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 30 | TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN) |
| 31 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 32 | // Verify it reports unknown by default. |
| 33 | |
| 34 | std::string path = "/xyz/openbmc_project"; |
| 35 | EXPECT_EQ(IOInterfaceType::UNKNOWN, GetWriteInterfaceType(path)); |
| 36 | } |
| 37 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 38 | TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE) |
| 39 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 40 | // Verify it responds to an empty string. |
| 41 | |
| 42 | EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("")); |
| 43 | } |
| 44 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 45 | TEST(UtilTest, ReadTypeNonePath_ReturnsNONE) |
| 46 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 47 | // Verify it responds to a path of "None" |
| 48 | |
| 49 | EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("None")); |
| 50 | } |
| 51 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 52 | TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL) |
| 53 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 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 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 60 | TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE) |
| 61 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 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 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 68 | TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS) |
| 69 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 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 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 76 | TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN) |
| 77 | { |
Patrick Venture | da06428 | 2018-06-12 19:33:47 -0700 | [diff] [blame] | 78 | // Verify it reports unknown by default. |
| 79 | |
| 80 | std::string path = "asdf09as0df9a0fd"; |
| 81 | EXPECT_EQ(IOInterfaceType::UNKNOWN, GetReadInterfaceType(path)); |
| 82 | } |