Add:AppManager test code.
This commit is contained in:
parent
3fef82c7d4
commit
a73b84039a
|
@ -20,11 +20,42 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
bool CreateAppManagerModule(void);
|
bool CreateAppManagerModule(void);
|
||||||
bool DestroyAppManagerModule(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
|
class VAppMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VAppMonitor() = default;
|
VAppMonitor() = default;
|
||||||
virtual ~VAppMonitor() = default;
|
virtual ~VAppMonitor() = default;
|
||||||
|
virtual StatusCode GetProductInfo(AppGetProductInfo ¶m);
|
||||||
|
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
||||||
};
|
};
|
||||||
typedef struct app_param
|
typedef struct app_param
|
||||||
{
|
{
|
||||||
|
@ -40,5 +71,6 @@ public:
|
||||||
static std::shared_ptr<IAppManager> &GetInstance(std::shared_ptr<IAppManager> *impl = nullptr);
|
static std::shared_ptr<IAppManager> &GetInstance(std::shared_ptr<IAppManager> *impl = nullptr);
|
||||||
virtual const StatusCode Init(const AppParam ¶m);
|
virtual const StatusCode Init(const AppParam ¶m);
|
||||||
virtual const StatusCode UnInit(void);
|
virtual const StatusCode UnInit(void);
|
||||||
|
virtual const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -34,6 +34,11 @@ const StatusCode AppManager::UnInit(void)
|
||||||
mProtocolHandle.reset();
|
mProtocolHandle.reset();
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
const StatusCode AppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||||
|
{
|
||||||
|
mProtocolHandle->SetAppMonitor(monitor);
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||||
void *context)
|
void *context)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
virtual ~AppManager() = default;
|
virtual ~AppManager() = default;
|
||||||
const StatusCode Init(const AppParam ¶m) override;
|
const StatusCode Init(const AppParam ¶m) override;
|
||||||
const StatusCode UnInit(void) override;
|
const StatusCode UnInit(void) override;
|
||||||
|
const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||||
void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context);
|
void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
*/
|
*/
|
||||||
#include "IAppManager.h"
|
#include "IAppManager.h"
|
||||||
#include "ILog.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> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
|
std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<IAppManager>();
|
static auto instance = std::make_shared<IAppManager>();
|
||||||
|
@ -30,3 +36,7 @@ std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManag
|
||||||
}
|
}
|
||||||
const StatusCode IAppManager::Init(const AppParam ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
const StatusCode IAppManager::Init(const AppParam ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
const StatusCode IAppManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
const StatusCode IAppManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
const StatusCode IAppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
|
@ -14,8 +14,8 @@
|
||||||
*/
|
*/
|
||||||
#ifndef I_APP_PROTOCOL_HANDLE_H
|
#ifndef I_APP_PROTOCOL_HANDLE_H
|
||||||
#define I_APP_PROTOCOL_HANDLE_H
|
#define I_APP_PROTOCOL_HANDLE_H
|
||||||
#include "FxHttpServer.h"
|
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
|
#include "WebServer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -36,5 +36,6 @@ public:
|
||||||
void *context)
|
void *context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
virtual void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) {}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -21,9 +21,12 @@ using std::placeholders::_2;
|
||||||
using std::placeholders::_3;
|
using std::placeholders::_3;
|
||||||
// using std::placeholders::_4;
|
// using std::placeholders::_4;
|
||||||
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||||
|
const char *APP_UPLOAD_FILE = "/upload";
|
||||||
SixFrameHandle::SixFrameHandle()
|
SixFrameHandle::SixFrameHandle()
|
||||||
{
|
{
|
||||||
|
mAppMonitor = std::make_shared<VAppMonitor>();
|
||||||
mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3);
|
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);
|
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||||
|
@ -88,6 +91,21 @@ void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::strin
|
||||||
char *resultStr = nullptr;
|
char *resultStr = nullptr;
|
||||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||||
resultStr = cJSON_Print(result);
|
resultStr = cJSON_Print(result);
|
||||||
|
AppGetProductInfo info;
|
||||||
|
mAppMonitor->GetProductInfo(info);
|
||||||
|
responseHandle(resultStr, context);
|
||||||
|
free(resultStr);
|
||||||
|
cJSON_Delete(result);
|
||||||
|
}
|
||||||
|
void SixFrameHandle::RequestUpload(std::multimap<std::string, std::string> ¶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);
|
responseHandle(resultStr, context);
|
||||||
free(resultStr);
|
free(resultStr);
|
||||||
cJSON_Delete(result);
|
cJSON_Delete(result);
|
||||||
|
@ -99,3 +117,12 @@ cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result)
|
||||||
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result));
|
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result));
|
||||||
return resultCJSON;
|
return resultCJSON;
|
||||||
}
|
}
|
||||||
|
void SixFrameHandle::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||||
|
{
|
||||||
|
if (monitor) {
|
||||||
|
mAppMonitor = monitor;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("SetAppMonitor failed.\n");
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#ifndef SIX_FRAME_HANDLE_H
|
#ifndef SIX_FRAME_HANDLE_H
|
||||||
#define SIX_FRAME_HANDLE_H
|
#define SIX_FRAME_HANDLE_H
|
||||||
|
#include "IAppManager.h"
|
||||||
#include "IAppProtocolHandle.h"
|
#include "IAppProtocolHandle.h"
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
|
@ -23,12 +24,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using ResquesHandleFunc = std::function<void(std::multimap<std::string, std::string> &, ResponseHandle, void *)>;
|
using ResquesHandleFunc = std::function<void(std::multimap<std::string, std::string> &, ResponseHandle, void *)>;
|
||||||
enum class ResposeResult
|
|
||||||
{
|
|
||||||
SUCCESSFUL = 0,
|
|
||||||
FAILED,
|
|
||||||
END
|
|
||||||
};
|
|
||||||
class SixFrameHandle : public IAppProtocolHandle
|
class SixFrameHandle : public IAppProtocolHandle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -46,11 +41,17 @@ private:
|
||||||
void DoNothing(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle, void *context);
|
void DoNothing(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle, void *context);
|
||||||
void RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
||||||
void *context);
|
void *context);
|
||||||
|
void RequestUpload(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
||||||
|
void *context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cJSON *MakeResponseResult(const ResposeResult result);
|
cJSON *MakeResponseResult(const ResposeResult result);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, ResquesHandleFunc> mResquesHandleFunc;
|
std::map<std::string, ResquesHandleFunc> mResquesHandleFunc;
|
||||||
|
std::shared_ptr<VAppMonitor> mAppMonitor;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -45,4 +45,5 @@ using ::testing::SetArgumentPointee;
|
||||||
using ::testing::Unused;
|
using ::testing::Unused;
|
||||||
using ::testing::WithArgs;
|
using ::testing::WithArgs;
|
||||||
using ::testing::internal::BuiltInDefaultValue;
|
using ::testing::internal::BuiltInDefaultValue;
|
||||||
|
using ::testing::SetArgReferee;
|
||||||
#endif
|
#endif
|
|
@ -9,11 +9,8 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||||
${UTILS_SOURCE_PATH}/LedControl/include
|
${UTILS_SOURCE_PATH}/LedControl/include
|
||||||
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
|
||||||
${HAL_SOURCE_PATH}/src
|
${HAL_SOURCE_PATH}/src
|
||||||
# /home/xiaojiazhu/project/rkipc/battery/ipc-rk1106/ipc-sdk/hal/src/HalCpp.h
|
${TEST_SOURCE_PATH}
|
||||||
# ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
|
||||||
# ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
|
||||||
)
|
)
|
||||||
# link_directories(
|
# link_directories(
|
||||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||||
|
|
|
@ -14,40 +14,9 @@
|
||||||
*/
|
*/
|
||||||
#ifndef HAL_TEST_TOOL_H
|
#ifndef HAL_TEST_TOOL_H
|
||||||
#define HAL_TEST_TOOL_H
|
#define HAL_TEST_TOOL_H
|
||||||
|
#include "GtestUsing.h"
|
||||||
#include "IHalCpp.h"
|
#include "IHalCpp.h"
|
||||||
#include "LedControl.h"
|
#include "LedControl.h"
|
||||||
#include <gmock/gmock.h>
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
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
|
class HalTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -10,6 +10,7 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||||
${UTILS_SOURCE_PATH}/LedControl/include
|
${UTILS_SOURCE_PATH}/LedControl/include
|
||||||
|
${UTILS_SOURCE_PATH}/WebServer/include
|
||||||
${HAL_SOURCE_PATH}/include
|
${HAL_SOURCE_PATH}/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/src
|
${MIDDLEWARE_SOURCE_PATH}/AppManager/src
|
||||||
|
|
|
@ -55,7 +55,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo0)
|
||||||
{
|
{
|
||||||
IAppManager::GetInstance()->Init(mAppParam);
|
IAppManager::GetInstance()->Init(mAppParam);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
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();
|
IAppManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo
|
// ../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));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
IAppManager::GetInstance()->UnInit();
|
IAppManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo2
|
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_Upload
|
||||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo2)
|
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_Upload)
|
||||||
{
|
{
|
||||||
IAppManager::GetInstance()->Init(mAppParam);
|
IAppManager::GetInstance()->Init(mAppParam);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#ifndef APP_MANAGER_TEST_TOOL_H
|
#ifndef APP_MANAGER_TEST_TOOL_H
|
||||||
#define APP_MANAGER_TEST_TOOL_H
|
#define APP_MANAGER_TEST_TOOL_H
|
||||||
#include "GtestUsing.h"
|
#include "GtestUsing.h"
|
||||||
|
#include "IAppManager.h"
|
||||||
|
#include <memory>
|
||||||
class AppManagerTestTool
|
class AppManagerTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -26,5 +28,12 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void MockGetProductInfo(void);
|
void MockGetProductInfo(void);
|
||||||
void MockUploadFiles(void);
|
void MockUploadFiles(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void AppManagerMockInit(std::shared_ptr<IAppManager> &vMock);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<IAppManager> mAppManagerMock;
|
||||||
|
std::shared_ptr<VAppMonitor> mAppMonitorMock;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -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> &appManagerMock)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppManagerMakePtr> impl = std::make_shared<AppManagerMakePtrTest>();
|
||||||
|
std::shared_ptr<AppManagerMakePtrTest> test = std::dynamic_pointer_cast<AppManagerMakePtrTest>(impl);
|
||||||
|
if (test) {
|
||||||
|
test->mAppManagerMock = appManagerMock;
|
||||||
|
}
|
||||||
|
AppManagerMakePtr::GetInstance(&impl);
|
||||||
|
}
|
||||||
|
void CancelOverrideAppManagerMakePtrObject(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppManagerMakePtr> tmp = AppManagerMakePtr::GetInstance();
|
||||||
|
std::shared_ptr<AppManagerMakePtrTest> test = std::dynamic_pointer_cast<AppManagerMakePtrTest>(tmp);
|
||||||
|
if (test) {
|
||||||
|
test->mAppManagerMock.reset();
|
||||||
|
}
|
||||||
|
std::shared_ptr<AppManagerMakePtr> impl = std::make_shared<AppManagerMakePtrTest>();
|
||||||
|
AppManagerMakePtr::GetInstance(&impl);
|
||||||
|
}
|
||||||
|
AppManagerMakePtrTest::AppManagerMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
AppManagerMakePtrTest::~AppManagerMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
mAppManagerMock.reset();
|
||||||
|
}
|
||||||
|
const StatusCode AppManagerMakePtrTest::CreateAppManager(std::shared_ptr<IAppManager> &impl)
|
||||||
|
{
|
||||||
|
if (mAppManagerMock) {
|
||||||
|
LogInfo("CreateAppManager mAppManagerMock\n");
|
||||||
|
impl = mAppManagerMock;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("CreateMcuManager failed:mAppManagerMock is nullptr.\n");
|
||||||
|
}
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
32
test/middleware/AppManager/tool/src/AppManagerMakePtrTest.h
Normal file
32
test/middleware/AppManager/tool/src/AppManagerMakePtrTest.h
Normal file
|
@ -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> &appManagerMock);
|
||||||
|
void CancelOverrideAppManagerMakePtrObject(void);
|
||||||
|
class AppManagerMakePtrTest : public AppManagerMakePtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppManagerMakePtrTest();
|
||||||
|
virtual ~AppManagerMakePtrTest();
|
||||||
|
const StatusCode CreateAppManager(std::shared_ptr<IAppManager> &impl) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<AppManagerMock> mAppManagerMock;
|
||||||
|
};
|
||||||
|
#endif
|
40
test/middleware/AppManager/tool/src/AppManagerMock.cpp
Normal file
40
test/middleware/AppManager/tool/src/AppManagerMock.cpp
Normal file
|
@ -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<VAppMonitor> &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<VAppMonitor> &monitor)
|
||||||
|
{
|
||||||
|
LogInfo("AppManagerTest::SetAppMonitorTrace\n");
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
// StatusCode AppManagerTest::GetAllLedsTrace(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||||
|
// {
|
||||||
|
// LogInfo("AppManagerTest::GetAllLedsTrace\n");
|
||||||
|
// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
// }
|
||||||
|
// StatusCode AppManagerTest::GetAllKeysTrace(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||||
|
// {
|
||||||
|
// LogInfo("AppManagerTest::GetAllKeysTrace\n");
|
||||||
|
// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
// }
|
36
test/middleware/AppManager/tool/src/AppManagerMock.h
Normal file
36
test/middleware/AppManager/tool/src/AppManagerMock.h
Normal file
|
@ -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<VAppMonitor> &monitor) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const StatusCode SetAppMonitorTrace(std::shared_ptr<VAppMonitor> &monitor);
|
||||||
|
};
|
||||||
|
class AppManagerMock : public AppManagerTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppManagerMock() = default;
|
||||||
|
virtual ~AppManagerMock() = default;
|
||||||
|
MOCK_METHOD1(SetAppMonitorTrace, const StatusCode(std::shared_ptr<VAppMonitor> &));
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -13,14 +13,23 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "AppManagerTestTool.h"
|
#include "AppManagerTestTool.h"
|
||||||
|
#include "AppManagerMakePtrTest.h"
|
||||||
|
#include "AppManagerMock.h"
|
||||||
|
#include "AppMonitorMock.h"
|
||||||
|
#include "ILog.h"
|
||||||
#include "ServersMock.h"
|
#include "ServersMock.h"
|
||||||
void AppManagerTestTool::Init(void)
|
void AppManagerTestTool::Init(void)
|
||||||
{
|
{
|
||||||
//
|
mAppManagerMock = std::make_shared<AppManagerMock>();
|
||||||
|
AppManagerMockInit(mAppManagerMock);
|
||||||
|
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(mAppManagerMock);
|
||||||
|
OverrideAppManagerMakePtrObject(mock);
|
||||||
}
|
}
|
||||||
void AppManagerTestTool::UnInit(void)
|
void AppManagerTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
//
|
mAppManagerMock.reset();
|
||||||
|
mAppMonitorMock.reset();
|
||||||
|
CancelOverrideAppManagerMakePtrObject();
|
||||||
}
|
}
|
||||||
void AppManagerTestTool::MockGetProductInfo(void)
|
void AppManagerTestTool::MockGetProductInfo(void)
|
||||||
{
|
{
|
||||||
|
@ -32,3 +41,19 @@ void AppManagerTestTool::MockUploadFiles(void)
|
||||||
//
|
//
|
||||||
ServersMock::GetInstance()->MockUploadFiles();
|
ServersMock::GetInstance()->MockUploadFiles();
|
||||||
}
|
}
|
||||||
|
void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(vMock);
|
||||||
|
if (!mock) {
|
||||||
|
LogError("vMock error.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto getAppMonitor = [=](std::shared_ptr<VAppMonitor> &monitor) {
|
||||||
|
LogInfo("mAppMonitorMock get.\n");
|
||||||
|
mAppMonitorMock = std::dynamic_pointer_cast<AppMonitorMock>(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))));
|
||||||
|
}
|
44
test/middleware/AppManager/tool/src/AppMonitorMock.cpp
Normal file
44
test/middleware/AppManager/tool/src/AppMonitorMock.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
39
test/middleware/AppManager/tool/src/AppMonitorMock.h
Normal file
39
test/middleware/AppManager/tool/src/AppMonitorMock.h
Normal file
|
@ -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
|
|
@ -59,7 +59,7 @@ void ServersMock::MockGetProductInfo(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef PLATFORM_PATH
|
#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
|
#endif
|
||||||
void ServersMock::MockUploadFiles(void)
|
void ServersMock::MockUploadFiles(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,20 +8,13 @@ include_directories(
|
||||||
./tool/include
|
./tool/include
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
# ${UTILS_SOURCE_PATH}/UartDevice/include
|
|
||||||
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
|
||||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||||
${UTILS_SOURCE_PATH}/LedControl/include
|
${UTILS_SOURCE_PATH}/LedControl/include
|
||||||
${HAL_SOURCE_PATH}/include
|
${HAL_SOURCE_PATH}/include
|
||||||
# ${HAL_SOURCE_PATH}/src
|
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
||||||
# ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
${TEST_SOURCE_PATH}
|
||||||
# ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
|
||||||
${TEST_SOURCE_PATH}/hal/tool/include
|
${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/googletest/include
|
||||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,6 +13,7 @@ include_directories(
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||||
|
${TEST_SOURCE_PATH}
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
||||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
|
|
|
@ -27,22 +27,27 @@ static void sigHandler(int signo)
|
||||||
static void CheckUploadDir(void)
|
static void CheckUploadDir(void)
|
||||||
{
|
{
|
||||||
const char *directory = GOAHEAD_UPLOAD_TMP_PATH;
|
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) {
|
if (result == 0) {
|
||||||
LogInfo("mkdir upload tmp path successfuly.\n");
|
LogInfo("mkdir upload tmp path successfuly.\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("mkdir upload tmp path failed.\n");
|
LogError("mkdir upload tmp path failed.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *directory2 = GOAHEAD_UPLOAD_PATH;
|
const char *directory2 = GOAHEAD_UPLOAD_PATH;
|
||||||
result = mkdir(directory2, 0777);
|
if (access(directory2, F_OK) != 0) {
|
||||||
|
int result = mkdir(directory2, 0777);
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
LogInfo("mkdir upload path successfuly.\n");
|
LogInfo("mkdir upload path successfuly.\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("mkdir upload path failed.\n");
|
LogError("mkdir upload path failed.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void logHeader(void)
|
static void logHeader(void)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user