From d3dca44f9141f3962ab95ad28dc1a8c679fa9794 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Tue, 5 Mar 2024 22:40:05 -0800 Subject: [PATCH] Backup:MissionManager module. --- application/HunttingCamera/src/MainThread.cpp | 6 ++ application/HunttingCamera/src/MainThread.h | 2 +- application/MissionManager/src/AppMonitor.cpp | 2 + application/MissionManager/src/MissionState.h | 2 +- .../MissionManager/src/TestMissionState.cpp | 5 +- build/cmake/toolchain/linux.toolchain.cmake | 2 +- middleware/AppManager/src/AppManager.cpp | 2 +- .../src/Protocol/SixFrame/SixFrameHandle.cpp | 14 ++- .../src/Protocol/SixFrame/SixFrameHandle.h | 1 + test/application/CMakeLists.txt | 3 +- .../src_mock/HunttingCamera_Mock_Test.cpp | 2 +- .../application/MissionManager/CMakeLists.txt | 2 + .../MissionManager/tool/CMakeLists.txt | 58 +++++++++++ .../tool/include/MissionManagerTestTool.h | 39 ++++++++ .../tool/src/MissionManagerTestTool.cpp | 30 ++++++ .../tool/src/TestMissionStateMock.cpp | 95 +++++++++++++++++++ .../tool/src/TestMissionStateMock.h | 45 +++++++++ .../tool/src/AppManagerTestTool.cpp | 74 +++++++-------- 18 files changed, 337 insertions(+), 47 deletions(-) create mode 100644 test/application/MissionManager/CMakeLists.txt create mode 100644 test/application/MissionManager/tool/CMakeLists.txt create mode 100644 test/application/MissionManager/tool/include/MissionManagerTestTool.h create mode 100644 test/application/MissionManager/tool/src/MissionManagerTestTool.cpp create mode 100644 test/application/MissionManager/tool/src/TestMissionStateMock.cpp create mode 100644 test/application/MissionManager/tool/src/TestMissionStateMock.h diff --git a/application/HunttingCamera/src/MainThread.cpp b/application/HunttingCamera/src/MainThread.cpp index dcbf8a4e..611479c1 100644 --- a/application/HunttingCamera/src/MainThread.cpp +++ b/application/HunttingCamera/src/MainThread.cpp @@ -79,4 +79,10 @@ void MainThread::Runing(void) while (mMainThreadRuning) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } +} +extern bool CreateProtocolHandleImpl(void); +void MainThread::CustomizationInit(void) +{ + // + CreateProtocolHandleImpl(); } \ No newline at end of file diff --git a/application/HunttingCamera/src/MainThread.h b/application/HunttingCamera/src/MainThread.h index 4ced64cb..a0a6d9b0 100644 --- a/application/HunttingCamera/src/MainThread.h +++ b/application/HunttingCamera/src/MainThread.h @@ -26,7 +26,7 @@ public: virtual StatusCode UnInit(void); void Runing(void); void Exit(void) { mMainThreadRuning = false; } - virtual void CustomizationInit(void) {} + virtual void CustomizationInit(void); private: StatusCode CreateAllModules(void); diff --git a/application/MissionManager/src/AppMonitor.cpp b/application/MissionManager/src/AppMonitor.cpp index 481ddbf2..615a98bd 100644 --- a/application/MissionManager/src/AppMonitor.cpp +++ b/application/MissionManager/src/AppMonitor.cpp @@ -1,6 +1,8 @@ #include "AppMonitor.h" +#include "ILog.h" StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m) { + LogInfo("AppMonitor::GetProductInfo.\n"); param.mModel = "test"; param.mCompany = "test"; param.mSoc = "test"; diff --git a/application/MissionManager/src/MissionState.h b/application/MissionManager/src/MissionState.h index ab4e897a..883a5128 100644 --- a/application/MissionManager/src/MissionState.h +++ b/application/MissionManager/src/MissionState.h @@ -16,7 +16,7 @@ #define MISSION_STATE_H #include "DataProcessing.h" #include "IStateMachine.h" -class MissionState : public State, public DataProcessing +class MissionState : public State, public DataProcessing, public std::enable_shared_from_this { public: MissionState(const std::string &name); diff --git a/application/MissionManager/src/TestMissionState.cpp b/application/MissionManager/src/TestMissionState.cpp index af633610..ede0c2d7 100644 --- a/application/MissionManager/src/TestMissionState.cpp +++ b/application/MissionManager/src/TestMissionState.cpp @@ -20,8 +20,11 @@ void TestMissionState::GoInState() { MissionState::GoInState(); LogInfo(" ========== TestMissionState::GoInState.\n"); - AppParam mAppParam("192.168.1.29", APP_MANAGER_HTTP_SERVER_PORT); // TODO: + AppParam mAppParam(APP_MANAGER_HTTP_SERVER_IP, APP_MANAGER_HTTP_SERVER_PORT); // TODO: IAppManager::GetInstance()->Init(mAppParam); + std::shared_ptr monitor = + std::dynamic_pointer_cast(MissionState::shared_from_this()); + IAppManager::GetInstance()->SetAppMonitor(monitor); } void TestMissionState::GoOutState() { diff --git a/build/cmake/toolchain/linux.toolchain.cmake b/build/cmake/toolchain/linux.toolchain.cmake index 63eee977..597aef7b 100755 --- a/build/cmake/toolchain/linux.toolchain.cmake +++ b/build/cmake/toolchain/linux.toolchain.cmake @@ -49,7 +49,7 @@ set(LOG_SUPPORT "true") set(GOAHEAD_DOCUMENTS_PATH "web") set(GOAHEAD_UPLOAD_TMP_PATH "./goahead") set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}") -set(GOAHEAD_LIMIT_POST "33554432") # If not defined means using default setting. See goahead-linux-static-fancy.mk +set(GOAHEAD_LIMIT_POST "335544320") # If not defined means using default setting. See goahead-linux-static-fancy.mk # GOAHEAD_CONFIG_FILE_PATH should be set when cross compile # set(GOAHEAD_CONFIG_FILE_PATH "./") # ------------ build GoAhead end ------------ # diff --git a/middleware/AppManager/src/AppManager.cpp b/middleware/AppManager/src/AppManager.cpp index 1877b726..c4171e81 100644 --- a/middleware/AppManager/src/AppManager.cpp +++ b/middleware/AppManager/src/AppManager.cpp @@ -19,8 +19,8 @@ #include "WebServer.h" AppManager::AppManager() { - // // mHttpServerRuning = false; + mProtocolHandle = std::make_shared(); } const StatusCode AppManager::Init(const AppParam ¶m) { diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp index a590d5d1..f628974e 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp @@ -102,14 +102,24 @@ void SixFrameHandle::RequestGetProductInfo(const std::string &url, ResponseHandl { LogInfo("RequestGetProductInfo.\n"); char *resultStr = nullptr; - cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); - resultStr = cJSON_Print(result); AppGetProductInfo param; mAppMonitor->GetProductInfo(param); + cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); + ResponseGetProductInfo(result, param); + resultStr = cJSON_Print(result); responseHandle(resultStr, context); free(resultStr); cJSON_Delete(result); } +void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetProductInfo ¶m) +{ + cJSON *info = nullptr; + cJSON_AddItemToObject(result, CJSON_INFO_STRING, info = cJSON_CreateObject()); + cJSON_AddStringToObject(info, "model", param.mModel.c_str()); + cJSON_AddStringToObject(info, "company", param.mCompany.c_str()); + cJSON_AddStringToObject(info, "soc", param.mSoc.c_str()); + cJSON_AddStringToObject(info, "sp", param.mSp.c_str()); +} void SixFrameHandle::RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context) { LogInfo("RequestGetDeviceAttr.\n"); diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h index 3b779cbd..3fc9a5cd 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h @@ -59,6 +59,7 @@ private: void *context); void DoNothing(const std::string &url, ResponseHandle responseHandle, void *context); void RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context); + void ResponseGetProductInfo(cJSON *result, const AppGetProductInfo ¶m); void RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context); void ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m); void RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context); diff --git a/test/application/CMakeLists.txt b/test/application/CMakeLists.txt index cdf96549..dff2f938 100644 --- a/test/application/CMakeLists.txt +++ b/test/application/CMakeLists.txt @@ -1,2 +1,3 @@ -add_subdirectory(HunttingCamera) \ No newline at end of file +add_subdirectory(HunttingCamera) +add_subdirectory(MissionManager) \ No newline at end of file diff --git a/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp b/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp index e5803757..73f56d91 100644 --- a/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp +++ b/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp @@ -73,7 +73,7 @@ TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo) MainThread::GetInstance()->Init(); TestManager::ResetTimeOut(1000 * 3); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - MockGetMediaInfo(); + MockGetProductInfo(); MainThread::GetInstance()->Runing(); } } // namespace HunttingCameraTest \ No newline at end of file diff --git a/test/application/MissionManager/CMakeLists.txt b/test/application/MissionManager/CMakeLists.txt new file mode 100644 index 00000000..f4e8c70d --- /dev/null +++ b/test/application/MissionManager/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(tool) \ No newline at end of file diff --git a/test/application/MissionManager/tool/CMakeLists.txt b/test/application/MissionManager/tool/CMakeLists.txt new file mode 100644 index 00000000..d917c25a --- /dev/null +++ b/test/application/MissionManager/tool/CMakeLists.txt @@ -0,0 +1,58 @@ +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 + ${APPLICATION_SOURCE_PATH}/MissionManager/include + ${APPLICATION_SOURCE_PATH}/MissionManager/src + ${MIDDLEWARE_SOURCE_PATH}/AppManager/include + ${MIDDLEWARE_SOURCE_PATH}/StateMachine/include + ${TEST_SOURCE_PATH} + ${TEST_SOURCE_PATH}/middleware/AppManager/tool/include + ${TEST_SOURCE_PATH}/middleware/AppManager/tool/src + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/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 MissionManagerTestTool) +add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) +target_link_libraries(${TEST_TOOL_TARGET} MissionManager AppManagerTestTool Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + MissionManagerTestTool_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}/application/MissionManager/tool +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + MissionManagerTestTool_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${TEST_TOOL_SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/application/MissionManager/tool +) +add_custom_command( + TARGET ${TEST_TOOL_TARGET} + PRE_BUILD + COMMAND make MissionManagerTestTool_code_check + COMMAND make MissionManagerTestTool_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/application/MissionManager/tool/include/MissionManagerTestTool.h b/test/application/MissionManager/tool/include/MissionManagerTestTool.h new file mode 100644 index 00000000..0f65e86c --- /dev/null +++ b/test/application/MissionManager/tool/include/MissionManagerTestTool.h @@ -0,0 +1,39 @@ +/* + * 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 MISSION_MANAGER_TEST_TOOL_H +#define MISSION_MANAGER_TEST_TOOL_H +#include "GtestUsing.h" +#include "IMissionManager.h" +#include +class MissionManagerTestTool +{ +public: + MissionManagerTestTool() = default; + virtual ~MissionManagerTestTool() = default; + void Init(void); + void UnInit(void); + +private: + // void MissionManagerMockInit(std::shared_ptr &vMock); + + // private: + // std::shared_ptr mMissionManagerMock; + // std::shared_ptr mAppMonitorMock; + + // public: + // static std::shared_ptr MakeMonitorMock(void); + // void AppMonitorInit(std::shared_ptr &vMock); +}; +#endif \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp b/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp new file mode 100644 index 00000000..c0e989c0 --- /dev/null +++ b/test/application/MissionManager/tool/src/MissionManagerTestTool.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 "MissionManagerTestTool.h" +void MissionManagerTestTool::Init(void) +{ + // ServersMock::GetInstance()->Init(); + // mMissionManagerMock = std::make_shared(); + // MissionManagerMockInit(mMissionManagerMock); + // std::shared_ptr mock = std::dynamic_pointer_cast(mMissionManagerMock); + // OverrideMissionManagerMakePtrObject(mock); +} +void MissionManagerTestTool::UnInit(void) +{ + // ServersMock::GetInstance()->UnInit(); + // mMissionManagerMock.reset(); + // mAppMonitorMock.reset(); + // CancelOverrideMissionManagerMakePtrObject(); +} \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/TestMissionStateMock.cpp b/test/application/MissionManager/tool/src/TestMissionStateMock.cpp new file mode 100644 index 00000000..6045c95d --- /dev/null +++ b/test/application/MissionManager/tool/src/TestMissionStateMock.cpp @@ -0,0 +1,95 @@ +/* + * 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 "TestMissionStateMock.h" +#include "AppMonitorMock.h" +#include "ILog.h" +StatusCode TestMissionStateTest::GetProductInfo(AppGetProductInfo ¶m) +{ + LogInfo("TestMissionStateTest::GetProductInfo\n"); + StatusCode code = GetProductInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::GetProductInfo(param); + } + return code; +} +StatusCode TestMissionStateTest::GetDeviceAttr(AppGetDeviceAttr ¶m) +{ + LogInfo("TestMissionStateTest::GetDeviceAttr\n"); + StatusCode code = GetDeviceAttrTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::GetDeviceAttr(param); + } + return code; +} +StatusCode TestMissionStateTest::GetMediaInfo(AppGetMeidaInfo ¶m) +{ + LogInfo("TestMissionStateTest::GetMediaInfo\n"); + StatusCode code = GetMediaInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::GetMediaInfo(param); + } + return code; +} +StatusCode TestMissionStateTest::GetSdCardInfo(AppGetSdCardInfo ¶m) +{ + LogInfo("TestMissionStateTest::GetSdCardInfo\n"); + StatusCode code = GetSdCardInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::GetSdCardInfo(param); + } + return code; +} +StatusCode TestMissionStateTest::GetBatteryInfo(AppGetBatteryInfo ¶m) +{ + LogInfo("TestMissionStateTest::GetBatteryInfo\n"); + StatusCode code = GetBatteryInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::GetBatteryInfo(param); + } + return code; +} +StatusCode TestMissionStateTest::SetDateTime(AppSetDateTime ¶m) +{ + LogInfo("TestMissionStateTest::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 AppMonitor::SetDateTime(param); + } + return code; +} +StatusCode TestMissionStateTest::SetTimeZone(const unsigned int &zone) +{ + LogInfo("TestMissionStateTest::SetTimeZone = %u\n", zone); + StatusCode code = SetTimeZoneTrace(zone); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::SetTimeZone(zone); + } + return code; +} +StatusCode TestMissionStateTest::UploadFile(AppUploadFile ¶m) +{ + LogInfo("TestMissionStateTest::UploadFile\n"); + StatusCode code = UploadFileTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::UploadFile(param); + } + return code; +} \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/TestMissionStateMock.h b/test/application/MissionManager/tool/src/TestMissionStateMock.h new file mode 100644 index 00000000..2806095b --- /dev/null +++ b/test/application/MissionManager/tool/src/TestMissionStateMock.h @@ -0,0 +1,45 @@ +/* + * 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 TEST_MISSION_STATE_MOCK_H +#define TEST_MISSION_STATE_MOCK_H +#include "AppMonitorMock.h" +#include "MissionManagerTestTool.h" +#include "TestMissionState.h" +class TestMissionStateTest : public TestMissionState, virtual public AppMonitorTrace +{ +public: + TestMissionStateTest() = default; + virtual ~TestMissionStateTest() = 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 SetDateTime(AppSetDateTime ¶m) override; + StatusCode SetTimeZone(const unsigned int &zone) override; + StatusCode UploadFile(AppUploadFile ¶m) override; + // const StatusCode SetAppMonitor(std::shared_ptr &monitor) override; + +protected: + // virtual const StatusCode SetAppMonitorTrace(std::shared_ptr &monitor); +}; +class TestMissionStateMock : public AppMonitorMock, public TestMissionStateTest +{ +public: + TestMissionStateMock() = default; + virtual ~TestMissionStateMock() = default; + // MOCK_METHOD1(SetAppMonitorTrace, const StatusCode(std::shared_ptr &)); +}; +#endif \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp index 56d32324..7651dc08 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -36,84 +36,82 @@ void AppManagerTestTool::UnInit(void) } void AppManagerTestTool::MockGetProductInfo(void) { - // + std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); + if (mock) { + EXPECT_CALL(*mock.get(), GetProductInfoTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); + } ServersMock::GetInstance()->MockGetProductInfo(); } void AppManagerTestTool::MockGetDeviceAttr(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), GetDeviceAttrTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), GetDeviceAttrTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockGetDeviceAttr(); } void AppManagerTestTool::MockGetMediaInfo(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), GetMediaInfoTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), GetMediaInfoTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockGetMediaInfo(); } void AppManagerTestTool::MockGetSdCardInfo(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockGetSdCardInfo(); } void AppManagerTestTool::MockGetBatteryInfo(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockGetBatteryInfo(); } void AppManagerTestTool::MockSetDateTime(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockSetDateTime(); } void AppManagerTestTool::MockSetTimeZone(void) { std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); - if (!mock) { - LogError("vMock error.\n"); - return; + if (mock) { + EXPECT_CALL(*mock.get(), SetTimeZoneTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } - EXPECT_CALL(*mock.get(), SetTimeZoneTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) - .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockSetTimeZone(); } void AppManagerTestTool::MockUploadFiles(void) { - // + std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); + if (mock) { + EXPECT_CALL(*mock.get(), UploadFileTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); + } ServersMock::GetInstance()->MockUploadFiles(); } void AppManagerTestTool::AppManagerMockInit(std::shared_ptr &vMock)