diff options
Diffstat (limited to 'test/oemrouter_unittest.cpp')
-rw-r--r-- | test/oemrouter_unittest.cpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/test/oemrouter_unittest.cpp b/test/oemrouter_unittest.cpp index a5a79dd..b48798b 100644 --- a/test/oemrouter_unittest.cpp +++ b/test/oemrouter_unittest.cpp @@ -1,8 +1,10 @@ -#include "host-ipmid/ipmid-api.h" #include "host-ipmid/oemrouter.hpp" -#include "sample.h" #include <cstring> + +#include "host-ipmid/ipmid-api.h" +#include "sample.h" + #include <gtest/gtest.h> // Watch for correct singleton behavior. @@ -52,19 +54,18 @@ void RegisterWithRouter(Number oen, ipmi_cmd_t cmd, Handler cb) singletonUnderTest->registerHandler(oen, cmd, cb); } -uint8_t msgPlain[] = { 0x56, 0x34, 0x12 }; -uint8_t replyPlain[] = { 0x56, 0x34, 0x12, 0x31, 0x41 }; -uint8_t msgPlus2[] = { 0x67, 0x45, 0x23, 0x10, 0x20 }; -uint8_t msgBadOen[] = { 0x57, 0x34, 0x12 }; +uint8_t msgPlain[] = {0x56, 0x34, 0x12}; +uint8_t replyPlain[] = {0x56, 0x34, 0x12, 0x31, 0x41}; +uint8_t msgPlus2[] = {0x67, 0x45, 0x23, 0x10, 0x20}; +uint8_t msgBadOen[] = {0x57, 0x34, 0x12}; -void RegisterTwoWays(ipmi_cmd_t *nextCmd) +void RegisterTwoWays(ipmi_cmd_t* nextCmd) { - Handler f = [](ipmi_cmd_t cmd, const uint8_t* reqBuf, - uint8_t* replyBuf, size_t* dataLen) - { + Handler f = [](ipmi_cmd_t cmd, const uint8_t* reqBuf, uint8_t* replyBuf, + size_t* dataLen) { // Check inputs EXPECT_EQ(0x78, cmd); - EXPECT_EQ(0, *dataLen); // Excludes OEN + EXPECT_EQ(0, *dataLen); // Excludes OEN // Generate reply. *dataLen = 2; @@ -75,11 +76,10 @@ void RegisterTwoWays(ipmi_cmd_t *nextCmd) *nextCmd = IPMI_CMD_WILDCARD; Handler g = [nextCmd](ipmi_cmd_t cmd, const uint8_t* reqBuf, - uint8_t* replyBuf, size_t* dataLen) - { + uint8_t* replyBuf, size_t* dataLen) { // Check inputs EXPECT_EQ(*nextCmd, cmd); - EXPECT_EQ(2, *dataLen); // Excludes OEN + EXPECT_EQ(2, *dataLen); // Excludes OEN if (2 != *dataLen) { return 0xE0; @@ -93,18 +93,21 @@ void RegisterTwoWays(ipmi_cmd_t *nextCmd) }; RegisterWithRouter(0x234567, IPMI_CMD_WILDCARD, g); } -} // namespace +} // namespace -TEST(OemRouterTest, MakeRouterProducesConsistentSingleton) { +TEST(OemRouterTest, MakeRouterProducesConsistentSingleton) +{ MakeRouter(); } -TEST(OemRouterTest, ActivateRouterSetsLastNetToOEMGROUP) { +TEST(OemRouterTest, ActivateRouterSetsLastNetToOEMGROUP) +{ lastNetFunction = 0; ActivateRouter(); } -TEST(OemRouterTest, VerifiesSpecificCommandMatches) { +TEST(OemRouterTest, VerifiesSpecificCommandMatches) +{ ipmi_cmd_t cmd; uint8_t reply[256]; size_t dataLen; @@ -112,9 +115,8 @@ TEST(OemRouterTest, VerifiesSpecificCommandMatches) { RegisterTwoWays(&cmd); dataLen = 3; - EXPECT_EQ(0, - wildHandler(NETFUN_OEM_GROUP, 0x78, msgPlain, reply, - &dataLen, nullptr)); + EXPECT_EQ(0, wildHandler(NETFUN_OEM_GROUP, 0x78, msgPlain, reply, &dataLen, + nullptr)); EXPECT_EQ(5, dataLen); EXPECT_EQ(replyPlain[0], reply[0]); EXPECT_EQ(replyPlain[1], reply[1]); @@ -123,7 +125,8 @@ TEST(OemRouterTest, VerifiesSpecificCommandMatches) { EXPECT_EQ(replyPlain[4], reply[4]); } -TEST(OemRouterTest, WildCardMatchesTwoRandomCodes) { +TEST(OemRouterTest, WildCardMatchesTwoRandomCodes) +{ ipmi_cmd_t cmd; uint8_t reply[256]; size_t dataLen; @@ -133,20 +136,19 @@ TEST(OemRouterTest, WildCardMatchesTwoRandomCodes) { // Check two random command codes. dataLen = 5; cmd = 0x89; - EXPECT_EQ(0, - wildHandler(NETFUN_OEM_GROUP, cmd, msgPlus2, reply, - &dataLen, nullptr)); + EXPECT_EQ(0, wildHandler(NETFUN_OEM_GROUP, cmd, msgPlus2, reply, &dataLen, + nullptr)); EXPECT_EQ(3, dataLen); dataLen = 5; cmd = 0x67; - EXPECT_EQ(0, - wildHandler(NETFUN_OEM_GROUP, cmd, msgPlus2, reply, - &dataLen, nullptr)); + EXPECT_EQ(0, wildHandler(NETFUN_OEM_GROUP, cmd, msgPlus2, reply, &dataLen, + nullptr)); EXPECT_EQ(3, dataLen); } -TEST(OemRouterTest, CommandsAreRejectedIfInvalid) { +TEST(OemRouterTest, CommandsAreRejectedIfInvalid) +{ ipmi_cmd_t cmd; uint8_t reply[256]; size_t dataLen; @@ -156,20 +158,18 @@ TEST(OemRouterTest, CommandsAreRejectedIfInvalid) { // Message too short to include whole OEN? dataLen = 2; EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, - wildHandler(NETFUN_OEM_GROUP, 0x78, msgPlain, reply, - &dataLen, nullptr)); + wildHandler(NETFUN_OEM_GROUP, 0x78, msgPlain, reply, &dataLen, + nullptr)); // Wrong specific command? dataLen = 3; - EXPECT_EQ(IPMI_CC_INVALID, - wildHandler(NETFUN_OEM_GROUP, 0x89, msgPlain, reply, - &dataLen, nullptr)); + EXPECT_EQ(IPMI_CC_INVALID, wildHandler(NETFUN_OEM_GROUP, 0x89, msgPlain, + reply, &dataLen, nullptr)); // Wrong OEN? dataLen = 3; - EXPECT_EQ(IPMI_CC_INVALID, - wildHandler(NETFUN_OEM_GROUP, 0x78, msgBadOen, reply, - &dataLen, nullptr)); + EXPECT_EQ(IPMI_CC_INVALID, wildHandler(NETFUN_OEM_GROUP, 0x78, msgBadOen, + reply, &dataLen, nullptr)); } -} // namespace oem +} // namespace oem |