diff --git a/application/MissionManager/src/DataProcessing.h b/application/MissionManager/src/DataProcessing.h index 2ad8653..f367552 100644 --- a/application/MissionManager/src/DataProcessing.h +++ b/application/MissionManager/src/DataProcessing.h @@ -24,6 +24,7 @@ enum class InternalStateEvent { STORAGE_HANDLE_STATE_INIT = static_cast(MissionEvent::END), SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED, + ANY_STATE_SD_STATUS_PERORIED, CHECK_UPGRADE_FILE, MEDIA_REPORT_EVENT, END diff --git a/application/MissionManager/src/MissionState.h b/application/MissionManager/src/MissionState.h index 84d1aa0..5b11988 100644 --- a/application/MissionManager/src/MissionState.h +++ b/application/MissionManager/src/MissionState.h @@ -25,9 +25,11 @@ public: void GoOutState() override; bool ExecuteStateMsg(VStateMachineData *msg) override; +protected: + bool SdCardEventReportHandle(VStateMachineData *msg); + private: bool MediaReportHandle(VStateMachineData *msg); - bool SdCardEventReportHandle(VStateMachineData *msg); bool CheckUpgradeFileHandle(VStateMachineData *msg); }; #endif \ No newline at end of file diff --git a/application/MissionManager/src/StorageHandleState.cpp b/application/MissionManager/src/StorageHandleState.cpp index 57198a7..86b80a9 100644 --- a/application/MissionManager/src/StorageHandleState.cpp +++ b/application/MissionManager/src/StorageHandleState.cpp @@ -48,6 +48,9 @@ void StorageHandleState::ReportEvent(const StorageEvent &event) std::shared_ptr message = std::make_shared>( static_cast(InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED), event); MissionStateMachine::GetInstance()->SendStateMessage(message); + std::shared_ptr message2 = std::make_shared>( + static_cast(InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED), event); + MissionStateMachine::GetInstance()->SendStateMessage(message2); } bool StorageHandleState::StorageStartInitHandle(VStateMachineData *msg) { diff --git a/application/MissionManager/src/TestMissionState.cpp b/application/MissionManager/src/TestMissionState.cpp index 9b6beff..e0dd1dd 100644 --- a/application/MissionManager/src/TestMissionState.cpp +++ b/application/MissionManager/src/TestMissionState.cpp @@ -15,8 +15,12 @@ #include "TestMissionState.h" #include "IAppManager.h" #include "ILog.h" +#include "IStorageManager.h" +#include "MissionStateMachine.h" TestMissionState::TestMissionState() : MissionState("TestMissionState") { + mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] = + std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1); } void TestMissionState::GoInState() { @@ -33,7 +37,27 @@ void TestMissionState::GoOutState() MissionState::GoOutState(); LogInfo(" ========== TestMissionState::GoOutState.\n"); } -// bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg) -// { -// return MissionState::EventHandle(msg); -// } \ No newline at end of file +bool TestMissionState::SdCardEventReportSendToApp(VStateMachineData *msg) +{ + std::shared_ptr message = std::dynamic_pointer_cast(msg->GetMessageObj()); + std::shared_ptr> data = + std::dynamic_pointer_cast>(message->mMissionData); + LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData)); + SdCardStatus status = SdCardStatusConvert(data->mData); + IAppManager::GetInstance()->SetSdCardStatus(status); + return EXECUTED; +} +SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event) +{ + switch (event) { + case StorageEvent::SD_CARD_INSERT: + return SdCardStatus::NORMAL; + case StorageEvent::SD_CARD_REMOVE: + return SdCardStatus::NOT_INSERTED; + case StorageEvent::SD_ABNORMAL: + return SdCardStatus::NOT_INSERTED; + default: + LogError("SdCardStatusConvert failed.\n"); + return SdCardStatus::END; + } +} \ No newline at end of file diff --git a/application/MissionManager/src/TestMissionState.h b/application/MissionManager/src/TestMissionState.h index 0d266e6..62322ae 100644 --- a/application/MissionManager/src/TestMissionState.h +++ b/application/MissionManager/src/TestMissionState.h @@ -16,6 +16,7 @@ #define TEST_MISSION_STATE_H #include "AppMonitor.h" #include "IStateMachine.h" +#include "IStorageManager.h" #include "MissionState.h" class TestMissionState : public MissionState, public AppMonitor { @@ -24,6 +25,11 @@ public: virtual ~TestMissionState() = default; void GoInState() override; void GoOutState() override; - // bool ExecuteStateMsg(VStateMachineData *msg) override; + +private: + bool SdCardEventReportSendToApp(VStateMachineData *msg); + +private: + SdCardStatus SdCardStatusConvert(const StorageEvent &event); }; #endif \ No newline at end of file diff --git a/middleware/AppManager/include/IAppManager.h b/middleware/AppManager/include/IAppManager.h index de70391..9eae983 100644 --- a/middleware/AppManager/include/IAppManager.h +++ b/middleware/AppManager/include/IAppManager.h @@ -337,5 +337,6 @@ public: virtual const StatusCode Init(const AppParam ¶m); virtual const StatusCode UnInit(void); virtual const StatusCode SetAppMonitor(std::shared_ptr &monitor); + virtual StatusCode SetSdCardStatus(const SdCardStatus &status); }; #endif \ No newline at end of file diff --git a/middleware/AppManager/src/AppManager.cpp b/middleware/AppManager/src/AppManager.cpp index 64bb579..ccc64d7 100644 --- a/middleware/AppManager/src/AppManager.cpp +++ b/middleware/AppManager/src/AppManager.cpp @@ -63,6 +63,13 @@ const StatusCode AppManager::SetAppMonitor(std::shared_ptr &monitor mAppMonitor = monitor; return CreateStatusCode(STATUS_CODE_OK); } +StatusCode AppManager::SetSdCardStatus(const SdCardStatus &status) +{ + for (const auto &pair : mAppClients) { + pair.second->SetSdCardStatus(status); + } + return CreateStatusCode(STATUS_CODE_OK); +} void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context) { diff --git a/middleware/AppManager/src/AppManager.h b/middleware/AppManager/src/AppManager.h index 25e044e..0034e8d 100644 --- a/middleware/AppManager/src/AppManager.h +++ b/middleware/AppManager/src/AppManager.h @@ -26,6 +26,7 @@ public: const StatusCode Init(const AppParam ¶m) override; const StatusCode UnInit(void) override; const StatusCode SetAppMonitor(std::shared_ptr &monitor) override; + StatusCode SetSdCardStatus(const SdCardStatus &status) override; void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context); void AppRequestHandleTcp(const char *data, const unsigned int dataLength, ResponseHandle responseHandle, void *context); diff --git a/middleware/AppManager/src/IAppManager.cpp b/middleware/AppManager/src/IAppManager.cpp index 64bcc9c..950f955 100644 --- a/middleware/AppManager/src/IAppManager.cpp +++ b/middleware/AppManager/src/IAppManager.cpp @@ -207,6 +207,10 @@ const StatusCode IAppManager::UnInit(void) return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IAppManager::SetAppMonitor(std::shared_ptr &monitor) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IAppManager::SetSdCardStatus(const SdCardStatus &status) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/test/application/HuntingCamera/src_mock/AppManager_Mock_Test.cpp b/test/application/HuntingCamera/src_mock/AppManager_Mock_Test.cpp new file mode 100644 index 0000000..7317df6 --- /dev/null +++ b/test/application/HuntingCamera/src_mock/AppManager_Mock_Test.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "AppManagerTestTool.h" +#include "GtestUsing.h" +#include "HalTestTool.h" +#include "HuntingCameraTest.h" +#include "ILog.h" +#include "MainThread.h" +#include "McuManagerTestTool.h" +#include "MissionManagerTestTool.h" +#include "TestManager.h" +#include +namespace AppManager_Mock_Test +{ +/** + * @brief Construct a new test f object + * ../output_files/test/bin/HuntingCameraTest + * --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_SetSdCardStatus + */ +TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_SetSdCardStatus) +{ + MainThread::GetInstance()->Init(); + TestManager::ResetTimeOut(1000 * 6); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + AppManagerTestTool::MockAppClientConnect(); + HalTestTool::MockSdCardRemove(mLinuxTest); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + HalTestTool::MockSdCardInsert(mLinuxTest); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MainThread::GetInstance()->Runing(); + // printf("helle world\n"); + // LogInfo("helle world\n"); + // +} +} // namespace AppManager_Mock_Test \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/TestMissionStateMock.cpp b/test/application/MissionManager/tool/src/TestMissionStateMock.cpp index 75e92de..13a58cc 100644 --- a/test/application/MissionManager/tool/src/TestMissionStateMock.cpp +++ b/test/application/MissionManager/tool/src/TestMissionStateMock.cpp @@ -164,4 +164,13 @@ StatusCode TestMissionStateTest::UploadFile(AppUploadFile ¶m) return AppMonitor::UploadFile(param); } return code; +} +StatusCode TestMissionStateTest::AppClientConnected(std::shared_ptr &client) +{ + LogInfo("TestMissionStateTest::AppClientConnected\n"); + StatusCode code = AppClientConnectedTrace(client); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppMonitor::AppClientConnected(client); + } + 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 index 3ff21d7..3590c2b 100644 --- a/test/application/MissionManager/tool/src/TestMissionStateMock.h +++ b/test/application/MissionManager/tool/src/TestMissionStateMock.h @@ -38,6 +38,7 @@ public: StatusCode EnterRecorder(void) override; StatusCode AppPlayback(const PlayBackEvent &event) override; StatusCode UploadFile(AppUploadFile ¶m) override; + StatusCode AppClientConnected(std::shared_ptr &client) override; protected: }; diff --git a/test/hal/tool/include/HalTestTool.h b/test/hal/tool/include/HalTestTool.h index 584b056..0235b27 100644 --- a/test/hal/tool/include/HalTestTool.h +++ b/test/hal/tool/include/HalTestTool.h @@ -68,7 +68,10 @@ private: // About camera hal void InitAllCamerasMock(std::map> &allCameras); void InitCamerasMock(std::shared_ptr &vMock); -private: // About sd card hal +protected: // About sd card hal + void MockSdCardRemove(std::shared_ptr &mock); + void MockSdCardInsert(std::shared_ptr &mock); + public: static std::shared_ptr MakeKeyHalTest(const std::string &keyName); static std::shared_ptr MakeLedHalTest(const std::string &ledName); diff --git a/test/hal/tool/src/HalTestTool.cpp b/test/hal/tool/src/HalTestTool.cpp index f992959..2a42fe7 100644 --- a/test/hal/tool/src/HalTestTool.cpp +++ b/test/hal/tool/src/HalTestTool.cpp @@ -312,6 +312,24 @@ void HalTestTool::InitCamerasMock(std::shared_ptr &vMock) constexpr int USER_SHOULD_SET_CAMERA_MONITER = 1; EXPECT_CALL(*mock.get(), SetCameraMonitorTrace(_)).Times(USER_SHOULD_SET_CAMERA_MONITER); } +void HalTestTool::MockSdCardRemove(std::shared_ptr &mock) +{ + std::shared_ptr sdCardHal = std::dynamic_pointer_cast(mSdCardHal); + if (nullptr == sdCardHal) { + LogError("SdCardHalMock is null.\n"); + return; + } + sdCardHal->MockSdCardRemove(mock); +} +void HalTestTool::MockSdCardInsert(std::shared_ptr &mock) +{ + std::shared_ptr sdCardHal = std::dynamic_pointer_cast(mSdCardHal); + if (nullptr == sdCardHal) { + LogError("SdCardHalMock is null.\n"); + return; + } + sdCardHal->MockSdCardInsert(mock); +} std::shared_ptr HalTestTool::MakeKeyHalTest(const std::string &keyName) { std::shared_ptr key = std::make_shared(keyName); diff --git a/test/hal/tool/src/SdCardHalMock.cpp b/test/hal/tool/src/SdCardHalMock.cpp index 0be72d7..d332901 100644 --- a/test/hal/tool/src/SdCardHalMock.cpp +++ b/test/hal/tool/src/SdCardHalMock.cpp @@ -15,14 +15,15 @@ #include "SdCardHalMock.h" #include "ILog.h" extern const char *SD_CARD_DEVICE; +constexpr int FSTAT_SUCCESS = 0; +constexpr int FILE_EXIST = 0; +constexpr int FILE_NOT_EXIST = -1; SdCardHalMock::SdCardHalMock() { mDevFd = -1; } void SdCardHalMock::SetLinuxTest(std::shared_ptr &mock) { - constexpr int FSTAT_SUCCESS = 0; - constexpr int FILE_EXIST = 0; mLinuxTest = mock; mDevFd = mLinuxTest->GetHandleForMock(); EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST))); @@ -32,4 +33,12 @@ void SdCardHalMock::SetLinuxTest(std::shared_ptr &mock) }; EXPECT_CALL(*mock.get(), fx_fstat(mDevFd, _)) .WillRepeatedly(DoAll(WithArgs<0, 1>(Invoke(fstatFunc)), Return(FSTAT_SUCCESS))); +} +void SdCardHalMock::MockSdCardRemove(std::shared_ptr &mock) +{ + EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_NOT_EXIST))); +} +void SdCardHalMock::MockSdCardInsert(std::shared_ptr &mock) +{ + EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST))); } \ No newline at end of file diff --git a/test/hal/tool/src/SdCardHalMock.h b/test/hal/tool/src/SdCardHalMock.h index 72fb110..bf7f5e2 100644 --- a/test/hal/tool/src/SdCardHalMock.h +++ b/test/hal/tool/src/SdCardHalMock.h @@ -23,6 +23,8 @@ public: SdCardHalMock(); virtual ~SdCardHalMock() = default; void SetLinuxTest(std::shared_ptr &mock); + void MockSdCardRemove(std::shared_ptr &mock); + void MockSdCardInsert(std::shared_ptr &mock); private: std::shared_ptr mLinuxTest; diff --git a/test/middleware/AppManager/tool/include/AppManagerTestTool.h b/test/middleware/AppManager/tool/include/AppManagerTestTool.h index da36e22..3889ecf 100644 --- a/test/middleware/AppManager/tool/include/AppManagerTestTool.h +++ b/test/middleware/AppManager/tool/include/AppManagerTestTool.h @@ -25,7 +25,7 @@ public: void Init(void); void UnInit(void); -protected: +protected: // About http void MockGetProductInfo(void); void MockGetDeviceAttr(void); void MockGetMediaInfo(void); @@ -44,7 +44,7 @@ protected: void MockAppPlayback(void); void MockMonitorSetFileList(std::vector &files); -protected: +protected: // About TCP void MockAppClientConnect(void); void MockSetRecordingStatus(const RecordingStatus &status); void MockSetMicrophoneStatus(const MicrophoneStatus &status); diff --git a/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h index 1a1749a..9ee6027 100644 --- a/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h +++ b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h @@ -15,39 +15,9 @@ #ifndef DEVICE_MANAGER_TEST_TOOL_H #define DEVICE_MANAGER_TEST_TOOL_H #include "DeviceManager.h" +#include "GtestUsing.h" #include "HalTestTool.h" #include "LedControl.h" -#include -#include -using ::testing::_; -using ::testing::Action; -using ::testing::ActionInterface; -using ::testing::AnyNumber; -using ::testing::Assign; -using ::testing::AtLeast; -using ::testing::ByMove; -using ::testing::ByRef; -using ::testing::DefaultValue; -using ::testing::DoAll; -using ::testing::DoDefault; -using ::testing::IgnoreResult; -using ::testing::Invoke; -using ::testing::InvokeWithoutArgs; -using ::testing::MakePolymorphicAction; -using ::testing::PolymorphicAction; -using ::testing::Return; -using ::testing::ReturnNew; -using ::testing::ReturnNull; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::ReturnRefOfCopy; -using ::testing::ReturnRoundRobin; -using ::testing::SaveArg; -using ::testing::SetArgPointee; -using ::testing::SetArgumentPointee; -using ::testing::Unused; -using ::testing::WithArgs; -using ::testing::internal::BuiltInDefaultValue; class DeviceManagerTool : public DeviceManager { public: