From ffce54a373c0d0aabacbacc284dfa4637ee75370 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Mon, 4 Mar 2024 01:00:04 -0800 Subject: [PATCH] Add:SixFrame protocol code. --- middleware/AppManager/include/IAppManager.h | 43 ++++++- middleware/AppManager/src/IAppManager.cpp | 8 ++ .../src/Protocol/SixFrame/SixFrameHandle.cpp | 115 ++++++++++++++---- .../src/Protocol/SixFrame/SixFrameHandle.h | 55 ++++++--- .../AppManager/src/AppManager_Test.cpp | 24 ++++ .../tool/include/AppManagerTestTool.h | 2 + .../tool/src/AppManagerTestTool.cpp | 28 +++++ .../AppManager/tool/src/AppMonitorMock.cpp | 28 +++++ .../AppManager/tool/src/AppMonitorMock.h | 6 + .../AppManager/tool/src/ServersMock.cpp | 36 ++++++ .../AppManager/tool/src/ServersMock.h | 2 + 11 files changed, 309 insertions(+), 38 deletions(-) diff --git a/middleware/AppManager/include/IAppManager.h b/middleware/AppManager/include/IAppManager.h index 0e839979..8f5c555f 100644 --- a/middleware/AppManager/include/IAppManager.h +++ b/middleware/AppManager/include/IAppManager.h @@ -61,8 +61,15 @@ typedef struct app_get_media_info } AppGetMeidaInfo; enum class SdCardStatus { - UNMOUNT = 0, - END + NORMAL = 0, + UNFORMATTED = 1, + NOT_INSERTED = 2, + CARD_DAMAGED = 3, + CARD_LOCKED = 10, + SLOW_CARD = 11, + FORMAT_REQUIRED = 12, + FORMATTING = 13, + END = 99 }; typedef struct app_get_sd_card_info { @@ -76,6 +83,36 @@ typedef struct app_get_sd_card_info int mFree; int mTotal; } AppGetSdCardInfo; +enum class ChargeStatus +{ + UNCHARGED = 0, + CHARGING, + END +}; +typedef struct app_get_battery_info +{ + app_get_battery_info() + { + mCapacity = 0; + mChargeStatus = ChargeStatus::END; + } + int mCapacity; + ChargeStatus mChargeStatus; +} AppGetBatteryInfo; +typedef struct app_set_date_time +{ + app_set_date_time(const unsigned int year, const unsigned int month, const unsigned int day, + const unsigned int hour, const unsigned int minute, const unsigned int second) + : mYear(year), mMonth(month), mDay(day), mHour(hour), mMinute(minute), mSecond(second) + { + } + const unsigned int mYear; + const unsigned int mMonth; + const unsigned int mDay; + const unsigned int mHour; + const unsigned int mMinute; + const unsigned int mSecond; +} AppSetDateTime; typedef struct app_upload_file { app_upload_file(const std::string filePath, const UploadCommand command) : mFilePath(filePath), mCommand(command) @@ -95,6 +132,8 @@ public: virtual StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m); virtual StatusCode GetMediaInfo(AppGetMeidaInfo ¶m); virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m); + virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m); + virtual StatusCode SetDateTime(AppSetDateTime ¶m); virtual StatusCode UploadFile(AppUploadFile ¶m); }; typedef struct app_param diff --git a/middleware/AppManager/src/IAppManager.cpp b/middleware/AppManager/src/IAppManager.cpp index 68d43d35..9d2a570d 100644 --- a/middleware/AppManager/src/IAppManager.cpp +++ b/middleware/AppManager/src/IAppManager.cpp @@ -30,6 +30,14 @@ StatusCode inline VAppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +StatusCode inline VAppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode inline VAppMonitor::SetDateTime(AppSetDateTime ¶m) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} StatusCode inline VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp index 94db5e3c..637102ca 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp @@ -19,22 +19,26 @@ using std::placeholders::_1; using std::placeholders::_2; using std::placeholders::_3; -// using std::placeholders::_4; +using std::placeholders::_4; const char *CJSON_INFO_STRING = "info"; const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo"; const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr"; const char *APP_GET_MEDIA_INFO = "/app/getmediainfo"; const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo"; +const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo"; +const char *APP_SET_DATE_TIME = "/app/setsystime"; const char *APP_UPLOAD_FILE = "/upload"; SixFrameHandle::SixFrameHandle() { mAppMonitor = std::make_shared(); - mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3); - mResquesHandleFunc[APP_GET_DEVICE_ATTR] = std::bind(&SixFrameHandle::RequestGetDeviceAttr, this, _1, _2, _3); - mResquesHandleFunc[APP_GET_MEDIA_INFO] = std::bind(&SixFrameHandle::RequestGetMediaInfo, this, _1, _2, _3); - mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3); - mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3); - // mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3); + mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_GET_DEVICE_ATTR] = std::bind(&SixFrameHandle::RequestGetDeviceAttr, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_GET_MEDIA_INFO] = std::bind(&SixFrameHandle::RequestGetMediaInfo, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_SET_DATE_TIME] = std::bind(&SixFrameHandle::RequestSetDateTime, this, _1, _2, _3, _4); + mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3, _4); + // mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3,_4); } void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context) @@ -51,10 +55,11 @@ void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength command = urlStr2.substr(0, urlStr2.length()); } LogInfo("command = %s\n", command.c_str()); - ExtractParamsFromUrl(urlStr2, paramsMap); - RequestHandle2(command, paramsMap, responseHandle, context); + // ExtractParamsFromUrl(urlStr2, paramsMap); + RequestHandle2(command, paramsMap, urlStr2, responseHandle, context); } -void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap ¶msMap) +void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap ¶msMap, + ParseUrlResultFunc resultHandle, std::shared_ptr &context) { size_t queryStartPos = url.find('?'); if (queryStartPos != std::string::npos && queryStartPos + 1 < url.length()) { @@ -68,30 +73,31 @@ void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap< std::string key = token.substr(0, equalSignPos); std::string value = token.substr(equalSignPos + 1); LogInfo("url get [%s] = %s\n", key.c_str(), value.c_str()); - paramsMap.insert({key, value}); + resultHandle(key, value, context); + // paramsMap.insert({key, value}); } } } } void SixFrameHandle::RequestHandle2(const std::string command, std::multimap ¶msMap, - ResponseHandle responseHandle, void *context) + const std::string &url, ResponseHandle responseHandle, void *context) { auto result = mResquesHandleFunc.find(command); if (result != mResquesHandleFunc.end()) { - (*result).second(paramsMap, responseHandle, context); + (*result).second(paramsMap, url, responseHandle, context); } else { LogError("Unknown command.\n"); - DoNothing(paramsMap, responseHandle, context); + DoNothing(paramsMap, url, responseHandle, context); } } -void SixFrameHandle::DoNothing(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context) +void SixFrameHandle::DoNothing(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context) { // responseHandle("Unknown command.", context); } -void SixFrameHandle::RequestGetProductInfo(std::multimap ¶msMap, +void SixFrameHandle::RequestGetProductInfo(std::multimap ¶msMap, const std::string &url, ResponseHandle responseHandle, void *context) { LogInfo("RequestGetProductInfo.\n"); @@ -104,7 +110,7 @@ void SixFrameHandle::RequestGetProductInfo(std::multimap ¶msMap, +void SixFrameHandle::RequestGetDeviceAttr(std::multimap ¶msMap, const std::string &url, ResponseHandle responseHandle, void *context) { LogInfo("RequestGetDeviceAttr.\n"); @@ -132,7 +138,7 @@ void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDev cJSON_AddStringToObject(info, "curcamid", param.mCurrentCameraID.c_str()); cJSON_AddStringToObject(info, "wifireboot", param.mWifiReboot.c_str()); } -void SixFrameHandle::RequestGetMediaInfo(std::multimap ¶msMap, +void SixFrameHandle::RequestGetMediaInfo(std::multimap ¶msMap, const std::string &url, ResponseHandle responseHandle, void *context) { LogInfo("RequestGetDeviceAttr.\n"); @@ -154,7 +160,7 @@ void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeid cJSON_AddStringToObject(info, "softver", param.mTransport.c_str()); cJSON_AddNumberToObject(info, "otaver", param.mPort); } -void SixFrameHandle::RequestGetSdCardInfo(std::multimap ¶msMap, +void SixFrameHandle::RequestGetSdCardInfo(std::multimap ¶msMap, const std::string &url, ResponseHandle responseHandle, void *context) { LogInfo("RequestGetDeviceAttr.\n"); @@ -176,8 +182,73 @@ void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdC cJSON_AddNumberToObject(info, "free", param.mFree); cJSON_AddNumberToObject(info, "total", param.mTotal); } -void SixFrameHandle::RequestUpload(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context) +void SixFrameHandle::RequestGetBatteryInfo(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context) +{ + LogInfo("RequestGetDeviceAttr.\n"); + char *resultStr = nullptr; + AppGetBatteryInfo param; + mAppMonitor->GetBatteryInfo(param); + cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); + ResponseGetBatteryInfo(result, param); + resultStr = cJSON_Print(result); + responseHandle(resultStr, context); + free(resultStr); + cJSON_Delete(result); +} +void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m) +{ + cJSON *info = nullptr; + cJSON_AddItemToObject(result, CJSON_INFO_STRING, info = cJSON_CreateObject()); + cJSON_AddNumberToObject(info, "charge", static_cast(param.mChargeStatus)); + cJSON_AddNumberToObject(info, "capacity", param.mCapacity); +} +AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string &url) +{ + auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr &parse) { + std::shared_ptr> parseyImpl = std::dynamic_pointer_cast>(parse); + if ("date" == key) { + parseyImpl->mData = value; + } + }; + std::shared_ptr parse = std::make_shared>(); + std::multimap paramsMap; + ExtractParamsFromUrl(url, paramsMap, parseFunc, parse); + std::shared_ptr> parseyImpl = std::dynamic_pointer_cast>(parse); + if (14 != parseyImpl->mData.length()) { + LogError("date parse failed.\n"); + return AppSetDateTime(0, 0, 0, 0, 0, 0); + } + std::string yearStr = parseyImpl->mData.substr(0, 4); + std::string monthStr = parseyImpl->mData.substr(4, 2); + std::string dayStr = parseyImpl->mData.substr(6, 2); + std::string hourStr = parseyImpl->mData.substr(8, 2); + std::string minuteStr = parseyImpl->mData.substr(10, 2); + std::string secondStr = parseyImpl->mData.substr(12, 2); + unsigned int year = std::stoi(yearStr); + unsigned int month = std::stoi(monthStr); + unsigned int day = std::stoi(dayStr); + unsigned int hour = std::stoi(hourStr); + unsigned int minute = std::stoi(minuteStr); + unsigned int second = std::stoi(secondStr); + return AppSetDateTime(year, month, day, hour, minute, second); +} +void SixFrameHandle::RequestSetDateTime(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context) +{ + LogInfo("RequestGetDeviceAttr.\n"); + char *resultStr = nullptr; + AppSetDateTime param = RequestSetDateTimeParse(url); + mAppMonitor->SetDateTime(param); + cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); + // ResponseGetBatteryInfo(result, param); + resultStr = cJSON_Print(result); + responseHandle(resultStr, context); + free(resultStr); + cJSON_Delete(result); +} +void SixFrameHandle::RequestUpload(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context) { LogInfo("RequestUpload.\n"); char *resultStr = nullptr; diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h index fcd11849..f75ab67f 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h @@ -23,7 +23,26 @@ #include #include #include -using ResquesHandleFunc = std::function &, ResponseHandle, void *)>; +using ResquesHandleFunc = + std::function &, const std::string &, ResponseHandle, void *)>; +class VParseUrl +{ +public: + VParseUrl() = default; + virtual ~VParseUrl() = default; +}; +template +class ParseUrl : public VParseUrl +{ + +public: + ParseUrl() {} + virtual ~ParseUrl() = default; + +public: + T mData; +}; +using ParseUrlResultFunc = void(const std::string &, const std::string &, std::shared_ptr &); class SixFrameHandle : public IAppProtocolHandle { public: @@ -35,23 +54,31 @@ public: void *context) override; private: - void ExtractParamsFromUrl(const std::string &url, std::multimap ¶msMap); + void ExtractParamsFromUrl(const std::string &url, std::multimap ¶msMap, + ParseUrlResultFunc resultHandle, std::shared_ptr &context); void RequestHandle2(const std::string command, std::multimap ¶msMap, - ResponseHandle responseHandle, void *context); - void DoNothing(std::multimap ¶msMap, ResponseHandle responseHandle, void *context); - void RequestGetProductInfo(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context); - void RequestGetDeviceAttr(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context); + const std::string &url, ResponseHandle responseHandle, void *context); + void DoNothing(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); + void RequestGetProductInfo(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); + void RequestGetDeviceAttr(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); void ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m); - void RequestGetMediaInfo(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context); + void RequestGetMediaInfo(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); void ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo ¶m); - void RequestGetSdCardInfo(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context); + void RequestGetSdCardInfo(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m); - void RequestUpload(std::multimap ¶msMap, ResponseHandle responseHandle, - void *context); + void RequestGetBatteryInfo(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); + void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m); + AppSetDateTime RequestSetDateTimeParse(const std::string &url); + void RequestSetDateTime(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); + void RequestUpload(std::multimap ¶msMap, const std::string &url, + ResponseHandle responseHandle, void *context); private: cJSON *MakeResponseResult(const ResposeResult result); diff --git a/test/middleware/AppManager/src/AppManager_Test.cpp b/test/middleware/AppManager/src/AppManager_Test.cpp index 2c42b0b7..6f714c1e 100644 --- a/test/middleware/AppManager/src/AppManager_Test.cpp +++ b/test/middleware/AppManager/src/AppManager_Test.cpp @@ -109,4 +109,28 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetSdCardInfo) std::this_thread::sleep_for(std::chrono::milliseconds(1000)); IAppManager::GetInstance()->UnInit(); } +// ../output_files/test/bin/AppManagerTest +// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetBatteryInfo +TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetBatteryInfo) +{ + std::shared_ptr monitor = AppManagerTestTool::MakeMonitorMock(); + IAppManager::GetInstance()->Init(mAppParam); + IAppManager::GetInstance()->SetAppMonitor(monitor); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MockGetBatteryInfo(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + IAppManager::GetInstance()->UnInit(); +} +// ../output_files/test/bin/AppManagerTest +// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime +TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime) +{ + std::shared_ptr monitor = AppManagerTestTool::MakeMonitorMock(); + IAppManager::GetInstance()->Init(mAppParam); + IAppManager::GetInstance()->SetAppMonitor(monitor); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MockSetDateTime(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + IAppManager::GetInstance()->UnInit(); +} } // namespace AppManagerTest \ No newline at end of file diff --git a/test/middleware/AppManager/tool/include/AppManagerTestTool.h b/test/middleware/AppManager/tool/include/AppManagerTestTool.h index bb4dd807..6b4af590 100644 --- a/test/middleware/AppManager/tool/include/AppManagerTestTool.h +++ b/test/middleware/AppManager/tool/include/AppManagerTestTool.h @@ -30,6 +30,8 @@ protected: void MockGetDeviceAttr(void); void MockGetMediaInfo(void); void MockGetSdCardInfo(void); + void MockGetBatteryInfo(void); + void MockSetDateTime(void); void MockUploadFiles(void); private: diff --git a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp index e461b560..29574081 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -75,6 +75,30 @@ void AppManagerTestTool::MockGetSdCardInfo(void) .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; + } + 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; + } + EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); + ServersMock::GetInstance()->MockSetDateTime(); +} void AppManagerTestTool::MockUploadFiles(void) { // @@ -107,6 +131,10 @@ std::shared_ptr AppManagerTestTool::MakeMonitorMock(void) .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)))); return monitor; diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp index 0600adfa..202f0331 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp @@ -70,6 +70,34 @@ StatusCode AppMonitorTest::GetSdCardInfoTrace(AppGetSdCardInfo ¶m) LogInfo("AppMonitorTest::GetSdCardInfoTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +StatusCode AppMonitorTest::GetBatteryInfo(AppGetBatteryInfo ¶m) +{ + LogInfo("AppMonitorTest::GetBatteryInfo\n"); + StatusCode code = GetBatteryInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return VAppMonitor::GetBatteryInfo(param); + } + return code; +} +StatusCode AppMonitorTest::GetBatteryInfoTrace(AppGetBatteryInfo ¶m) +{ + LogInfo("AppMonitorTest::GetBatteryInfoTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m) +{ + LogInfo("AppMonitorTest::SetDateTime\n"); + StatusCode code = SetDateTimeTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return VAppMonitor::SetDateTime(param); + } + return code; +} +StatusCode AppMonitorTest::SetDateTimeTrace(AppSetDateTime ¶m) +{ + LogInfo("AppMonitorTest::SetDateTimeTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m) { LogInfo("AppMonitorTest::UploadFile\n"); diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.h b/test/middleware/AppManager/tool/src/AppMonitorMock.h index 748fbaaf..136a7a0c 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.h +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.h @@ -25,6 +25,8 @@ public: 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 UploadFile(AppUploadFile ¶m) override; protected: @@ -32,6 +34,8 @@ protected: 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 UploadFileTrace(AppUploadFile ¶m); }; class AppMonitorMock : public AppMonitorTest @@ -43,6 +47,8 @@ public: MOCK_METHOD1(GetDeviceAttrTrace, StatusCode(AppGetDeviceAttr &)); MOCK_METHOD1(GetMediaInfoTrace, StatusCode(AppGetMeidaInfo &)); MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &)); + MOCK_METHOD1(GetBatteryInfoTrace, StatusCode(AppGetBatteryInfo &)); + MOCK_METHOD1(SetDateTimeTrace, StatusCode(AppSetDateTime &)); MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &)); }; #endif \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/ServersMock.cpp b/test/middleware/AppManager/tool/src/ServersMock.cpp index cfa49a16..91e82ee1 100644 --- a/test/middleware/AppManager/tool/src/ServersMock.cpp +++ b/test/middleware/AppManager/tool/src/ServersMock.cpp @@ -21,6 +21,8 @@ extern const char *APP_GET_DEVICE_ATTR; extern const char *APP_UPLOAD_FILE; extern const char *APP_GET_MEDIA_INFO; extern const char *APP_GET_SD_CARD_INFO; +extern const char *APP_GET_BATTERY_INFO; +extern const char *APP_SET_DATE_TIME; std::shared_ptr &ServersMock::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -120,6 +122,40 @@ void ServersMock::MockGetSdCardInfo(void) DeleteServersHttp(http); } } +void ServersMock::MockGetBatteryInfo(void) +{ + LogInfo("APP_GET_BATTERY_INFO test start.\n"); + std::string mockRequest = mServerUrl + APP_GET_BATTERY_INFO; + ServerHttp *http = NewServersHttp(mockRequest.c_str()); + if (http) { + HttpGet(http); + if (http->reply) { + char *replyStr = (char *)malloc(http->replyLength + 1); + memset(replyStr, 0, http->replyLength + 1); + memcpy(replyStr, http->reply, http->replyLength); + LogInfo("HttpGet response :\n%s\n", replyStr); + free(replyStr); + } + DeleteServersHttp(http); + } +} +void ServersMock::MockSetDateTime(void) +{ + LogInfo("APP_GET_BATTERY_INFO test start.\n"); + std::string mockRequest = mServerUrl + APP_SET_DATE_TIME + "?date=20240101010101"; + ServerHttp *http = NewServersHttp(mockRequest.c_str()); + if (http) { + HttpGet(http); + if (http->reply) { + char *replyStr = (char *)malloc(http->replyLength + 1); + memset(replyStr, 0, http->replyLength + 1); + memcpy(replyStr, http->reply, http->replyLength); + LogInfo("HttpGet response :\n%s\n", replyStr); + free(replyStr); + } + DeleteServersHttp(http); + } +} #ifndef PLATFORM_PATH #error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}") #endif diff --git a/test/middleware/AppManager/tool/src/ServersMock.h b/test/middleware/AppManager/tool/src/ServersMock.h index a94c5796..4bf7d4cb 100644 --- a/test/middleware/AppManager/tool/src/ServersMock.h +++ b/test/middleware/AppManager/tool/src/ServersMock.h @@ -27,6 +27,8 @@ public: virtual void MockGetDeviceAttr(void); virtual void MockGetMediaInfo(void); virtual void MockGetSdCardInfo(void); + virtual void MockGetBatteryInfo(void); + virtual void MockSetDateTime(void); virtual void MockUploadFiles(void); private: