1ded66d0fSJason Ling #include "data_mock.hpp"
2ded66d0fSJason Ling #include "firmware_handler.hpp"
3ded66d0fSJason Ling #include "firmware_unittest.hpp"
4ded66d0fSJason Ling #include "image_mock.hpp"
5ded66d0fSJason Ling #include "triggerable_mock.hpp"
6ded66d0fSJason Ling #include "util.hpp"
7ded66d0fSJason Ling
8ded66d0fSJason Ling #include <memory>
9ded66d0fSJason Ling #include <vector>
10ded66d0fSJason Ling
11ded66d0fSJason Ling #include <gmock/gmock.h>
12ded66d0fSJason Ling #include <gtest/gtest.h>
13ded66d0fSJason Ling
14ded66d0fSJason Ling namespace ipmi_flash
15ded66d0fSJason Ling {
16ded66d0fSJason Ling namespace
17ded66d0fSJason Ling {
18ded66d0fSJason Ling
19ded66d0fSJason Ling using ::testing::Return;
20ded66d0fSJason Ling using ::testing::StrEq;
21ded66d0fSJason Ling
22ded66d0fSJason Ling class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest
23ded66d0fSJason Ling {};
24ded66d0fSJason Ling
TEST_F(FirmwareHandlerCloseTest,CloseSucceedsWithDataHandler)25ded66d0fSJason Ling TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler)
26ded66d0fSJason Ling {
27ded66d0fSJason Ling /* Boring test where you open a blob_id, then verify that when it's closed
28ded66d0fSJason Ling * everything looks right.
29ded66d0fSJason Ling */
30ded66d0fSJason Ling EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
3156a2273fSJason Ling EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId), std::ios::out))
3256a2273fSJason Ling .WillOnce(Return(true));
33ded66d0fSJason Ling
34*b487eb47SWilly Tu EXPECT_TRUE(
35*b487eb47SWilly Tu handler->open(0,
36*b487eb47SWilly Tu static_cast<std::uint16_t>(blobs::OpenFlags::write) |
37*b487eb47SWilly Tu FirmwareFlags::UpdateFlags::lpc,
38ded66d0fSJason Ling hashBlobId));
39ded66d0fSJason Ling
40ded66d0fSJason Ling /* The active hash blob_id was added. */
41ded66d0fSJason Ling auto currentBlobs = handler->getBlobIds();
42ded66d0fSJason Ling EXPECT_EQ(3, currentBlobs.size());
43ded66d0fSJason Ling EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
44ded66d0fSJason Ling activeHashBlobId));
45ded66d0fSJason Ling
46ded66d0fSJason Ling /* Set up close() expectations. */
47ded66d0fSJason Ling EXPECT_CALL(*dataMock, close());
48ded66d0fSJason Ling EXPECT_CALL(*hashImageMock, close());
49ded66d0fSJason Ling EXPECT_TRUE(handler->close(0));
50ded66d0fSJason Ling
51ded66d0fSJason Ling /* Close does not delete the active blob id. This indicates that there is
52ded66d0fSJason Ling * data queued.
53ded66d0fSJason Ling */
54ded66d0fSJason Ling }
55ded66d0fSJason Ling
TEST_F(FirmwareHandlerCloseTest,CloseSucceedsWithoutDataHandler)56ded66d0fSJason Ling TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler)
57ded66d0fSJason Ling {
58ded66d0fSJason Ling /* Boring test where you open a blob_id using ipmi, so there's no data
59ded66d0fSJason Ling * handler, and it's closed and everything looks right.
60ded66d0fSJason Ling */
6156a2273fSJason Ling EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId), std::ios::out))
6256a2273fSJason Ling .WillOnce(Return(true));
63ded66d0fSJason Ling
64*b487eb47SWilly Tu EXPECT_TRUE(
65*b487eb47SWilly Tu handler->open(0,
66*b487eb47SWilly Tu static_cast<std::uint16_t>(blobs::OpenFlags::write) |
67*b487eb47SWilly Tu FirmwareFlags::UpdateFlags::ipmi,
68ded66d0fSJason Ling hashBlobId));
69ded66d0fSJason Ling
70ded66d0fSJason Ling /* The active hash blob_id was added. */
71ded66d0fSJason Ling auto currentBlobs = handler->getBlobIds();
72ded66d0fSJason Ling EXPECT_EQ(3, currentBlobs.size());
73ded66d0fSJason Ling EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
74ded66d0fSJason Ling activeHashBlobId));
75ded66d0fSJason Ling
76ded66d0fSJason Ling /* Set up close() expectations. */
77ded66d0fSJason Ling EXPECT_CALL(*hashImageMock, close());
78ded66d0fSJason Ling EXPECT_TRUE(handler->close(0));
79ded66d0fSJason Ling }
80ded66d0fSJason Ling
81ded66d0fSJason Ling } // namespace
82ded66d0fSJason Ling } // namespace ipmi_flash
83