/* * 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(); AppManagerMockInit(mAppManagerMock); std::shared_ptr mock = std::dynamic_pointer_cast(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 &vMock) { std::shared_ptr mock = std::dynamic_pointer_cast(vMock); if (!mock) { LogError("vMock error.\n"); return; } auto getAppMonitor = [=](std::shared_ptr &monitor) { LogInfo("mAppMonitorMock get.\n"); mAppMonitorMock = std::dynamic_pointer_cast(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 AppManagerTestTool::MakeMonitorMock(void) { auto monitor = std::make_shared(); 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 &vMock) { std::shared_ptr mock = std::dynamic_pointer_cast(vMock); if (mock) { EXPECT_CALL(*mock.get(), UploadFileTrace(_)) .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } }