Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 1 | #include "helper.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 2 | #include "ipmi.hpp" |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 3 | #include "manager_mock.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 4 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 5 | #include <cstring> |
| 6 | #include <vector> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace blobs |
| 11 | { |
| 12 | |
| 13 | using ::testing::Return; |
| 14 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 15 | // the request here is only the subcommand byte and therefore there's no invalid |
| 16 | // length check, etc to handle within the method. |
| 17 | |
| 18 | TEST(BlobCountTest, ReturnsZeroBlobs) |
| 19 | { |
| 20 | // Calling BmcBlobGetCount if there are no handlers registered should just |
| 21 | // return that there are 0 blobs. |
| 22 | |
| 23 | ManagerMock mgr; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 24 | struct BmcBlobCountRx rep; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 25 | |
| 26 | rep.crc = 0; |
| 27 | rep.blobCount = 0; |
| 28 | |
| 29 | EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(0)); |
| 30 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 31 | auto result = validateReply(getBlobCount(&mgr, {})); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 32 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 33 | EXPECT_EQ(sizeof(rep), result.size()); |
| 34 | EXPECT_EQ(0, std::memcmp(result.data(), &rep, sizeof(rep))); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | TEST(BlobCountTest, ReturnsTwoBlobs) |
| 38 | { |
| 39 | // Calling BmcBlobGetCount with one handler registered that knows of two |
| 40 | // blobs will return that it found two blobs. |
| 41 | |
| 42 | ManagerMock mgr; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 43 | struct BmcBlobCountRx rep; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 44 | |
| 45 | rep.crc = 0; |
| 46 | rep.blobCount = 2; |
| 47 | |
| 48 | EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(2)); |
| 49 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 50 | auto result = validateReply(getBlobCount(&mgr, {})); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 51 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 52 | EXPECT_EQ(sizeof(rep), result.size()); |
| 53 | EXPECT_EQ(0, std::memcmp(result.data(), &rep, sizeof(rep))); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 54 | } |
| 55 | } // namespace blobs |