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