1 #pragma once
2 
3 #include "platform-mc/terminus_manager.hpp"
4 
5 #include <queue>
6 
7 #include <gmock/gmock.h>
8 
9 namespace pldm
10 {
11 namespace platform_mc
12 {
13 
14 class MockTerminusManager : public TerminusManager
15 {
16   public:
MockTerminusManager(sdeventplus::Event & event,RequesterHandler & handler,pldm::InstanceIdDb & instanceIdDb,TerminiMapper & termini,Manager * manager)17     MockTerminusManager(sdeventplus::Event& event, RequesterHandler& handler,
18                         pldm::InstanceIdDb& instanceIdDb,
19                         TerminiMapper& termini, Manager* manager) :
20         TerminusManager(event, handler, instanceIdDb, termini, manager,
21                         pldm::BmcMctpEid)
22     {}
23 
sendRecvPldmMsgOverMctp(mctp_eid_t,Request &,const pldm_msg ** responseMsg,size_t * responseLen)24     exec::task<int> sendRecvPldmMsgOverMctp(
25         mctp_eid_t /*eid*/, Request& /*request*/, const pldm_msg** responseMsg,
26         size_t* responseLen) override
27     {
28         if (responseMsgs.empty() || responseMsg == nullptr ||
29             responseLen == nullptr)
30         {
31             co_return PLDM_ERROR;
32         }
33 
34         *responseMsg = responseMsgs.front();
35         *responseLen = responseLens.front() - sizeof(pldm_msg_hdr);
36 
37         responseMsgs.pop();
38         responseLens.pop();
39         co_return PLDM_SUCCESS;
40     }
41 
enqueueResponse(pldm_msg * responseMsg,size_t responseLen)42     int enqueueResponse(pldm_msg* responseMsg, size_t responseLen)
43     {
44         if (responseMsg == nullptr)
45         {
46             return PLDM_ERROR_INVALID_DATA;
47         }
48 
49         if (responseLen <= sizeof(pldm_msg_hdr))
50         {
51             return PLDM_ERROR_INVALID_LENGTH;
52         }
53 
54         responseMsgs.push(responseMsg);
55         responseLens.push(responseLen);
56         return PLDM_SUCCESS;
57     }
58 
clearQueuedResponses()59     int clearQueuedResponses()
60     {
61         while (!responseMsgs.empty())
62         {
63             responseMsgs.pop();
64             responseLens.pop();
65         }
66         return PLDM_SUCCESS;
67     }
68 
69     std::queue<pldm_msg*> responseMsgs;
70     std::queue<size_t> responseLens;
71 };
72 
73 } // namespace platform_mc
74 } // namespace pldm
75