1*067ece15SWilly Tu #include "helper.hpp"
2ef3aeadcSPatrick Venture #include "ipmi.hpp"
3cd8dab49SPatrick Venture #include "manager_mock.hpp"
4ef3aeadcSPatrick Venture
5ef3aeadcSPatrick Venture #include <cstring>
6ef3aeadcSPatrick Venture #include <string>
7ef3aeadcSPatrick Venture
8ef3aeadcSPatrick Venture #include <gtest/gtest.h>
9ef3aeadcSPatrick Venture
10ef3aeadcSPatrick Venture namespace blobs
11ef3aeadcSPatrick Venture {
12ef3aeadcSPatrick Venture
13ef3aeadcSPatrick Venture using ::testing::Return;
14ef3aeadcSPatrick Venture
TEST(BlobEnumerateTest,VerifyIfRequestByIdInvalidReturnsFailure)15ef3aeadcSPatrick Venture TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure)
16ef3aeadcSPatrick Venture {
17ef3aeadcSPatrick Venture // This tests to verify that if the index is invalid, it'll return failure.
18ef3aeadcSPatrick Venture
19ef3aeadcSPatrick Venture ManagerMock mgr;
20*067ece15SWilly Tu std::vector<uint8_t> request;
21ef3aeadcSPatrick Venture struct BmcBlobEnumerateTx req;
22ef3aeadcSPatrick Venture req.blobIdx = 0;
23*067ece15SWilly Tu
24*067ece15SWilly Tu request.resize(sizeof(struct BmcBlobEnumerateTx));
25*067ece15SWilly Tu std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
26ef3aeadcSPatrick Venture
27ef3aeadcSPatrick Venture EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(""));
28*067ece15SWilly Tu EXPECT_EQ(ipmi::responseInvalidFieldRequest(),
29*067ece15SWilly Tu enumerateBlob(&mgr, request));
30ef3aeadcSPatrick Venture }
31ef3aeadcSPatrick Venture
TEST(BlobEnumerateTest,BoringRequestByIdAndReceive)32ef3aeadcSPatrick Venture TEST(BlobEnumerateTest, BoringRequestByIdAndReceive)
33ef3aeadcSPatrick Venture {
34ef3aeadcSPatrick Venture // This tests that if an index into the blob_id cache is valid, the command
35ef3aeadcSPatrick Venture // will return the blobId.
36ef3aeadcSPatrick Venture
37ef3aeadcSPatrick Venture ManagerMock mgr;
38*067ece15SWilly Tu std::vector<uint8_t> request;
39ef3aeadcSPatrick Venture struct BmcBlobEnumerateTx req;
40*067ece15SWilly Tu req.blobIdx = 0;
41ef3aeadcSPatrick Venture std::string blobId = "/asdf";
42ef3aeadcSPatrick Venture
43*067ece15SWilly Tu request.resize(sizeof(struct BmcBlobEnumerateTx));
44*067ece15SWilly Tu std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
45ef3aeadcSPatrick Venture
46ef3aeadcSPatrick Venture EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
47ef3aeadcSPatrick Venture
48*067ece15SWilly Tu auto result = validateReply(enumerateBlob(&mgr, request));
49ef3aeadcSPatrick Venture
50ef3aeadcSPatrick Venture // We're expecting this as a response.
51ef3aeadcSPatrick Venture // blobId.length + 1 + sizeof(uint16_t);
52*067ece15SWilly Tu EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), result.size());
53*067ece15SWilly Tu EXPECT_EQ(blobId,
54*067ece15SWilly Tu // Remove crc and nul-terminator.
55*067ece15SWilly Tu std::string(result.begin() + sizeof(uint16_t), result.end() - 1));
56ef3aeadcSPatrick Venture }
57ef3aeadcSPatrick Venture } // namespace blobs
58