embedded-framework/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp
2024-03-03 19:04:45 -08:00

77 lines
2.9 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 "AppManagerTestTool.h"
#include "AppManagerMakePtrTest.h"
#include "AppManagerMock.h"
#include "AppMonitorMock.h"
#include "ILog.h"
#include "ServersMock.h"
void AppManagerTestTool::Init(void)
{
mAppManagerMock = std::make_shared<AppManagerMock>();
AppManagerMockInit(mAppManagerMock);
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(mAppManagerMock);
OverrideAppManagerMakePtrObject(mock);
}
void AppManagerTestTool::UnInit(void)
{
mAppManagerMock.reset();
mAppMonitorMock.reset();
CancelOverrideAppManagerMakePtrObject();
}
void AppManagerTestTool::MockGetProductInfo(void)
{
//
ServersMock::GetInstance()->MockGetProductInfo();
}
void AppManagerTestTool::MockUploadFiles(void)
{
//
ServersMock::GetInstance()->MockUploadFiles();
}
void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
{
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(vMock);
if (!mock) {
LogError("vMock error.\n");
return;
}
auto getAppMonitor = [=](std::shared_ptr<VAppMonitor> &monitor) {
LogInfo("mAppMonitorMock get.\n");
mAppMonitorMock = std::dynamic_pointer_cast<AppMonitorMock>(monitor);
AppManagerTestTool::AppMonitorInit(mAppMonitorMock);
};
constexpr int ONLY_BE_CALLED_ONCE = 1;
EXPECT_CALL(*mock.get(), SetAppMonitorTrace(_))
.Times(ONLY_BE_CALLED_ONCE)
.WillOnce(DoAll(WithArgs<0>(Invoke(getAppMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
}
std::shared_ptr<VAppMonitor> AppManagerTestTool::MakeMonitorMock(void)
{
auto monitor = std::make_shared<AppMonitorMock>();
EXPECT_CALL(*monitor.get(), GetProductInfoTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
EXPECT_CALL(*monitor.get(), UploadFileTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
return monitor;
}
void AppManagerTestTool::AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock)
{
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(vMock);
if (mock) {
EXPECT_CALL(*mock.get(), UploadFileTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
}
}