diff --git a/middleware/AppManager/include/IAppManager.h b/middleware/AppManager/include/IAppManager.h index 187ef988..b6a41259 100644 --- a/middleware/AppManager/include/IAppManager.h +++ b/middleware/AppManager/include/IAppManager.h @@ -20,11 +20,42 @@ #include bool CreateAppManagerModule(void); bool DestroyAppManagerModule(void); +enum class ResposeResult +{ + SUCCESSFUL = 0, + FAILED, + END +}; +enum class UploadCommand +{ + UPGRADE_CPU = 0, + END +}; +typedef struct app_get_product_info +{ + app_get_product_info() {} + std::string mModel; + std::string mCompany; + std::string mSoc; + std::string mSp; +} AppGetProductInfo; +typedef struct app_upload_file +{ + app_upload_file(const std::string filePath, const UploadCommand command) : mFilePath(filePath), mCommand(command) + { + mResult = ResposeResult::END; + } + const std::string mFilePath; + const UploadCommand mCommand; + ResposeResult mResult; +} AppUploadFile; class VAppMonitor { public: VAppMonitor() = default; virtual ~VAppMonitor() = default; + virtual StatusCode GetProductInfo(AppGetProductInfo ¶m); + virtual StatusCode UploadFile(AppUploadFile ¶m); }; typedef struct app_param { @@ -40,5 +71,6 @@ public: static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual const StatusCode Init(const AppParam ¶m); virtual const StatusCode UnInit(void); + virtual const StatusCode SetAppMonitor(std::shared_ptr &monitor); }; #endif \ No newline at end of file diff --git a/middleware/AppManager/src/AppManager.cpp b/middleware/AppManager/src/AppManager.cpp index e0b388b4..caed3909 100644 --- a/middleware/AppManager/src/AppManager.cpp +++ b/middleware/AppManager/src/AppManager.cpp @@ -34,6 +34,11 @@ const StatusCode AppManager::UnInit(void) mProtocolHandle.reset(); return CreateStatusCode(STATUS_CODE_OK); } +const StatusCode AppManager::SetAppMonitor(std::shared_ptr &monitor) +{ + mProtocolHandle->SetAppMonitor(monitor); + 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 d9542cb0..fa3e3dbf 100644 --- a/middleware/AppManager/src/AppManager.h +++ b/middleware/AppManager/src/AppManager.h @@ -24,6 +24,7 @@ public: virtual ~AppManager() = default; const StatusCode Init(const AppParam ¶m) override; const StatusCode UnInit(void) override; + const StatusCode SetAppMonitor(std::shared_ptr &monitor) override; void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context); private: diff --git a/middleware/AppManager/src/IAppManager.cpp b/middleware/AppManager/src/IAppManager.cpp index d9cfcd93..1734d357 100644 --- a/middleware/AppManager/src/IAppManager.cpp +++ b/middleware/AppManager/src/IAppManager.cpp @@ -14,6 +14,12 @@ */ #include "IAppManager.h" #include "ILog.h" + +StatusCode VAppMonitor::GetProductInfo(AppGetProductInfo ¶m) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } std::shared_ptr &IAppManager::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -29,4 +35,8 @@ std::shared_ptr &IAppManager::GetInstance(std::shared_ptr &monitor) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} \ No newline at end of file diff --git a/middleware/AppManager/src/IAppProtocolHandle.h b/middleware/AppManager/src/IAppProtocolHandle.h index 6d48e5bf..575ff52c 100644 --- a/middleware/AppManager/src/IAppProtocolHandle.h +++ b/middleware/AppManager/src/IAppProtocolHandle.h @@ -14,8 +14,8 @@ */ #ifndef I_APP_PROTOCOL_HANDLE_H #define I_APP_PROTOCOL_HANDLE_H -#include "FxHttpServer.h" #include "StatusCode.h" +#include "WebServer.h" #include #include #include @@ -36,5 +36,6 @@ public: void *context) { } + virtual void SetAppMonitor(std::shared_ptr &monitor) {} }; #endif \ No newline at end of file diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp index a136af77..54856027 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp @@ -21,9 +21,12 @@ using std::placeholders::_2; using std::placeholders::_3; // using std::placeholders::_4; const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo"; +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_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3); // mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3); } void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, @@ -88,6 +91,21 @@ void SixFrameHandle::RequestGetProductInfo(std::multimapGetProductInfo(info); + responseHandle(resultStr, context); + free(resultStr); + cJSON_Delete(result); +} +void SixFrameHandle::RequestUpload(std::multimap ¶msMap, ResponseHandle responseHandle, + void *context) +{ + LogInfo("RequestUpload.\n"); + char *resultStr = nullptr; + AppUploadFile info("path", UploadCommand::UPGRADE_CPU); + mAppMonitor->UploadFile(info); + cJSON *result = MakeResponseResult(info.mResult); + resultStr = cJSON_Print(result); responseHandle(resultStr, context); free(resultStr); cJSON_Delete(result); @@ -98,4 +116,13 @@ cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result) cJSON *resultCJSON = cJSON_CreateObject(); cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast(result)); return resultCJSON; +} +void SixFrameHandle::SetAppMonitor(std::shared_ptr &monitor) +{ + if (monitor) { + mAppMonitor = monitor; + } + else { + LogError("SetAppMonitor failed.\n"); + } } \ No newline at end of file diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h index 5a8902bc..36e9e76a 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h @@ -14,6 +14,7 @@ */ #ifndef SIX_FRAME_HANDLE_H #define SIX_FRAME_HANDLE_H +#include "IAppManager.h" #include "IAppProtocolHandle.h" #include "StatusCode.h" #include @@ -23,12 +24,6 @@ #include #include using ResquesHandleFunc = std::function &, ResponseHandle, void *)>; -enum class ResposeResult -{ - SUCCESSFUL = 0, - FAILED, - END -}; class SixFrameHandle : public IAppProtocolHandle { public: @@ -46,11 +41,17 @@ private: void DoNothing(std::multimap ¶msMap, ResponseHandle responseHandle, void *context); void RequestGetProductInfo(std::multimap ¶msMap, ResponseHandle responseHandle, void *context); + void RequestUpload(std::multimap ¶msMap, ResponseHandle responseHandle, + void *context); private: cJSON *MakeResponseResult(const ResposeResult result); +protected: + void SetAppMonitor(std::shared_ptr &monitor) override; + private: std::map mResquesHandleFunc; + std::shared_ptr mAppMonitor; }; #endif \ No newline at end of file diff --git a/test/GtestUsing.h b/test/GtestUsing.h index 7cfd887f..01764ec4 100644 --- a/test/GtestUsing.h +++ b/test/GtestUsing.h @@ -45,4 +45,5 @@ using ::testing::SetArgumentPointee; using ::testing::Unused; using ::testing::WithArgs; using ::testing::internal::BuiltInDefaultValue; +using ::testing::SetArgReferee; #endif \ No newline at end of file diff --git a/test/hal/tool/CMakeLists.txt b/test/hal/tool/CMakeLists.txt index 942fc820..67b4a2fa 100644 --- a/test/hal/tool/CMakeLists.txt +++ b/test/hal/tool/CMakeLists.txt @@ -9,11 +9,8 @@ include_directories( ${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/KeyControl/include ${UTILS_SOURCE_PATH}/LedControl/include - # ${UTILS_SOURCE_PATH}/McuProtocol/include ${HAL_SOURCE_PATH}/src - # /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/hal/src/HalCpp.h - # ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include - # ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include + ${TEST_SOURCE_PATH} ) # link_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs diff --git a/test/hal/tool/include/HalTestTool.h b/test/hal/tool/include/HalTestTool.h index 0aa46cd1..61b22d3b 100644 --- a/test/hal/tool/include/HalTestTool.h +++ b/test/hal/tool/include/HalTestTool.h @@ -14,40 +14,9 @@ */ #ifndef HAL_TEST_TOOL_H #define HAL_TEST_TOOL_H +#include "GtestUsing.h" #include "IHalCpp.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::SetArgReferee; -using ::testing::SetArgumentPointee; -using ::testing::Unused; -using ::testing::WithArgs; -using ::testing::internal::BuiltInDefaultValue; class HalTestTool { public: diff --git a/test/middleware/AppManager/CMakeLists.txt b/test/middleware/AppManager/CMakeLists.txt index cb89bc49..928eeada 100644 --- a/test/middleware/AppManager/CMakeLists.txt +++ b/test/middleware/AppManager/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( ${UTILS_SOURCE_PATH}/StatusCode/include ${UTILS_SOURCE_PATH}/KeyControl/include ${UTILS_SOURCE_PATH}/LedControl/include + ${UTILS_SOURCE_PATH}/WebServer/include ${HAL_SOURCE_PATH}/include ${MIDDLEWARE_SOURCE_PATH}/AppManager/include ${MIDDLEWARE_SOURCE_PATH}/AppManager/src diff --git a/test/middleware/AppManager/src/AppManager_Test.cpp b/test/middleware/AppManager/src/AppManager_Test.cpp index 32e3e52f..79e83117 100644 --- a/test/middleware/AppManager/src/AppManager_Test.cpp +++ b/test/middleware/AppManager/src/AppManager_Test.cpp @@ -55,7 +55,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo0) { IAppManager::GetInstance()->Init(mAppParam); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::this_thread::sleep_for(std::chrono::milliseconds(200000)); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); IAppManager::GetInstance()->UnInit(); } // ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo @@ -67,8 +67,8 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo) std::this_thread::sleep_for(std::chrono::milliseconds(1000)); IAppManager::GetInstance()->UnInit(); } -// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo2 -TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo2) +// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_Upload +TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_Upload) { IAppManager::GetInstance()->Init(mAppParam); std::this_thread::sleep_for(std::chrono::milliseconds(100)); diff --git a/test/middleware/AppManager/tool/include/AppManagerTestTool.h b/test/middleware/AppManager/tool/include/AppManagerTestTool.h index 4ac14234..22edadbd 100644 --- a/test/middleware/AppManager/tool/include/AppManagerTestTool.h +++ b/test/middleware/AppManager/tool/include/AppManagerTestTool.h @@ -15,6 +15,8 @@ #ifndef APP_MANAGER_TEST_TOOL_H #define APP_MANAGER_TEST_TOOL_H #include "GtestUsing.h" +#include "IAppManager.h" +#include class AppManagerTestTool { public: @@ -26,5 +28,12 @@ public: protected: void MockGetProductInfo(void); void MockUploadFiles(void); + +private: + void AppManagerMockInit(std::shared_ptr &vMock); + +private: + std::shared_ptr mAppManagerMock; + std::shared_ptr mAppMonitorMock; }; #endif \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.cpp b/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.cpp new file mode 100644 index 00000000..db0c83dd --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.cpp @@ -0,0 +1,55 @@ +/* + * 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 "AppManagerMakePtrTest.h" +#include "ILog.h" +void OverrideAppManagerMakePtrObject(std::shared_ptr &appManagerMock) +{ + std::shared_ptr impl = std::make_shared(); + std::shared_ptr test = std::dynamic_pointer_cast(impl); + if (test) { + test->mAppManagerMock = appManagerMock; + } + AppManagerMakePtr::GetInstance(&impl); +} +void CancelOverrideAppManagerMakePtrObject(void) +{ + std::shared_ptr tmp = AppManagerMakePtr::GetInstance(); + std::shared_ptr test = std::dynamic_pointer_cast(tmp); + if (test) { + test->mAppManagerMock.reset(); + } + std::shared_ptr impl = std::make_shared(); + AppManagerMakePtr::GetInstance(&impl); +} +AppManagerMakePtrTest::AppManagerMakePtrTest() +{ + // +} +AppManagerMakePtrTest::~AppManagerMakePtrTest() +{ + // + mAppManagerMock.reset(); +} +const StatusCode AppManagerMakePtrTest::CreateAppManager(std::shared_ptr &impl) +{ + if (mAppManagerMock) { + LogInfo("CreateAppManager mAppManagerMock\n"); + impl = mAppManagerMock; + } + else { + LogWarning("CreateMcuManager failed:mAppManagerMock is nullptr.\n"); + } + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.h b/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.h new file mode 100644 index 00000000..cd49153a --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppManagerMakePtrTest.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef APP_MANAGER_MAKE_PTR_TEST_H +#define APP_MANAGER_MAKE_PTR_TEST_H +#include "AppManagerMakePtr.h" +#include "AppManagerMock.h" +#include "AppManagerTestTool.h" +void OverrideAppManagerMakePtrObject(std::shared_ptr &appManagerMock); +void CancelOverrideAppManagerMakePtrObject(void); +class AppManagerMakePtrTest : public AppManagerMakePtr +{ +public: + AppManagerMakePtrTest(); + virtual ~AppManagerMakePtrTest(); + const StatusCode CreateAppManager(std::shared_ptr &impl) override; + +public: + std::shared_ptr mAppManagerMock; +}; +#endif \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerMock.cpp b/test/middleware/AppManager/tool/src/AppManagerMock.cpp new file mode 100644 index 00000000..07445b07 --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppManagerMock.cpp @@ -0,0 +1,40 @@ +/* + * 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 "AppManagerMock.h" +#include "ILog.h" +const StatusCode AppManagerTest::SetAppMonitor(std::shared_ptr &monitor) +{ + LogInfo("AppManagerTest::GetAllLeds\n"); + StatusCode code = SetAppMonitorTrace(monitor); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return AppManager::SetAppMonitor(monitor); + } + return code; +} +const StatusCode AppManagerTest::SetAppMonitorTrace(std::shared_ptr &monitor) +{ + LogInfo("AppManagerTest::SetAppMonitorTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +// StatusCode AppManagerTest::GetAllLedsTrace(std::map> &allLeds) +// { +// LogInfo("AppManagerTest::GetAllLedsTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode AppManagerTest::GetAllKeysTrace(std::map> &allKeys) +// { +// LogInfo("AppManagerTest::GetAllKeysTrace\n"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerMock.h b/test/middleware/AppManager/tool/src/AppManagerMock.h new file mode 100644 index 00000000..03313190 --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppManagerMock.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef APP_MANAGER_MOCK_H +#define APP_MANAGER_MOCK_H +#include "AppManager.h" +#include "AppManagerTestTool.h" +class AppManagerTest : public AppManager +{ +public: + AppManagerTest() = default; + virtual ~AppManagerTest() = default; + const StatusCode SetAppMonitor(std::shared_ptr &monitor) override; + +protected: + virtual const StatusCode SetAppMonitorTrace(std::shared_ptr &monitor); +}; +class AppManagerMock : public AppManagerTest +{ +public: + AppManagerMock() = default; + virtual ~AppManagerMock() = 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 d3d7fff1..8eebfc95 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -13,14 +13,23 @@ * limitations under the License. */ #include "AppManagerTestTool.h" +#include "AppManagerMakePtrTest.h" +#include "AppManagerMock.h" +#include "AppMonitorMock.h" +#include "ILog.h" #include "ServersMock.h" void AppManagerTestTool::Init(void) { - // + mAppManagerMock = std::make_shared(); + AppManagerMockInit(mAppManagerMock); + std::shared_ptr mock = std::dynamic_pointer_cast(mAppManagerMock); + OverrideAppManagerMakePtrObject(mock); } void AppManagerTestTool::UnInit(void) { - // + mAppManagerMock.reset(); + mAppMonitorMock.reset(); + CancelOverrideAppManagerMakePtrObject(); } void AppManagerTestTool::MockGetProductInfo(void) { @@ -31,4 +40,20 @@ void AppManagerTestTool::MockUploadFiles(void) { // ServersMock::GetInstance()->MockUploadFiles(); +} +void AppManagerTestTool::AppManagerMockInit(std::shared_ptr &vMock) +{ + std::shared_ptr mock = std::dynamic_pointer_cast(vMock); + if (!mock) { + LogError("vMock error.\n"); + return; + } + auto getAppMonitor = [=](std::shared_ptr &monitor) { + LogInfo("mAppMonitorMock get.\n"); + mAppMonitorMock = std::dynamic_pointer_cast(monitor); + }; + constexpr int ONLY_BE_CALLED_ONCE = 1; + EXPECT_CALL(*mock.get(), SetAppMonitorTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(WithArgs<0>(Invoke(getAppMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp new file mode 100644 index 00000000..07cbc0c0 --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp @@ -0,0 +1,44 @@ +/* + * 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 "AppMonitorMock.h" +#include "ILog.h" +StatusCode AppMonitorTest::GetProductInfo(AppGetProductInfo ¶m) +{ + LogInfo("AppMonitorTest::GetProductInfo\n"); + StatusCode code = GetProductInfoTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return VAppMonitor::GetProductInfo(param); + } + return code; +} +StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m) +{ + LogInfo("AppMonitorTest::UploadFile\n"); + StatusCode code = UploadFileTrace(param); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return VAppMonitor::UploadFile(param); + } + return code; +} +StatusCode AppMonitorTest::GetProductInfoTrace(AppGetProductInfo ¶m) +{ + LogInfo("AppMonitorTest::GetProductInfoTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode AppMonitorTest::UploadFileTrace(AppUploadFile ¶m) +{ + LogInfo("AppMonitorTest::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 new file mode 100644 index 00000000..669070f4 --- /dev/null +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.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 APP_MONITOR_MOCK_H +#define APP_MONITOR_MOCK_H +#include "GtestUsing.h" +#include "IAppManager.h" +class AppMonitorTest : public VAppMonitor +{ +public: + AppMonitorTest() = default; + virtual ~AppMonitorTest() = default; + StatusCode GetProductInfo(AppGetProductInfo ¶m) override; + StatusCode UploadFile(AppUploadFile ¶m) override; + +protected: + virtual StatusCode GetProductInfoTrace(AppGetProductInfo ¶m); + virtual StatusCode UploadFileTrace(AppUploadFile ¶m); +}; +class AppMonitorMock : public AppMonitorTest +{ +public: + AppMonitorMock() = default; + virtual ~AppMonitorMock() = default; + MOCK_METHOD1(GetProductInfoTrace, StatusCode(AppGetProductInfo &)); + 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 fb842d49..44866330 100644 --- a/test/middleware/AppManager/tool/src/ServersMock.cpp +++ b/test/middleware/AppManager/tool/src/ServersMock.cpp @@ -59,7 +59,7 @@ void ServersMock::MockGetProductInfo(void) } } #ifndef PLATFORM_PATH -#error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}") + #error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}") #endif void ServersMock::MockUploadFiles(void) { diff --git a/test/middleware/DeviceManager/CMakeLists.txt b/test/middleware/DeviceManager/CMakeLists.txt index 560518de..1467f2a1 100644 --- a/test/middleware/DeviceManager/CMakeLists.txt +++ b/test/middleware/DeviceManager/CMakeLists.txt @@ -8,20 +8,13 @@ include_directories( ./tool/include ${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/StatusCode/include - # ${UTILS_SOURCE_PATH}/UartDevice/include - # ${UTILS_SOURCE_PATH}/McuProtocol/include ${UTILS_SOURCE_PATH}/KeyControl/include ${UTILS_SOURCE_PATH}/LedControl/include ${HAL_SOURCE_PATH}/include - # ${HAL_SOURCE_PATH}/src ${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include ${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src - # ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include - # ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/hal/tool/include - # ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include - # ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include - # ${TEST_SOURCE_PATH}/middleware/McuAskBase/tool/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include ) diff --git a/test/middleware/McuManager/CMakeLists.txt b/test/middleware/McuManager/CMakeLists.txt index e9622631..e6a860d4 100644 --- a/test/middleware/McuManager/CMakeLists.txt +++ b/test/middleware/McuManager/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( ${MIDDLEWARE_SOURCE_PATH}/McuManager/include ${MIDDLEWARE_SOURCE_PATH}/McuManager/src ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include + ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include diff --git a/utils/WebServer/src/WebServer.cpp b/utils/WebServer/src/WebServer.cpp index 6aa3cde4..85f85bf9 100644 --- a/utils/WebServer/src/WebServer.cpp +++ b/utils/WebServer/src/WebServer.cpp @@ -27,22 +27,27 @@ static void sigHandler(int signo) static void CheckUploadDir(void) { const char *directory = GOAHEAD_UPLOAD_TMP_PATH; - int result = mkdir(directory, 0777); + if (access(directory, F_OK) != 0) { + int result = mkdir(directory, 0777); - if (result == 0) { - LogInfo("mkdir upload tmp path successfuly.\n"); - } - else { - LogError("mkdir upload tmp path failed.\n"); + if (result == 0) { + LogInfo("mkdir upload tmp path successfuly.\n"); + } + else { + LogError("mkdir upload tmp path failed.\n"); + } } + const char *directory2 = GOAHEAD_UPLOAD_PATH; - result = mkdir(directory2, 0777); + if (access(directory2, F_OK) != 0) { + int result = mkdir(directory2, 0777); - if (result == 0) { - LogInfo("mkdir upload path successfuly.\n"); - } - else { - LogError("mkdir upload path failed.\n"); + if (result == 0) { + LogInfo("mkdir upload path successfuly.\n"); + } + else { + LogError("mkdir upload path failed.\n"); + } } } static void logHeader(void)