From 82b6cf466318e3e7504b0770d2764eb0ecf22a61 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Tue, 5 Mar 2024 19:01:11 -0800 Subject: [PATCH 1/4] Improve:AppManager test code. --- .../MissionManager/src/MissionState.cpp | 29 ++++++++++++++ application/MissionManager/src/MissionState.h | 28 +++++++++++++ .../MissionManager/src/TestMissionState.cpp | 8 ++-- .../MissionManager/src/TestMissionState.h | 4 +- .../application/HunttingCamera/CMakeLists.txt | 3 +- .../src_mock/HunttingCamera_Mock_Test.cpp | 8 +++- .../tool/src/AppManagerTestTool.cpp | 40 +++++++++++-------- .../AppManager/tool/src/AppMonitorMock.cpp | 32 +++++++-------- .../AppManager/tool/src/AppMonitorMock.h | 31 ++++++++------ 9 files changed, 130 insertions(+), 53 deletions(-) create mode 100644 application/MissionManager/src/MissionState.cpp create mode 100644 application/MissionManager/src/MissionState.h diff --git a/application/MissionManager/src/MissionState.cpp b/application/MissionManager/src/MissionState.cpp new file mode 100644 index 0000000..658c8cd --- /dev/null +++ b/application/MissionManager/src/MissionState.cpp @@ -0,0 +1,29 @@ +/* + * 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 "MissionState.h" +#include "IAppManager.h" +#include "ILog.h" +MissionState::MissionState(const std::string &name) : State(name) {} +void MissionState::GoInState() +{ + // + LogInfo(" ========== MissionState::GoInState.\n"); +} +void MissionState::GoOutState() +{ + // + LogInfo(" ========== MissionState::GoOutState.\n"); +} +bool MissionState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); } \ No newline at end of file diff --git a/application/MissionManager/src/MissionState.h b/application/MissionManager/src/MissionState.h new file mode 100644 index 0000000..ab4e897 --- /dev/null +++ b/application/MissionManager/src/MissionState.h @@ -0,0 +1,28 @@ +/* + * 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_STATE_H +#define MISSION_STATE_H +#include "DataProcessing.h" +#include "IStateMachine.h" +class MissionState : public State, public DataProcessing +{ +public: + MissionState(const std::string &name); + virtual ~MissionState() = default; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(VStateMachineData *msg) override; +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/TestMissionState.cpp b/application/MissionManager/src/TestMissionState.cpp index 16853f2..af63361 100644 --- a/application/MissionManager/src/TestMissionState.cpp +++ b/application/MissionManager/src/TestMissionState.cpp @@ -15,17 +15,17 @@ #include "TestMissionState.h" #include "IAppManager.h" #include "ILog.h" -TestMissionState::TestMissionState() : State("TestMissionState") {} +TestMissionState::TestMissionState() : MissionState("TestMissionState") {} void TestMissionState::GoInState() { - // + MissionState::GoInState(); LogInfo(" ========== TestMissionState::GoInState.\n"); AppParam mAppParam("192.168.1.29", APP_MANAGER_HTTP_SERVER_PORT); // TODO: IAppManager::GetInstance()->Init(mAppParam); } void TestMissionState::GoOutState() { - // + MissionState::GoOutState(); LogInfo(" ========== TestMissionState::GoOutState.\n"); } -bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); } \ No newline at end of file +bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg) { return MissionState::EventHandle(msg); } \ No newline at end of file diff --git a/application/MissionManager/src/TestMissionState.h b/application/MissionManager/src/TestMissionState.h index 44f2cce..56b96f0 100644 --- a/application/MissionManager/src/TestMissionState.h +++ b/application/MissionManager/src/TestMissionState.h @@ -15,9 +15,9 @@ #ifndef TEST_MISSION_STATE_H #define TEST_MISSION_STATE_H #include "AppMonitor.h" -#include "DataProcessing.h" #include "IStateMachine.h" -class TestMissionState : public State, public DataProcessing, public AppMonitor +#include "MissionState.h" +class TestMissionState : public MissionState, public AppMonitor { public: TestMissionState(); diff --git a/test/application/HunttingCamera/CMakeLists.txt b/test/application/HunttingCamera/CMakeLists.txt index 5bf5957..3eeea30 100644 --- a/test/application/HunttingCamera/CMakeLists.txt +++ b/test/application/HunttingCamera/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( ${UTILS_SOURCE_PATH}/UartDevice/include ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/middleware/McuManager/tool/include + ${TEST_SOURCE_PATH}/middleware/AppManager/tool/include ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include ${TEST_SOURCE_PATH}/utils/TestManager/include ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include @@ -34,7 +35,7 @@ endif() set(TARGET_NAME HunttingCameraTest) add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} HunttingMainLib McuManagerTestTool McuAskBaseTestTool TestManager gtest gmock pthread) +target_link_libraries(${TARGET_NAME} HunttingMainLib McuManagerTestTool McuAskBaseTestTool AppManagerTestTool TestManager gtest gmock pthread) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() diff --git a/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp b/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp index e066971..e580375 100644 --- a/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp +++ b/test/application/HunttingCamera/src_mock/HunttingCamera_Mock_Test.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "AppManagerTestTool.h" #include "GtestUsing.h" #include "ILog.h" #include "MainThread.h" @@ -20,7 +21,10 @@ #include namespace HunttingCameraTest { -class HunttingCameraTest : public testing::Test, public TestManager, public McuManagerTestTool +class HunttingCameraTest : public testing::Test, + public TestManager, + public McuManagerTestTool, + public AppManagerTestTool { public: HunttingCameraTest() {} @@ -68,6 +72,8 @@ TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo) { MainThread::GetInstance()->Init(); TestManager::ResetTimeOut(1000 * 3); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MockGetMediaInfo(); MainThread::GetInstance()->Runing(); } } // namespace HunttingCameraTest \ 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 adbf105..56d3232 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -106,7 +106,7 @@ void AppManagerTestTool::MockSetTimeZone(void) LogError("vMock error.\n"); return; } - EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) + EXPECT_CALL(*mock.get(), SetTimeZoneTrace(_)) .Times(ONLY_BE_CALLED_ONCE) .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockSetTimeZone(); @@ -125,7 +125,8 @@ void AppManagerTestTool::AppManagerMockInit(std::shared_ptr &vMock) } auto getAppMonitor = [=](std::shared_ptr &monitor) { LogInfo("mAppMonitorMock get.\n"); - mAppMonitorMock = std::dynamic_pointer_cast(monitor); + // mAppMonitorMock = std::dynamic_pointer_cast(monitor); + mAppMonitorMock = monitor; AppManagerTestTool::AppMonitorInit(mAppMonitorMock); }; EXPECT_CALL(*mock.get(), SetAppMonitorTrace(_)) @@ -134,27 +135,32 @@ void AppManagerTestTool::AppManagerMockInit(std::shared_ptr &vMock) } 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(), GetDeviceAttrTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); - EXPECT_CALL(*monitor.get(), GetMediaInfoTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); - EXPECT_CALL(*monitor.get(), GetSdCardInfoTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); - EXPECT_CALL(*monitor.get(), GetBatteryInfoTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); - EXPECT_CALL(*monitor.get(), SetDateTimeTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); - EXPECT_CALL(*monitor.get(), UploadFileTrace(_)) - .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); + class Monitor : public AppMonitorMock, public AppMonitorTest + { + public: + Monitor() = default; + virtual ~Monitor() = default; + }; + std::shared_ptr monitor = std::make_shared(); + // auto result = std::dynamic_pointer_cast(monitor); return monitor; } void AppManagerTestTool::AppMonitorInit(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(), 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(), UploadFileTrace(_)) .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp index c9dafc9..5185208 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp @@ -23,9 +23,9 @@ StatusCode AppMonitorTest::GetProductInfo(AppGetProductInfo ¶m) } return code; } -StatusCode AppMonitorTest::GetProductInfoTrace(AppGetProductInfo ¶m) +StatusCode AppMonitorTrace::GetProductInfoTrace(AppGetProductInfo ¶m) { - LogInfo("AppMonitorTest::GetProductInfoTrace\n"); + LogInfo("AppMonitorTrace::GetProductInfoTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::GetDeviceAttr(AppGetDeviceAttr ¶m) @@ -37,9 +37,9 @@ StatusCode AppMonitorTest::GetDeviceAttr(AppGetDeviceAttr ¶m) } return code; } -StatusCode AppMonitorTest::GetDeviceAttrTrace(AppGetDeviceAttr ¶m) +StatusCode AppMonitorTrace::GetDeviceAttrTrace(AppGetDeviceAttr ¶m) { - LogInfo("AppMonitorTest::GetDeviceAttrTrace\n"); + LogInfo("AppMonitorTrace::GetDeviceAttrTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::GetMediaInfo(AppGetMeidaInfo ¶m) @@ -51,9 +51,9 @@ StatusCode AppMonitorTest::GetMediaInfo(AppGetMeidaInfo ¶m) } return code; } -StatusCode AppMonitorTest::GetMediaInfoTrace(AppGetMeidaInfo ¶m) +StatusCode AppMonitorTrace::GetMediaInfoTrace(AppGetMeidaInfo ¶m) { - LogInfo("AppMonitorTest::GetMediaInfoTrace\n"); + LogInfo("AppMonitorTrace::GetMediaInfoTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::GetSdCardInfo(AppGetSdCardInfo ¶m) @@ -65,9 +65,9 @@ StatusCode AppMonitorTest::GetSdCardInfo(AppGetSdCardInfo ¶m) } return code; } -StatusCode AppMonitorTest::GetSdCardInfoTrace(AppGetSdCardInfo ¶m) +StatusCode AppMonitorTrace::GetSdCardInfoTrace(AppGetSdCardInfo ¶m) { - LogInfo("AppMonitorTest::GetSdCardInfoTrace\n"); + LogInfo("AppMonitorTrace::GetSdCardInfoTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::GetBatteryInfo(AppGetBatteryInfo ¶m) @@ -79,9 +79,9 @@ StatusCode AppMonitorTest::GetBatteryInfo(AppGetBatteryInfo ¶m) } return code; } -StatusCode AppMonitorTest::GetBatteryInfoTrace(AppGetBatteryInfo ¶m) +StatusCode AppMonitorTrace::GetBatteryInfoTrace(AppGetBatteryInfo ¶m) { - LogInfo("AppMonitorTest::GetBatteryInfoTrace\n"); + LogInfo("AppMonitorTrace::GetBatteryInfoTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m) @@ -99,9 +99,9 @@ StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m) } return code; } -StatusCode AppMonitorTest::SetDateTimeTrace(AppSetDateTime ¶m) +StatusCode AppMonitorTrace::SetDateTimeTrace(AppSetDateTime ¶m) { - LogInfo("AppMonitorTest::SetDateTimeTrace\n"); + LogInfo("AppMonitorTrace::SetDateTimeTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::SetTimeZone(const unsigned int &zone) @@ -113,9 +113,9 @@ StatusCode AppMonitorTest::SetTimeZone(const unsigned int &zone) } return code; } -StatusCode AppMonitorTest::SetTimeZoneTrace(const unsigned int &zone) +StatusCode AppMonitorTrace::SetTimeZoneTrace(const unsigned int &zone) { - LogInfo("AppMonitorTest::SetTimeZoneTrace\n"); + LogInfo("AppMonitorTrace::SetTimeZoneTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m) @@ -127,8 +127,8 @@ StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m) } return code; } -StatusCode AppMonitorTest::UploadFileTrace(AppUploadFile ¶m) +StatusCode AppMonitorTrace::UploadFileTrace(AppUploadFile ¶m) { - LogInfo("AppMonitorTest::UploadFileTrace\n"); + LogInfo("AppMonitorTrace::UploadFileTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.h b/test/middleware/AppManager/tool/src/AppMonitorMock.h index a8fde72..42add15 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.h +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.h @@ -16,7 +16,23 @@ #define APP_MONITOR_MOCK_H #include "GtestUsing.h" #include "IAppManager.h" -class AppMonitorTest : public VAppMonitor +class AppMonitorTrace +{ +public: + AppMonitorTrace() = default; + virtual ~AppMonitorTrace() = 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 SetDateTimeTrace(AppSetDateTime ¶m); + virtual StatusCode SetTimeZoneTrace(const unsigned int &zone); + virtual StatusCode UploadFileTrace(AppUploadFile ¶m); +}; +class AppMonitorTest : public VAppMonitor, virtual public AppMonitorTrace { public: AppMonitorTest() = default; @@ -29,18 +45,8 @@ public: StatusCode SetDateTime(AppSetDateTime ¶m) override; StatusCode SetTimeZone(const unsigned int &zone) override; StatusCode UploadFile(AppUploadFile ¶m) override; - -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 SetDateTimeTrace(AppSetDateTime ¶m); - virtual StatusCode SetTimeZoneTrace(const unsigned int &zone); - virtual StatusCode UploadFileTrace(AppUploadFile ¶m); }; -class AppMonitorMock : public AppMonitorTest +class AppMonitorMock : virtual public AppMonitorTrace { public: AppMonitorMock() = default; @@ -51,6 +57,7 @@ public: MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &)); MOCK_METHOD1(GetBatteryInfoTrace, StatusCode(AppGetBatteryInfo &)); MOCK_METHOD1(SetDateTimeTrace, StatusCode(AppSetDateTime &)); + MOCK_METHOD1(SetTimeZoneTrace, StatusCode(const unsigned int &)); MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &)); }; #endif \ No newline at end of file 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 2/4] 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 dcbf8a4..611479c 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 4ced64c..a0a6d9b 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 481ddbf..615a98b 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 ab4e897..883a512 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 af63361..ede0c2d 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 63eee97..597aef7 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 1877b72..c4171e8 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 a590d5d..f628974 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 3b779cb..3fc9a5c 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 cdf9654..dff2f93 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 e580375..73f56d9 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 0000000..f4e8c70 --- /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 0000000..d917c25 --- /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 0000000..0f65e86 --- /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 0000000..c0e989c --- /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 0000000..6045c95 --- /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 0000000..2806095 --- /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 56d3232..7651dc0 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) From b4d5fa020dc21336d18ac0c86eb9ea1b78f243d5 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Wed, 6 Mar 2024 00:23:17 -0800 Subject: [PATCH 3/4] Backup --- application/MissionManager/src/AppMonitor.cpp | 18 ++++++++++++++++++ .../MissionManager/src/DataProcessing.h | 4 ++-- .../MissionManager/src/MissionManager.h | 4 ++-- .../MissionManager/src/MissionManagerMakePtr.h | 4 ++-- .../MissionManager/src/MissionStateMachine.h | 4 ++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/application/MissionManager/src/AppMonitor.cpp b/application/MissionManager/src/AppMonitor.cpp index 615a98b..58ee339 100644 --- a/application/MissionManager/src/AppMonitor.cpp +++ b/application/MissionManager/src/AppMonitor.cpp @@ -1,3 +1,17 @@ +/* + * 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 "AppMonitor.h" #include "ILog.h" StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m) @@ -11,6 +25,7 @@ StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m) } StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m) { + LogInfo("AppMonitor::GetDeviceAttr.\n"); param.mUUID = "test"; param.mSoftVersion = "test"; param.mOtaVersion = "test"; @@ -24,6 +39,7 @@ StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m) } StatusCode AppMonitor::GetMediaInfo(AppGetMeidaInfo ¶m) { + LogInfo("AppMonitor::GetMediaInfo.\n"); param.mRtspUrl = "test"; param.mTransport = "test"; param.mPort = 123; @@ -31,6 +47,7 @@ StatusCode AppMonitor::GetMediaInfo(AppGetMeidaInfo ¶m) } StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m) { + LogInfo("AppMonitor::GetSdCardInfo.\n"); param.mStatus = SdCardStatus::CARD_DAMAGED; param.mFree = 0; param.mTotal = 0; @@ -38,6 +55,7 @@ StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m) } StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m) { + LogInfo("AppMonitor::GetBatteryInfo.\n"); param.mCapacity = 0; param.mChargeStatus = ChargeStatus::CHARGING; return CreateStatusCode(STATUS_CODE_OK); diff --git a/application/MissionManager/src/DataProcessing.h b/application/MissionManager/src/DataProcessing.h index 7f170e2..3543792 100644 --- a/application/MissionManager/src/DataProcessing.h +++ b/application/MissionManager/src/DataProcessing.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef DATAPROCESSING_H -#define DATAPROCESSING_H +#ifndef DATA_PROCESSING_H +#define DATA_PROCESSING_H #include "IMissionManager.h" #include "IStateMachine.h" #include diff --git a/application/MissionManager/src/MissionManager.h b/application/MissionManager/src/MissionManager.h index 7b33334..a1e6af4 100644 --- a/application/MissionManager/src/MissionManager.h +++ b/application/MissionManager/src/MissionManager.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MISSIONMANAGER_H -#define MISSIONMANAGER_H +#ifndef MISSION_MANAGER_H +#define MISSION_MANAGER_H #include "IMissionManager.h" class MissionManager : public IMissionManager { diff --git a/application/MissionManager/src/MissionManagerMakePtr.h b/application/MissionManager/src/MissionManagerMakePtr.h index c2e0b37..aac79f2 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.h +++ b/application/MissionManager/src/MissionManagerMakePtr.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MISSIONMANAGERMAKEIMPL_H -#define MISSIONMANAGERMAKEIMPL_H +#ifndef MISSION_MANAGER_MAKE_PTR_H +#define MISSION_MANAGER_MAKE_PTR_H #include "IMcuManager.h" #include "IMissionManager.h" #include "IStateMachine.h" diff --git a/application/MissionManager/src/MissionStateMachine.h b/application/MissionManager/src/MissionStateMachine.h index f0eccb9..c7273b3 100644 --- a/application/MissionManager/src/MissionStateMachine.h +++ b/application/MissionManager/src/MissionStateMachine.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MISSIONSTATEMACHINE_H -#define MISSIONSTATEMACHINE_H +#ifndef MISSION_STATE_MACHINE_H +#define MISSION_STATE_MACHINE_H // #include "IDeviceManager.h" #include "IMcuManager.h" #include "IMissionManager.h" From 7233841a4aaac7c9eca408437fc311922aa5d0ae Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Wed, 6 Mar 2024 05:49:11 -0800 Subject: [PATCH 4/4] Backup. --- hal/abstract/IHalCpp.cpp | 4 ++++ hal/include/IHalCpp.h | 8 ++++++++ hal/src/WifiHal.cpp | 14 ++++++++++++++ hal/src/WifiHal.h | 24 ++++++++++++++++++++++++ middleware/AppManager/src/AppManager.cpp | 10 +++++++++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 hal/src/WifiHal.cpp create mode 100644 hal/src/WifiHal.h diff --git a/hal/abstract/IHalCpp.cpp b/hal/abstract/IHalCpp.cpp index ae01756..58369e4 100644 --- a/hal/abstract/IHalCpp.cpp +++ b/hal/abstract/IHalCpp.cpp @@ -36,6 +36,10 @@ StatusCode IHalCpp::GetAllLeds(std::map> & return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode IHalCpp::GetAllKeys(std::map> &allKeys) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IHalCpp::GetWifiHal(std::shared_ptr &wifi) { 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 da82e9e..b885ed2 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -50,6 +50,13 @@ public: VLedHal() = default; virtual ~VLedHal() = default; }; +class VWifiHal +{ +public: + VWifiHal() = default; + virtual ~VWifiHal() = default; + virtual StatusCode OpenApMode(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +}; class IHalCpp { public: @@ -60,5 +67,6 @@ public: virtual StatusCode UnInit(void); virtual StatusCode GetAllLeds(std::map> &allLeds); virtual StatusCode GetAllKeys(std::map> &allKeys); + virtual StatusCode GetWifiHal(std::shared_ptr &wifi); }; #endif diff --git a/hal/src/WifiHal.cpp b/hal/src/WifiHal.cpp new file mode 100644 index 0000000..f297c00 --- /dev/null +++ b/hal/src/WifiHal.cpp @@ -0,0 +1,14 @@ +/* + * 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. + */ \ No newline at end of file diff --git a/hal/src/WifiHal.h b/hal/src/WifiHal.h new file mode 100644 index 0000000..70384bc --- /dev/null +++ b/hal/src/WifiHal.h @@ -0,0 +1,24 @@ +/* + * 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 WIFI_HAL_H +#define WIFI_HAL_H +#include "IHalCpp.h" +class WifiHal : public VWifiHal +{ +public: + WifiHal() = default; + virtual ~WifiHal() = default; +}; +#endif \ No newline at end of file diff --git a/middleware/AppManager/src/AppManager.cpp b/middleware/AppManager/src/AppManager.cpp index c4171e8..634bbeb 100644 --- a/middleware/AppManager/src/AppManager.cpp +++ b/middleware/AppManager/src/AppManager.cpp @@ -15,6 +15,7 @@ #include "AppManager.h" #include "AppManagerMakePtr.h" // #include "FxHttpServer.h" +#include "IHalCpp.h" #include "ILog.h" #include "WebServer.h" AppManager::AppManager() @@ -24,11 +25,18 @@ AppManager::AppManager() } const StatusCode AppManager::Init(const AppParam ¶m) { + std::shared_ptr wifi; + IHalCpp::GetInstance()->GetWifiHal(wifi); + if (!wifi) { + LogError("Get wifi hal failed.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + wifi->OpenApMode(); AppManagerMakePtr::GetInstance()->CreateProtocolHandle(mProtocolHandle); HttpServerStart(param); return CreateStatusCode(STATUS_CODE_OK); } -const StatusCode AppManager::UnInit(void) +const StatusCode AppManager::UnInit(void) { HttpServerStop(); mProtocolHandle.reset();