From ed9771b5b564d902208e6b8a5cfe5764fbfcf3cd Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Thu, 25 Apr 2024 16:46:33 +0800 Subject: [PATCH] Backup:MediaManager module. --- hal/abstract/IHalCpp.cpp | 11 +- hal/include/IHalCpp.h | 26 +- middleware/MediaManager/CMakeLists.txt | 1 + .../MediaManager/include/IMediaManager.h | 47 +-- middleware/MediaManager/src/IMediaManager.cpp | 24 +- .../MediaManager/src/MediaManagerImpl.cpp | 14 +- .../MediaManager/src/MediaManagerImpl.h | 8 + .../MediaManager/src/MediaManagerMakePtr.cpp | 10 +- .../MediaManager/src/MediaManagerMakePtr.h | 4 +- test/middleware/CMakeLists.txt | 3 +- test/middleware/MediaManager/CMakeLists.txt | 81 ++++++ test/middleware/MediaManager/mainTest.cpp | 23 ++ .../MediaManager/src/MediaManager_Test.cpp | 74 +++++ .../MediaManager/tool/CMakeLists.txt | 56 ++++ .../tool/include/MediaManagerTestTool.h | 36 +++ .../tool/src/MediaManagerMakePtrTest.cpp | 57 ++++ .../tool/src/MediaManagerMakePtrTest.h | 32 ++ .../tool/src/MediaManagerMock.cpp | 30 ++ .../MediaManager/tool/src/MediaManagerMock.h | 37 +++ .../tool/src/MediaManagerTestTool.cpp | 91 ++++++ .../tool/src/MediaMonitorMock.cpp | 274 ++++++++++++++++++ .../MediaManager/tool/src/MediaMonitorMock.h | 93 ++++++ 22 files changed, 992 insertions(+), 40 deletions(-) create mode 100644 test/middleware/MediaManager/CMakeLists.txt create mode 100644 test/middleware/MediaManager/mainTest.cpp create mode 100644 test/middleware/MediaManager/src/MediaManager_Test.cpp create mode 100644 test/middleware/MediaManager/tool/CMakeLists.txt create mode 100644 test/middleware/MediaManager/tool/include/MediaManagerTestTool.h create mode 100644 test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.cpp create mode 100644 test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.h create mode 100644 test/middleware/MediaManager/tool/src/MediaManagerMock.cpp create mode 100644 test/middleware/MediaManager/tool/src/MediaManagerMock.h create mode 100644 test/middleware/MediaManager/tool/src/MediaManagerTestTool.cpp create mode 100644 test/middleware/MediaManager/tool/src/MediaMonitorMock.cpp create mode 100644 test/middleware/MediaManager/tool/src/MediaMonitorMock.h diff --git a/hal/abstract/IHalCpp.cpp b/hal/abstract/IHalCpp.cpp index 20aeb951..3415752b 100644 --- a/hal/abstract/IHalCpp.cpp +++ b/hal/abstract/IHalCpp.cpp @@ -15,6 +15,11 @@ #include "IHalCpp.h" #include "ILog.h" #include +camera_report_event::camera_report_event(const std::string &fileName, const std::string &filePath, + const CameraEventType &type) + : mFileName(fileName), mFilePath(filePath), mType(type) +{ +} void VKeyHalMonitor::KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) { @@ -32,6 +37,9 @@ StatusCode VWifiHal::OpenApMode(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event) +{ +} std::shared_ptr &IHalCpp::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -66,6 +74,7 @@ StatusCode IHalCpp::GetWifiHal(std::shared_ptr &wifi) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } -StatusCode IHalCpp::GetCameraHal(std::shared_ptr &camera) +StatusCode IHalCpp::GetCameraHal(std::map> &allCameras) { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index 72411b43..8a90a761 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef IHALCPP_H -#define IHALCPP_H +#ifndef I_HAL_CPP_H +#define I_HAL_CPP_H #include "StatusCode.h" #include #include @@ -24,6 +24,25 @@ using VirtualKeyEvent = unsigned char; constexpr int INVALID_PERIOD = -1; constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100; constexpr int IMEI_LEN = 15; +enum class CameraType +{ + MAIN_CAMERA = 0, + END +}; +enum class CameraEventType +{ + PICTIRUE = 0, + VIDEO, + PICTIRUE_AND_VIDEO, + END +}; +typedef struct camera_report_event +{ + camera_report_event(const std::string &fileName, const std::string &filePath, const CameraEventType &type); + const std::string mFileName; + const std::string mFilePath; + const CameraEventType mType; +} CameraReportEvent; void CreateHalCppModule(void); void DestroyHalCppModule(void); class VKeyHalMonitor @@ -60,6 +79,7 @@ class VCameraHalMonitor public: VCameraHalMonitor() = default; virtual ~VCameraHalMonitor() = default; + virtual void ReportEvent(const CameraReportEvent &event); }; class VCameraHal { @@ -78,6 +98,6 @@ public: virtual StatusCode GetAllLeds(std::map> &allLeds); virtual StatusCode GetAllKeys(std::map> &allKeys); virtual StatusCode GetWifiHal(std::shared_ptr &wifi); - virtual StatusCode GetCameraHal(std::shared_ptr &camera); + virtual StatusCode GetCameraHal(std::map> &allCameras); }; #endif diff --git a/middleware/MediaManager/CMakeLists.txt b/middleware/MediaManager/CMakeLists.txt index a4565b22..472b9c20 100644 --- a/middleware/MediaManager/CMakeLists.txt +++ b/middleware/MediaManager/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories( ${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/McuProtocol/include ${UTILS_SOURCE_PATH}/UartDevice/include + ${HAL_SOURCE_PATH}/include ) #do not rely on any other library #link_directories( diff --git a/middleware/MediaManager/include/IMediaManager.h b/middleware/MediaManager/include/IMediaManager.h index 98b6ecaa..f0a143b0 100644 --- a/middleware/MediaManager/include/IMediaManager.h +++ b/middleware/MediaManager/include/IMediaManager.h @@ -17,15 +17,15 @@ #include "StatusCode.h" #include #include -bool CreateMediaManager(void); -bool DestroyMediaManager(void); -enum class SensorNum +bool CreateMediaManagerModule(void); +bool DestroyMediaManagerModule(void); +enum class MediaChannel { - SENSOR_1 = 1, - SENSOR_2, + MEDIA_1 = 1, + MEDIA_2, END }; -enum class SensorTaskType +enum class MediaTaskType { TAKE_PICTURE = 0, TAKE_VIDEO, @@ -33,32 +33,34 @@ enum class SensorTaskType MONITOR, END }; -class SensorTaskResponse +class MediaTaskResponse { public: - SensorTaskResponse() - { - } - ~SensorTaskResponse() - { - } + MediaTaskResponse() = default; + ~MediaTaskResponse() = default; }; -class VSensorTask +class VMediaTask { public: - VSensorTask() = default; - virtual ~VSensorTask() = default; - virtual const SensorTaskType GetTaskType(void); - virtual void Response(const std::vector &response); + VMediaTask() = default; + virtual ~VMediaTask() = default; + virtual const MediaTaskType GetTaskType(void); + virtual void Response(const std::vector &response); virtual bool IsTaskFinished(void); virtual const signed int GetIsNight(void); virtual const unsigned int GetIsMultShot(void); }; -class VSensorHandle +class VMediaMonitor { public: - VSensorHandle() = default; - virtual ~VSensorHandle() = default; + VMediaMonitor() = default; + virtual ~VMediaMonitor() = default; +}; +class VMediaHandle +{ +public: + VMediaHandle() = default; + virtual ~VMediaHandle() = default; }; class IMediaManager { @@ -66,5 +68,8 @@ public: IMediaManager() = default; virtual ~IMediaManager() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual const StatusCode Init(void); + virtual const StatusCode UnInit(void); + virtual StatusCode SetMeidaMonitor(std::shared_ptr &monitor); }; #endif \ No newline at end of file diff --git a/middleware/MediaManager/src/IMediaManager.cpp b/middleware/MediaManager/src/IMediaManager.cpp index d7576e1b..85d7a680 100644 --- a/middleware/MediaManager/src/IMediaManager.cpp +++ b/middleware/MediaManager/src/IMediaManager.cpp @@ -14,22 +14,22 @@ */ #include "IMediaManager.h" #include "ILog.h" -const SensorTaskType VSensorTask::GetTaskType(void) +const MediaTaskType VMediaTask::GetTaskType(void) { - return SensorTaskType::END; + return MediaTaskType::END; } -void VSensorTask::Response(const std::vector &response) +void VMediaTask::Response(const std::vector &response) { } -bool VSensorTask::IsTaskFinished(void) +bool VMediaTask::IsTaskFinished(void) { return false; } -const signed int VSensorTask::GetIsNight(void) +const signed int VMediaTask::GetIsNight(void) { return 0; } -const unsigned int VSensorTask::GetIsMultShot(void) +const unsigned int VMediaTask::GetIsMultShot(void) { return false; } @@ -46,4 +46,16 @@ std::shared_ptr &IMediaManager::GetInstance(std::shared_ptr &monitor) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerImpl.cpp b/middleware/MediaManager/src/MediaManagerImpl.cpp index 1152ba7c..4fa6d9e7 100644 --- a/middleware/MediaManager/src/MediaManagerImpl.cpp +++ b/middleware/MediaManager/src/MediaManagerImpl.cpp @@ -12,4 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "MediaManagerImpl.h" \ No newline at end of file +#include "MediaManagerImpl.h" +const StatusCode MediaManagerImpl::Init(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +const StatusCode MediaManagerImpl::UnInit(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode MediaManagerImpl::SetMeidaMonitor(std::shared_ptr &monitor) +{ + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerImpl.h b/middleware/MediaManager/src/MediaManagerImpl.h index d23495e4..d37cc503 100644 --- a/middleware/MediaManager/src/MediaManagerImpl.h +++ b/middleware/MediaManager/src/MediaManagerImpl.h @@ -14,11 +14,19 @@ */ #ifndef MEDIA_MANAGER_IMPL_H #define MEDIA_MANAGER_IMPL_H +#include "IHalCpp.h" #include "IMediaManager.h" +#include class MediaManagerImpl : public IMediaManager { public: MediaManagerImpl() = default; virtual ~MediaManagerImpl() = default; + const StatusCode Init(void) override; + const StatusCode UnInit(void) override; + StatusCode SetMeidaMonitor(std::shared_ptr &monitor) override; + +private: + std::map> mAllCameras; }; #endif \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerMakePtr.cpp b/middleware/MediaManager/src/MediaManagerMakePtr.cpp index 9c313200..aa1d19b2 100644 --- a/middleware/MediaManager/src/MediaManagerMakePtr.cpp +++ b/middleware/MediaManager/src/MediaManagerMakePtr.cpp @@ -15,18 +15,18 @@ #include "MediaManagerMakePtr.h" #include "ILog.h" #include "MediaManagerImpl.h" -bool CreateMediaManager(void) +bool CreateMediaManagerModule(void) { auto instance = std::make_shared(); - StatusCode code = MediaManagerMakePtr::GetInstance()->CreateMediaManager(instance); + StatusCode code = MediaManagerMakePtr::GetInstance()->CreateMediaManagerModule(instance); if (IsCodeOK(code)) { - LogInfo("CreateMediaManager is ok.\n"); + LogInfo("CreateMediaManagerModule is ok.\n"); IMediaManager::GetInstance(&instance); return true; } return false; } -bool DestroyMediaManager(void) +bool DestroyMediaManagerModule(void) { auto instance = std::make_shared(); IMediaManager::GetInstance(&instance); @@ -46,7 +46,7 @@ std::shared_ptr &MediaManagerMakePtr::GetInstance(std::shar } return instance; } -const StatusCode MediaManagerMakePtr::CreateMediaManager(std::shared_ptr &impl) +const StatusCode MediaManagerMakePtr::CreateMediaManagerModule(std::shared_ptr &impl) { auto tmp = std::make_shared(); impl = tmp; diff --git a/middleware/MediaManager/src/MediaManagerMakePtr.h b/middleware/MediaManager/src/MediaManagerMakePtr.h index 6896c914..4adc0175 100644 --- a/middleware/MediaManager/src/MediaManagerMakePtr.h +++ b/middleware/MediaManager/src/MediaManagerMakePtr.h @@ -23,6 +23,6 @@ public: MediaManagerMakePtr() = default; virtual ~MediaManagerMakePtr() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); - virtual const StatusCode CreateMediaManager(std::shared_ptr &impl); + virtual const StatusCode CreateMediaManagerModule(std::shared_ptr &impl); }; -#endif // !IPC_CONFIG_MAKE_PTR_H \ No newline at end of file +#endif // !MEDIA_MANAGER_MAKE_PTR_H \ No newline at end of file diff --git a/test/middleware/CMakeLists.txt b/test/middleware/CMakeLists.txt index 5d98a8d2..e9ab9d4b 100644 --- a/test/middleware/CMakeLists.txt +++ b/test/middleware/CMakeLists.txt @@ -4,4 +4,5 @@ add_subdirectory(IpcConfig) add_subdirectory(McuManager) add_subdirectory(McuAskBase) add_subdirectory(DeviceManager) -add_subdirectory(AppManager) \ No newline at end of file +add_subdirectory(AppManager) +add_subdirectory(MediaManager) \ No newline at end of file diff --git a/test/middleware/MediaManager/CMakeLists.txt b/test/middleware/MediaManager/CMakeLists.txt new file mode 100644 index 00000000..9330ef9d --- /dev/null +++ b/test/middleware/MediaManager/CMakeLists.txt @@ -0,0 +1,81 @@ +# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${MIDDLEWARE_SOURCE_PATH}/AppManager/build/app_manager.cmake) +set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) + +include_directories( + ./src + ./include + ./tool/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/StatusCode/include + # ${UTILS_SOURCE_PATH}/KeyControl/include + # ${UTILS_SOURCE_PATH}/LedControl/include + # ${UTILS_SOURCE_PATH}/WebServer/include + # ${HAL_SOURCE_PATH}/include + ${MIDDLEWARE_SOURCE_PATH}/MediaManager/include + ${TEST_SOURCE_PATH} + # ${TEST_SOURCE_PATH}/hal/tool/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include +) + +link_directories( + ${LIBS_OUTPUT_PATH} + ${EXTERNAL_LIBS_OUTPUT_PATH} +) + +aux_source_directory(. SRC_FILES_MAIN) +aux_source_directory(./src SRC_FILES) +if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) + aux_source_directory(./src_mock SRC_FILES) +endif() + +set(TARGET_NAME MediaManagerTest) +add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} MediaManager MediaManagerTestTool gtest gmock pthread) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() + +if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + MediaManagerTest_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + # --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]' + --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]' + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/AppManager +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make MediaManagerTest_code_check + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) + +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + MediaManagerTest_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${SRC_FILES_MAIN} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/AppManager +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make MediaManagerTest_code_check + COMMAND make MediaManagerTest_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) + +add_subdirectory(tool) \ No newline at end of file diff --git a/test/middleware/MediaManager/mainTest.cpp b/test/middleware/MediaManager/mainTest.cpp new file mode 100644 index 00000000..475ceee4 --- /dev/null +++ b/test/middleware/MediaManager/mainTest.cpp @@ -0,0 +1,23 @@ +/* + * 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 +#include +#include +#include +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/middleware/MediaManager/src/MediaManager_Test.cpp b/test/middleware/MediaManager/src/MediaManager_Test.cpp new file mode 100644 index 00000000..df313ad0 --- /dev/null +++ b/test/middleware/MediaManager/src/MediaManager_Test.cpp @@ -0,0 +1,74 @@ +/* + * 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 "GtestUsing.h" +#include "ILog.h" +#include "IMediaManager.h" +#include +#include +#include +namespace MediaManagerTest +{ +class MediaManagerTest : public testing::Test +{ +public: + MediaManagerTest() + { + } + virtual ~MediaManagerTest() + { + } + static void SetUpTestCase() + { + CreateLogModule(); + ILogInit(LOG_INSTANCE_TYPE_END); + } + static void TearDownTestCase() + { + ILogUnInit(); + } + virtual void SetUp() + { + // HalTestTool::Init(); + // AppManagerTestTool::Init(); + // CreateHalCppModule(); + CreateMediaManagerModule(); + } + virtual void TearDown() + { + // AppManagerTestTool::UnInit(); + // HalTestTool::UnInit(); + DestroyMediaManagerModule(); + // DestroyHalCppModule(); + } + +protected: + // const AppParam mAppParam; +}; +// ../output_files/test/bin/MediaManagerTest --gtest_filter=MediaManagerTest.INTEGRATION_MediaManager_EXAMPLE_Demo0 +TEST_F(MediaManagerTest, INTEGRATION_MediaManager_EXAMPLE_Demo0) +{ + // std::shared_ptr monitor = AppManagerTestTool::MakeMonitorMock(); + // IAppManager::GetInstance()->Init(mAppParam); + // IAppManager::GetInstance()->SetAppMonitor(monitor); + // std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // MockAppClientConnect(); + // std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // MockSetRecordingStatus(RecordingStatus::RECORDING_START); + // std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + // IAppManager::GetInstance()->UnInit(); + IMediaManager::GetInstance()->Init(); + IMediaManager::GetInstance()->UnInit(); +} +} // namespace MediaManagerTest \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/CMakeLists.txt b/test/middleware/MediaManager/tool/CMakeLists.txt new file mode 100644 index 00000000..c6b08d6a --- /dev/null +++ b/test/middleware/MediaManager/tool/CMakeLists.txt @@ -0,0 +1,56 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ./src + ./include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + # ${UTILS_SOURCE_PATH}/Servers/include + # ${UTILS_SOURCE_PATH}/TcpModule/include + ${MIDDLEWARE_SOURCE_PATH}/MediaManager/src + ${HAL_SOURCE_PATH}/include + ${TEST_SOURCE_PATH} + ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +aux_source_directory(./src TEST_TOOL_SRC_FILES) +set(TEST_TOOL_TARGET MediaManagerTestTool) +add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) +target_link_libraries(${TEST_TOOL_TARGET} MediaManager Servers Log) + +if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + MediaManagerTestTool_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${TEST_TOOL_SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/MediaManager/tool +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + MediaManagerTestTool_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${TEST_TOOL_SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/MediaManager/tool +) +add_custom_command( + TARGET ${TEST_TOOL_TARGET} + PRE_BUILD + COMMAND make MediaManagerTestTool_code_check + COMMAND make MediaManagerTestTool_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TEST_TOOL_TARGET}) \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/include/MediaManagerTestTool.h b/test/middleware/MediaManager/tool/include/MediaManagerTestTool.h new file mode 100644 index 00000000..2639f268 --- /dev/null +++ b/test/middleware/MediaManager/tool/include/MediaManagerTestTool.h @@ -0,0 +1,36 @@ +/* + * 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. + */ +#ifndef MEDIA_MANAGER_TEST_TOOL_H +#define MEDIA_MANAGER_TEST_TOOL_H +#include "GtestUsing.h" +#include "IMediaManager.h" +#include +class MediaManagerTestTool +{ +public: + MediaManagerTestTool() = default; + virtual ~MediaManagerTestTool() = default; + void Init(void); + void UnInit(void); + +private: + void MediaManagerMockInit(std::shared_ptr &vMock); + void MediaMonitorInit(std::shared_ptr &vMock); + +private: + std::shared_ptr mMediaManagerMock; + std::shared_ptr mMediaMonitorMock; +}; +#endif \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.cpp b/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.cpp new file mode 100644 index 00000000..8e6a2aed --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.cpp @@ -0,0 +1,57 @@ +/* + * 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 "MediaManagerMakePtrTest.h" +#include "ILog.h" +void OverrideMediaManagerMakePtrObject(std::shared_ptr &appManagerMock) +{ + std::shared_ptr impl = std::make_shared(); + std::shared_ptr test = std::dynamic_pointer_cast(impl); + if (test) { + test->mMediaManagerMock = appManagerMock; + } + MediaManagerMakePtr::GetInstance(&impl); +} +void CancelOverrideMediaManagerMakePtrObject(void) +{ + std::shared_ptr tmp = MediaManagerMakePtr::GetInstance(); + std::shared_ptr test = std::dynamic_pointer_cast(tmp); + if (test) { + test->mMediaManagerMock.reset(); + } + tmp.reset(); + test.reset(); + std::shared_ptr impl = std::make_shared(); + MediaManagerMakePtr::GetInstance(&impl); +} +MediaManagerMakePtrTest::MediaManagerMakePtrTest() +{ + // +} +MediaManagerMakePtrTest::~MediaManagerMakePtrTest() +{ + // + mMediaManagerMock.reset(); +} +const StatusCode MediaManagerMakePtrTest::CreateMediaManagerModule(std::shared_ptr &impl) +{ + if (mMediaManagerMock) { + LogInfo("CreateMediaManagerModule mMediaManagerMock\n"); + impl = mMediaManagerMock; + } + else { + LogWarning("CreateMcuManager failed:mMediaManagerMock is nullptr.\n"); + } + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.h b/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.h new file mode 100644 index 00000000..296d7822 --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaManagerMakePtrTest.h @@ -0,0 +1,32 @@ +/* + * 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. + */ +#ifndef MEDIA_MANAGER_MAKE_PTR_TEST_H +#define MEDIA_MANAGER_MAKE_PTR_TEST_H +#include "MediaManagerMock.h" +#include "MediaManagerTestTool.h" +#include "MediaManagerMakePtr.h" +void OverrideMediaManagerMakePtrObject(std::shared_ptr &appManagerMock); +void CancelOverrideMediaManagerMakePtrObject(void); +class MediaManagerMakePtrTest : public MediaManagerMakePtr +{ +public: + MediaManagerMakePtrTest(); + virtual ~MediaManagerMakePtrTest(); + const StatusCode CreateMediaManagerModule(std::shared_ptr &impl) override; + +public: + std::shared_ptr mMediaManagerMock; +}; +#endif \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaManagerMock.cpp b/test/middleware/MediaManager/tool/src/MediaManagerMock.cpp new file mode 100644 index 00000000..bf0cd5af --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaManagerMock.cpp @@ -0,0 +1,30 @@ +/* + * 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 "MediaManagerMock.h" +#include "ILog.h" +StatusCode MediaManagerTest::SetMeidaMonitor(std::shared_ptr &monitor) +{ + LogInfo("MediaManagerTest::SetAppMonitor\n"); + StatusCode code = SetMediaMonitorTrace(monitor); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return MediaManagerImpl::SetMeidaMonitor(monitor); + } + return code; +} +const StatusCode MediaManagerTest::SetMediaMonitorTrace(std::shared_ptr &monitor) +{ + LogInfo("SetMediaMonitorTrace::SetAppMonitorTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaManagerMock.h b/test/middleware/MediaManager/tool/src/MediaManagerMock.h new file mode 100644 index 00000000..8044a772 --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaManagerMock.h @@ -0,0 +1,37 @@ +/* + * 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. + */ +#ifndef MEDIA_MANAGER_MOCK_H +#define MEDIA_MANAGER_MOCK_H +#include "MediaManagerImpl.h" +#include "MediaManagerTestTool.h" +class MediaManagerTest : public MediaManagerImpl +{ +public: + MediaManagerTest() = default; + virtual ~MediaManagerTest() = default; + // const StatusCode SetMeidaMonitor(std::shared_ptr &monitor) override; + StatusCode SetMeidaMonitor(std::shared_ptr &monitor) override; + +protected: + virtual const StatusCode SetMediaMonitorTrace(std::shared_ptr &monitor); +}; +class MediaManagerMock : public MediaManagerTest +{ +public: + MediaManagerMock() = default; + virtual ~MediaManagerMock() = default; + MOCK_METHOD1(SetMediaMonitorTrace, const StatusCode(std::shared_ptr &)); +}; +#endif \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaManagerTestTool.cpp b/test/middleware/MediaManager/tool/src/MediaManagerTestTool.cpp new file mode 100644 index 00000000..31468d2b --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaManagerTestTool.cpp @@ -0,0 +1,91 @@ +/* + * 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)))); + } +} \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaMonitorMock.cpp b/test/middleware/MediaManager/tool/src/MediaMonitorMock.cpp new file mode 100644 index 00000000..a3a4ab7e --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaMonitorMock.cpp @@ -0,0 +1,274 @@ +/* + * 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 "MediaMonitorMock.h" +#include "ILog.h" +// StatusCode MediaMonitorTest::GetProductInfo(AppGetProductInfo ¶m) +// { +// LogInfo("MediaMonitorTest::GetProductInfo\n"); +// StatusCode code = GetProductInfoTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetProductInfo(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetProductInfoTrace(AppGetProductInfo ¶m) +// { +// LogInfo("MediaMonitorTrace::GetProductInfoTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetDeviceAttr(AppGetDeviceAttr ¶m) +// { +// LogInfo("MediaMonitorTest::GetDeviceAttr\n"); +// StatusCode code = GetDeviceAttrTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetDeviceAttr(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetDeviceAttrTrace(AppGetDeviceAttr ¶m) +// { +// LogInfo("MediaMonitorTrace::GetDeviceAttrTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetMediaInfo(AppGetMeidaInfo ¶m) +// { +// LogInfo("MediaMonitorTest::GetMediaInfo\n"); +// StatusCode code = GetMediaInfoTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetMediaInfo(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetMediaInfoTrace(AppGetMeidaInfo ¶m) +// { +// LogInfo("MediaMonitorTrace::GetMediaInfoTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetSdCardInfo(AppGetSdCardInfo ¶m) +// { +// LogInfo("MediaMonitorTest::GetSdCardInfo\n"); +// StatusCode code = GetSdCardInfoTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetSdCardInfo(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetSdCardInfoTrace(AppGetSdCardInfo ¶m) +// { +// LogInfo("MediaMonitorTrace::GetSdCardInfoTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetBatteryInfo(AppGetBatteryInfo ¶m) +// { +// LogInfo("MediaMonitorTest::GetBatteryInfo\n"); +// StatusCode code = GetBatteryInfoTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetBatteryInfo(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetBatteryInfoTrace(AppGetBatteryInfo ¶m) +// { +// LogInfo("MediaMonitorTrace::GetBatteryInfoTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetParamValue(AppParamValue ¶m) +// { +// LogInfo("MediaMonitorTest::GetParamValue\n"); +// StatusCode code = GetParamValueTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetParamValue(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetParamValueTrace(AppParamValue ¶m) +// { +// LogInfo("MediaMonitorTrace::GetParamValueTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetCapability(AppGetCapability ¶m) +// { +// LogInfo("MediaMonitorTest::GetCapability\n"); +// StatusCode code = GetCapabilityTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetCapability(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetCapabilityTrace(AppGetCapability ¶m) +// { +// LogInfo("MediaMonitorTrace::GetCapabilityTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetLockVideoStatus(LockVideoStatus ¶m) +// { +// LogInfo("MediaMonitorTest::GetLockVideoStatus\n"); +// StatusCode code = GetLockVideoStatusTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetLockVideoStatus(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetLockVideoStatusTrace(LockVideoStatus ¶m) +// { +// LogInfo("MediaMonitorTrace::GetLockVideoStatusTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetStorageInfo(std::vector ¶m) +// { +// LogInfo("MediaMonitorTest::GetStorageInfo\n"); +// StatusCode code = GetStorageInfoTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetStorageInfo(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetStorageInfoTrace(std::vector ¶m) +// { +// LogInfo("MediaMonitorTrace::GetStorageInfoTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector ¶m) +// { +// LogInfo("MediaMonitorTest::GetStorageFileList\n"); +// StatusCode code = GetStorageFileListTrace(fileInfo, param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetStorageFileList(fileInfo, param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetStorageFileListTrace(const AppGetFileInfo &fileInfo, std::vector ¶m) +// { +// LogInfo("MediaMonitorTrace::GetStorageFileListTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::SetDateTime(const AppSetDateTime ¶m) +// { +// LogInfo("MediaMonitorTest::SetDateTime\n"); +// LogInfo("mYear = %u\n", param.mYear); +// LogInfo("mMonth = %02u\n", param.mMonth); +// LogInfo("mDay = %02u\n", param.mDay); +// LogInfo("mHour = %02u\n", param.mHour); +// LogInfo("mMinute = %02u\n", param.mMinute); +// LogInfo("mSecond = %02u\n", param.mSecond); +// StatusCode code = SetDateTimeTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::SetDateTime(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::SetDateTimeTrace(const AppSetDateTime ¶m) +// { +// LogInfo("MediaMonitorTrace::SetDateTimeTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::SetTimeZone(const unsigned int &zone) +// { +// LogInfo("MediaMonitorTest::SetTimeZone = %u\n", zone); +// StatusCode code = SetTimeZoneTrace(zone); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::SetTimeZone(zone); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::SetTimeZoneTrace(const unsigned int &zone) +// { +// LogInfo("MediaMonitorTrace::SetTimeZoneTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::SetParamValue(const AppSetParamValue ¶m) +// { +// LogInfo("MediaMonitorTest::SetParamValue\n"); +// StatusCode code = SetParamValueTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::SetParamValue(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::SetParamValueTrace(const AppSetParamValue ¶m) +// { +// LogInfo("MediaMonitorTrace::SetParamValueTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::EnterRecorder(void) +// { +// LogInfo("MediaMonitorTest::EnterRecorder\n"); +// StatusCode code = EnterRecorderTrace(); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::EnterRecorder(); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::EnterRecorderTrace(void) +// { +// LogInfo("MediaMonitorTrace::EnterRecorderTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::AppPlayback(const PlayBackEvent &event) +// { +// LogInfo("MediaMonitorTest::AppPlayback\n"); +// StatusCode code = AppPlaybackTrace(event); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::AppPlayback(event); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::AppPlaybackTrace(const PlayBackEvent &event) +// { +// LogInfo("MediaMonitorTrace::AppPlaybackTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::UploadFile(AppUploadFile ¶m) +// { +// LogInfo("MediaMonitorTest::UploadFile\n"); +// StatusCode code = UploadFileTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::UploadFile(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::UploadFileTrace(AppUploadFile ¶m) +// { +// LogInfo("MediaMonitorTrace::UploadFileTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::GetThumbnail(AppGetThumbnail ¶m) +// { +// LogInfo("MediaMonitorTest::GetThumbnail\n"); +// StatusCode code = GetThumbnailTrace(param); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::GetThumbnail(param); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::GetThumbnailTrace(AppGetThumbnail ¶m) +// { +// LogInfo("MediaMonitorTrace::UploadFileTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode MediaMonitorTest::AppClientConnected(std::shared_ptr &client) +// { +// LogInfo("MediaMonitorTest::AppClientConnected\n"); +// StatusCode code = AppClientConnectedTrace(client); +// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { +// return VMediaMonitor::AppClientConnected(client); +// } +// return code; +// } +// StatusCode MediaMonitorTrace::AppClientConnectedTrace(std::shared_ptr &client) +// { +// LogInfo("MediaMonitorTrace::AppClientConnected\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaMonitorMock.h b/test/middleware/MediaManager/tool/src/MediaMonitorMock.h new file mode 100644 index 00000000..cd4b6386 --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaMonitorMock.h @@ -0,0 +1,93 @@ +/* + * 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. + */ +#ifndef APP_MONITOR_MOCK_H +#define APP_MONITOR_MOCK_H +#include "GtestUsing.h" +#include "IMediaManager.h" +class MediaMonitorTrace +{ +public: + MediaMonitorTrace() = default; + virtual ~MediaMonitorTrace() = default; + +protected: + // virtual StatusCode GetProductInfoTrace(AppGetProductInfo ¶m); + // virtual StatusCode GetDeviceAttrTrace(AppGetDeviceAttr ¶m); + // virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo ¶m); + // virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m); + // virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m); + // virtual StatusCode GetParamValueTrace(AppParamValue ¶m); + // virtual StatusCode GetCapabilityTrace(AppGetCapability ¶m); + // virtual StatusCode GetLockVideoStatusTrace(LockVideoStatus ¶m); + // virtual StatusCode GetStorageInfoTrace(std::vector ¶m); + // virtual StatusCode GetStorageFileListTrace(const AppGetFileInfo &fileInfo, std::vector ¶m); + // virtual StatusCode SetDateTimeTrace(const AppSetDateTime ¶m); + // virtual StatusCode SetTimeZoneTrace(const unsigned int &zone); + // virtual StatusCode SetParamValueTrace(const AppSetParamValue ¶m); + // virtual StatusCode EnterRecorderTrace(void); + // virtual StatusCode AppPlaybackTrace(const PlayBackEvent &event); + // virtual StatusCode UploadFileTrace(AppUploadFile ¶m); + // virtual StatusCode GetThumbnailTrace(AppGetThumbnail ¶m); + // virtual StatusCode AppClientConnectedTrace(std::shared_ptr &client); +}; +class MediaMonitorTest : public VMediaMonitor, virtual public MediaMonitorTrace +{ +public: + MediaMonitorTest() = default; + virtual ~MediaMonitorTest() = default; + // StatusCode GetProductInfo(AppGetProductInfo ¶m) override; + // StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override; + // StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override; + // StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override; + // StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override; + // StatusCode GetParamValue(AppParamValue ¶m) override; + // StatusCode GetCapability(AppGetCapability ¶m) override; + // StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override; + // StatusCode GetStorageInfo(std::vector ¶m) override; + // StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector ¶m) override; + // StatusCode SetDateTime(const AppSetDateTime ¶m) override; + // StatusCode SetTimeZone(const unsigned int &zone) override; + // StatusCode SetParamValue(const AppSetParamValue ¶m) override; + // StatusCode EnterRecorder(void) override; + // StatusCode AppPlayback(const PlayBackEvent &event) override; + // StatusCode UploadFile(AppUploadFile ¶m) override; + // StatusCode GetThumbnail(AppGetThumbnail ¶m) override; + // StatusCode AppClientConnected(std::shared_ptr &client) override; +}; +class MediaMonitorMock : virtual public MediaMonitorTrace +{ +public: + MediaMonitorMock() = default; + virtual ~MediaMonitorMock() = default; + // MOCK_METHOD1(GetProductInfoTrace, StatusCode(AppGetProductInfo &)); + // MOCK_METHOD1(GetDeviceAttrTrace, StatusCode(AppGetDeviceAttr &)); + // MOCK_METHOD1(GetMediaInfoTrace, StatusCode(AppGetMeidaInfo &)); + // MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &)); + // MOCK_METHOD1(GetBatteryInfoTrace, StatusCode(AppGetBatteryInfo &)); + // MOCK_METHOD1(GetParamValueTrace, StatusCode(AppParamValue &)); + // MOCK_METHOD1(GetCapabilityTrace, StatusCode(AppGetCapability &)); + // MOCK_METHOD1(GetLockVideoStatusTrace, StatusCode(LockVideoStatus &)); + // MOCK_METHOD1(GetStorageInfoTrace, StatusCode(std::vector &)); + // MOCK_METHOD2(GetStorageFileListTrace, StatusCode(const AppGetFileInfo &, std::vector &)); + // MOCK_METHOD1(SetDateTimeTrace, StatusCode(const AppSetDateTime &)); + // MOCK_METHOD1(SetTimeZoneTrace, StatusCode(const unsigned int &)); + // MOCK_METHOD1(SetParamValueTrace, StatusCode(const AppSetParamValue &)); + // MOCK_METHOD0(EnterRecorderTrace, StatusCode(void)); + // MOCK_METHOD1(AppPlaybackTrace, StatusCode(const PlayBackEvent &)); + // MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &)); + // MOCK_METHOD1(GetThumbnailTrace, StatusCode(AppGetThumbnail &)); + // MOCK_METHOD1(AppClientConnectedTrace, StatusCode(std::shared_ptr &)); +}; +#endif \ No newline at end of file