hunting/test/utils/McuProtocol/tool/src/ProtocolMonitor.cpp
2024-05-14 19:56:06 +08:00

52 lines
2.2 KiB
C++

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ProtocolMonitor.h"
#include "ILog.h"
std::shared_ptr<ProtocolMonitor> &ProtocolMonitor::GetInstance(std::shared_ptr<ProtocolMonitor> *impl)
{
static auto instance = std::make_shared<ProtocolMonitor>();
if (impl) {
if (instance.use_count() == 1) {
LogInfo("Instance changed succeed.\n");
instance = *impl;
}
else {
LogError("Can't changing the instance becase of using by some one.\n");
}
}
return instance;
}
void ProtocolMonitor::MonitorWriteProtocolData(const short &head, const unsigned int &serialNumber,
const short &command, const void *data, const short &packetLength)
{
}
void ProtocolMonitorTest::Init(std::shared_ptr<ProtocolMonitorTest> &test)
{
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return()));
}
void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &test, const short &head,
const unsigned int &serialNumber, const short &command, const void *data,
const short &packetLength)
{
auto printfParam = [=](const short &head,
const unsigned int &serialNumber,
const short &command,
const void *data,
const short &packetLength) {
};
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
.Times(1)
.WillOnce(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(printfParam)), Return()));
}