hunting/test/middleware/McuAskBase/tool/src/McuAskBaseTestTool.cpp
2024-03-12 14:46:12 +08:00

71 lines
3.0 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 "McuAskBaseTestTool.h"
#include "ILog.h"
constexpr int CALL_ONLY_ONCE = 1;
constexpr int SHOULD_NOT_CALL = 0;
ASK_RESULT McuAskBaseTest::Blocking(void)
{
BlockingTrace();
return McuAskBase::Blocking();
}
bool McuAskBaseTest::NeedReply(void)
{
NeedReplyTrace();
return McuAskBase::NeedReply();
}
void McuAskBaseTest::ReplyFinished(const bool result)
{
ReplyFinishedTrace(result);
McuAskBase::ReplyFinished(result);
}
bool McuAskBaseTest::IfTimeout(const unsigned int &integrationTimeMs)
{
IfTimeoutTrace(integrationTimeMs);
return McuAskBase::IfTimeout(integrationTimeMs);
}
void McuAskBaseTestTool::McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestTool> &mock)
{
if (McuAskBlock::BLOCK == mIsBlock && McuAskReply::NEED_REPLY == mNeedReply) {
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(CALL_ONLY_ONCE);
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AtLeast(1));
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(CALL_ONLY_ONCE);
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(AnyNumber());
}
if (McuAskBlock::NOT_BLOCK == mIsBlock && McuAskReply::NEED_REPLY == mNeedReply) {
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(CALL_ONLY_ONCE);
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AtLeast(1));
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(CALL_ONLY_ONCE);
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(AnyNumber());
}
if (McuAskBlock::UNRELATED == mIsBlock && McuAskReply::NEED_NOT_REPLY == mNeedReply) {
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(SHOULD_NOT_CALL);
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AtLeast(1));
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(SHOULD_NOT_CALL);
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(SHOULD_NOT_CALL);
}
}
void McuAskBaseTestTool::McuAskDoNothing(std::shared_ptr<McuAskBaseTestTool> &mock)
{
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(AnyNumber());
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AnyNumber());
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(AnyNumber());
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(AnyNumber());
}
void McuAskBaseTestTool::NoNeedToBlocking(std::shared_ptr<McuAskBaseTestTool> &mock)
{
// Mock::AllowLeak(mock.get());
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(SHOULD_NOT_CALL);
}