add handler logic to handle SysGetEthDevice
Add a handler to handle code logic outside of the actual IPMI
processing.
Tested: Only ran unit-tests (added new ones).
Change-Id: Iadd8c4f2d9b3e2cfba24ae32cda2ef66177b1177
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/eth_unittest.cpp b/test/eth_unittest.cpp
index f0e4d23..dd3c73f 100644
--- a/test/eth_unittest.cpp
+++ b/test/eth_unittest.cpp
@@ -1,14 +1,19 @@
#include "eth.hpp"
+#include "handler_mock.hpp"
#include "main.hpp"
#include <cstdint>
#include <cstring>
+#include <string>
+#include <tuple>
#include <vector>
#include <gtest/gtest.h>
#define MAX_IPMI_BUFFER 64
+using ::testing::Return;
+
namespace google
{
namespace ipmi
@@ -22,12 +27,21 @@
size_t dataLen = request.size();
std::uint8_t reply[MAX_IPMI_BUFFER];
const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'};
+ const std::uint8_t expectedChannel = 1;
- EXPECT_EQ(IPMI_CC_OK, GetEthDevice(request.data(), &reply[0], &dataLen));
+ HandlerMock hMock;
+ EXPECT_CALL(hMock, getEthDetails())
+ .WillOnce(Return(std::make_tuple(
+ expectedChannel,
+ std::string(expectedAnswer,
+ expectedAnswer + sizeof(expectedAnswer)))));
+
+ EXPECT_EQ(IPMI_CC_OK,
+ GetEthDevice(request.data(), &reply[0], &dataLen, &hMock));
struct EthDeviceReply check;
std::memcpy(&check, &reply[0], sizeof(check));
EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice);
- EXPECT_EQ(check.channel, 1);
+ EXPECT_EQ(check.channel, expectedChannel);
EXPECT_EQ(check.if_name_len, sizeof(expectedAnswer));
EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)],
sizeof(expectedAnswer)));