/* * 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 "MediaManagerTestTool.h" #include "ILog.h" #include "MediaManagerMakePtrTest.h" #include "MediaManagerMock.h" #include "MediaMonitorMock.h" constexpr int ONLY_BE_CALLED_ONCE = 1; void MediaManagerTestTool::Init(void) { mMediaManagerMock = std::make_shared(); MediaManagerMockInit(mMediaManagerMock); std::shared_ptr mock = std::dynamic_pointer_cast(mMediaManagerMock); OverrideMediaManagerMakePtrObject(mock); } void MediaManagerTestTool::UnInit(void) { mMediaManagerMock.reset(); mMediaMonitorMock.reset(); CancelOverrideMediaManagerMakePtrObject(); } void MediaManagerTestTool::MediaManagerMockInit(std::shared_ptr &vMock) { std::shared_ptr mock = std::dynamic_pointer_cast(vMock); if (!mock) { LogError("vMock error.\n"); return; } auto getMediaMonitor = [=](std::shared_ptr &monitor) { LogInfo("mMediaMonitorMock get.\n"); mMediaMonitorMock = monitor; MediaManagerTestTool::MediaMonitorInit(mMediaMonitorMock); }; EXPECT_CALL(*mock.get(), SetMediaMonitorTrace(_)) .Times(ONLY_BE_CALLED_ONCE) .WillOnce(DoAll(WithArgs<0>(Invoke(getMediaMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } void MediaManagerTestTool::MediaMonitorInit(std::shared_ptr &vMock) { std::shared_ptr mock = std::dynamic_pointer_cast(vMock); if (mock) { // EXPECT_CALL(*mock.get(), GetProductInfoTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetDeviceAttrTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetMediaInfoTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetParamValueTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetCapabilityTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetLockVideoStatusTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetStorageInfoTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetStorageFileListTrace(_, _)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), SetTimeZoneTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), SetParamValueTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), EnterRecorderTrace()) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), MediaPlaybackTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), UploadFileTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), GetThumbnailTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); // EXPECT_CALL(*mock.get(), MediaClientConnectedTrace(_)) // .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } } std::shared_ptr MediaManagerTestTool::MakeMonitorMock(void) { class Monitor : public MediaMonitorMock, public MediaMonitorTest { public: Monitor() = default; virtual ~Monitor() = default; }; std::shared_ptr monitor = std::make_shared(); return monitor; }