1 #include "helper.hpp" 2 #include "status.hpp" 3 4 #include <ipmiblob/test/blob_interface_mock.hpp> 5 6 #include <cstdint> 7 8 #include <gtest/gtest.h> 9 10 namespace host_tool 11 { 12 using ::testing::Return; 13 using ::testing::TypedEq; 14 15 class HelperTest : public ::testing::Test 16 { 17 protected: 18 ipmiblob::BlobInterfaceMock blobMock; 19 std::uint16_t session = 0xbeef; 20 }; 21 22 TEST_F(HelperTest, PollStatusReturnsAfterSuccess) 23 { 24 ipmiblob::StatResponse verificationResponse = {}; 25 /* the other details of the response are ignored, and should be. */ 26 verificationResponse.metadata.push_back( 27 static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); 28 29 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) 30 .WillOnce(Return(verificationResponse)); 31 32 EXPECT_TRUE(pollStatus(session, &blobMock)); 33 } 34 35 TEST_F(HelperTest, PollStatusReturnsAfterFailure) 36 { 37 ipmiblob::StatResponse verificationResponse = {}; 38 /* the other details of the response are ignored, and should be. */ 39 verificationResponse.metadata.push_back( 40 static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed)); 41 42 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) 43 .WillOnce(Return(verificationResponse)); 44 45 EXPECT_FALSE(pollStatus(session, &blobMock)); 46 } 47 48 TEST_F(HelperTest, MemcpyAlignedOneByte) 49 { 50 const char source = 'a'; 51 char destination; 52 53 EXPECT_EQ(&destination, 54 memcpyAligned(&destination, &source, sizeof(source))); 55 EXPECT_EQ(destination, source); 56 } 57 58 TEST_F(HelperTest, MemcpyAlignedMultiByte) 59 { 60 const char source[14] = "abcdefghijklm"; 61 char destination[14] = "xxxxxxxxxxxxx"; 62 63 EXPECT_EQ(&destination, 64 memcpyAligned(&destination, &source, sizeof(source))); 65 EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source))); 66 } 67 68 } // namespace host_tool 69