diff options
| author | Patrick Venture <venture@google.com> | 2019-06-27 12:09:52 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2019-06-28 08:23:43 -0700 |
| commit | cf9b2195a3509b7481cbe564b0fc290c9bfc1475 (patch) | |
| tree | 58786be59d2759ee9f77d21ae77f37acd8780bbd /tools/test | |
| parent | a29216eccb47ab8d0fa50c78184dcfdd598f7725 (diff) | |
| download | phosphor-ipmi-flash-cf9b2195a3509b7481cbe564b0fc290c9bfc1475.tar.gz phosphor-ipmi-flash-cf9b2195a3509b7481cbe564b0fc290c9bfc1475.zip | |
tools: add progress implementation
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I9da1674d6cbc688efc7bab0e033788d6ee4694f7
Diffstat (limited to 'tools/test')
| -rw-r--r-- | tools/test/internal_sys_mock.hpp | 3 | ||||
| -rw-r--r-- | tools/test/progress_mock.hpp | 19 | ||||
| -rw-r--r-- | tools/test/tools_bt_unittest.cpp | 9 | ||||
| -rw-r--r-- | tools/test/tools_lpc_unittest.cpp | 11 |
4 files changed, 40 insertions, 2 deletions
diff --git a/tools/test/internal_sys_mock.hpp b/tools/test/internal_sys_mock.hpp index fc98561..06aa023 100644 --- a/tools/test/internal_sys_mock.hpp +++ b/tools/test/internal_sys_mock.hpp @@ -4,6 +4,8 @@ #include <unistd.h> +#include <cstdint> + #include <gmock/gmock.h> namespace internal @@ -22,6 +24,7 @@ class InternalSysMock : public Sys MOCK_CONST_METHOD0(getpagesize, int()); MOCK_CONST_METHOD3(ioctl, int(int, unsigned long, void*)); MOCK_CONST_METHOD3(poll, int(struct pollfd*, nfds_t, int)); + MOCK_CONST_METHOD1(getSize, std::int64_t(const char*)); }; } // namespace internal diff --git a/tools/test/progress_mock.hpp b/tools/test/progress_mock.hpp new file mode 100644 index 0000000..80c0af1 --- /dev/null +++ b/tools/test/progress_mock.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "progress.hpp" + +#include <cstdint> + +#include <gmock/gmock.h> + +namespace host_tool +{ + +class ProgressMock : public ProgressInterface +{ + public: + MOCK_METHOD1(updateProgress, void(std::int64_t)); + MOCK_METHOD1(start, void(std::int64_t)); +}; + +} // namespace host_tool diff --git a/tools/test/tools_bt_unittest.cpp b/tools/test/tools_bt_unittest.cpp index 1a364d3..cca0b34 100644 --- a/tools/test/tools_bt_unittest.cpp +++ b/tools/test/tools_bt_unittest.cpp @@ -1,5 +1,6 @@ #include "bt.hpp" #include "internal_sys_mock.hpp" +#include "progress_mock.hpp" #include <cstring> #include <ipmiblob/test/blob_interface_mock.hpp> @@ -8,6 +9,8 @@ namespace host_tool { +namespace +{ using ::testing::_; using ::testing::ContainerEq; @@ -23,14 +26,17 @@ TEST(BtHandlerTest, verifySendsFileContents) */ internal::InternalSysMock sysMock; ipmiblob::BlobInterfaceMock blobMock; + ProgressMock progMock; - BtDataHandler handler(&blobMock, &sysMock); + BtDataHandler handler(&blobMock, &progMock, &sysMock); std::string filePath = "/asdf"; int fd = 1; std::uint16_t session = 0xbeef; std::vector<std::uint8_t> bytes = {'1', '2', '3', '4'}; + const int fakeFileSize = 100; EXPECT_CALL(sysMock, open(Eq(filePath), _)).WillOnce(Return(fd)); + EXPECT_CALL(sysMock, getSize(Eq(filePath))).WillOnce(Return(fakeFileSize)); EXPECT_CALL(sysMock, read(fd, NotNull(), _)) .WillOnce(Invoke([&](int fd, void* buf, std::size_t count) { EXPECT_TRUE(count > bytes.size()); @@ -45,4 +51,5 @@ TEST(BtHandlerTest, verifySendsFileContents) EXPECT_TRUE(handler.sendContents(filePath, session)); } +} // namespace } // namespace host_tool diff --git a/tools/test/tools_lpc_unittest.cpp b/tools/test/tools_lpc_unittest.cpp index 84a81eb..9e417ed 100644 --- a/tools/test/tools_lpc_unittest.cpp +++ b/tools/test/tools_lpc_unittest.cpp @@ -1,6 +1,7 @@ #include "internal_sys_mock.hpp" #include "io_mock.hpp" #include "lpc.hpp" +#include "progress_mock.hpp" #include <cstring> #include <ipmiblob/test/blob_interface_mock.hpp> @@ -9,6 +10,8 @@ namespace host_tool { +namespace +{ using ::testing::_; using ::testing::ContainerEq; @@ -23,14 +26,17 @@ TEST(LpcHandleTest, verifySendsFileContents) internal::InternalSysMock sysMock; ipmiblob::BlobInterfaceMock blobMock; HostIoInterfaceMock ioMock; + ProgressMock progMock; const std::uint32_t address = 0xfedc1000; const std::uint32_t length = 0x1000; - LpcDataHandler handler(&blobMock, &ioMock, address, length, &sysMock); + LpcDataHandler handler(&blobMock, &ioMock, address, length, &progMock, + &sysMock); std::uint16_t session = 0xbeef; std::string filePath = "/asdf"; int fileDescriptor = 5; + const int fakeFileSize = 100; LpcRegion host_lpc_buf; host_lpc_buf.address = address; @@ -45,6 +51,8 @@ TEST(LpcHandleTest, verifySendsFileContents) EXPECT_CALL(sysMock, open(StrEq(filePath.c_str()), _)) .WillOnce(Return(fileDescriptor)); + EXPECT_CALL(sysMock, getSize(StrEq(filePath.c_str()))) + .WillOnce(Return(fakeFileSize)); EXPECT_CALL(sysMock, read(_, NotNull(), Gt(data.size()))) .WillOnce(Invoke([&data](int, void* buf, std::size_t) { std::memcpy(buf, data.data(), data.size()); @@ -66,4 +74,5 @@ TEST(LpcHandleTest, verifySendsFileContents) EXPECT_TRUE(handler.sendContents(filePath, session)); } +} // namespace } // namespace host_tool |

