Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame^] | 1 | #include "commands.hpp" |
Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 2 | #include "entity_name.hpp" |
| 3 | #include "handler_mock.hpp" |
Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 4 | |
| 5 | #include <cstdint> |
| 6 | #include <cstring> |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | #define MAX_IPMI_BUFFER 64 |
| 13 | |
| 14 | using ::testing::Return; |
| 15 | |
| 16 | namespace google |
| 17 | { |
| 18 | namespace ipmi |
| 19 | { |
| 20 | |
| 21 | TEST(EntityNameCommandTest, InvalidCommandLength) |
| 22 | { |
| 23 | // GetEntityNameRequest is three bytes, let's send 2. |
| 24 | std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, 0x01}; |
| 25 | size_t dataLen = request.size(); |
| 26 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 27 | |
| 28 | HandlerMock hMock; |
| 29 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 30 | getEntityName(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | TEST(EntityNameCommandTest, ValidRequest) |
| 34 | { |
| 35 | std::uint8_t entityId = 3; |
| 36 | std::uint8_t entityInstance = 5; |
| 37 | std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, |
| 38 | entityId, entityInstance}; |
| 39 | size_t dataLen = request.size(); |
| 40 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 41 | std::string entityName = "asdf"; |
| 42 | |
| 43 | HandlerMock hMock; |
| 44 | EXPECT_CALL(hMock, getEntityName(entityId, entityInstance)) |
| 45 | .WillOnce(Return(entityName)); |
| 46 | EXPECT_EQ(IPMI_CC_OK, |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 47 | getEntityName(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 48 | EXPECT_EQ(reply[1], entityName.length()); |
| 49 | EXPECT_EQ(0, std::memcmp(&reply[2], entityName.c_str(), reply[1])); |
| 50 | } |
| 51 | |
| 52 | } // namespace ipmi |
| 53 | } // namespace google |