blob: 93887d2634d4158275ca54b627a5b68ca688abe1 [file] [log] [blame]
#include "data_mock.hpp"
#include "firmware_handler.hpp"
#include "image_mock.hpp"
#include "util.hpp"
#include "verification_mock.hpp"
#include <memory>
#include <vector>
#include <gtest/gtest.h>
namespace blobs
{
using ::testing::Eq;
using ::testing::Return;
class FirmwareHandlerWriteMetaTest : public ::testing::Test
{
protected:
DataHandlerMock dataMock;
ImageHandlerMock imageMock1, imageMock2;
std::vector<HandlerPack> blobs;
std::vector<DataHandlerPack> data;
std::unique_ptr<GenericBlobInterface> handler;
void SetUp() override
{
blobs = {
{hashBlobId, &imageMock1},
{"asdf", &imageMock2},
};
data = {
{FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
{FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
};
handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
blobs, data, CreateVerifyMock());
}
};
TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
{
EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
EXPECT_TRUE(handler->open(
0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
std::vector<std::uint8_t> bytes = {0xaa, 0x55};
EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
}
TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
{
EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
EXPECT_TRUE(handler->open(
0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
}
} // namespace blobs