mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Backup:AppManager test code.
This commit is contained in:
parent
a73b84039a
commit
6d23741b77
|
@ -15,10 +15,10 @@
|
|||
#include "AppManagerMakePtr.h"
|
||||
#include "AppManager.h"
|
||||
#include "ILog.h"
|
||||
extern bool CreateProtocolHandleImpl();
|
||||
// extern bool CreateProtocolHandleImpl();
|
||||
bool CreateAppManagerModule(void)
|
||||
{
|
||||
CreateProtocolHandleImpl(); // TODO: not good for gtest.
|
||||
// CreateProtocolHandleImpl(); // TODO: not good for gtest.
|
||||
auto instance = std::make_shared<IAppManager>();
|
||||
StatusCode code = AppManagerMakePtr::GetInstance()->CreateAppManager(instance);
|
||||
if (IsCodeOK(code)) {
|
||||
|
|
|
@ -45,7 +45,7 @@ endif()
|
|||
|
||||
set(TARGET_NAME AppManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} AppManager AppManagerTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} AppManagerTestTool gtest gmock pthread)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -33,18 +33,13 @@ public:
|
|||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
virtual void SetUp()
|
||||
{
|
||||
// CreateAllKeysMcok();
|
||||
// HalTestTool::Init();
|
||||
// AppManagerTestTool::Init();
|
||||
// CreateHalCppModule();
|
||||
AppManagerTestTool::Init();
|
||||
CreateAppManagerModule();
|
||||
}
|
||||
virtual void TearDown()
|
||||
{
|
||||
// HalTestTool::UnInit();
|
||||
// AppManagerTestTool::UnInit();
|
||||
AppManagerTestTool::UnInit();
|
||||
DestroyAppManagerModule();
|
||||
// DestroyAllKeysMock();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -70,7 +65,9 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo)
|
|||
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_Upload
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_Upload)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockUploadFiles();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
|
|
|
@ -9,6 +9,7 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/Servers/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/src
|
||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/src/Protocol/SixFrame
|
||||
${TEST_SOURCE_PATH}
|
||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||
|
@ -32,7 +33,7 @@ add_definitions(-DAPP_MANAGER_HTTP_SERVER_PORT=${APP_MANAGER_HTTP_SERVER_PORT})
|
|||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||
set(TEST_TOOL_TARGET AppManagerTestTool)
|
||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||
target_link_libraries(${TEST_TOOL_TARGET} Servers Log)
|
||||
target_link_libraries(${TEST_TOOL_TARGET} AppManager Servers Log)
|
||||
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
|
|
|
@ -35,5 +35,9 @@ private:
|
|||
private:
|
||||
std::shared_ptr<IAppManager> mAppManagerMock;
|
||||
std::shared_ptr<VAppMonitor> mAppMonitorMock;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<VAppMonitor> MakeMonitorMock(void);
|
||||
void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
|
||||
};
|
||||
#endif
|
|
@ -30,6 +30,8 @@ void CancelOverrideAppManagerMakePtrObject(void)
|
|||
if (test) {
|
||||
test->mAppManagerMock.reset();
|
||||
}
|
||||
tmp.reset();
|
||||
test.reset();
|
||||
std::shared_ptr<AppManagerMakePtr> impl = std::make_shared<AppManagerMakePtrTest>();
|
||||
AppManagerMakePtr::GetInstance(&impl);
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
*/
|
||||
#ifndef APP_MANAGER_MAKE_PTR_TEST_H
|
||||
#define APP_MANAGER_MAKE_PTR_TEST_H
|
||||
#include "AppManagerMakePtr.h"
|
||||
#include "AppManagerMock.h"
|
||||
#include "AppManagerTestTool.h"
|
||||
#include "SixFrameMakePtr.h"
|
||||
void OverrideAppManagerMakePtrObject(std::shared_ptr<AppManagerMock> &appManagerMock);
|
||||
void CancelOverrideAppManagerMakePtrObject(void);
|
||||
class AppManagerMakePtrTest : public AppManagerMakePtr
|
||||
class AppManagerMakePtrTest : public SixFrameMakePtr
|
||||
{
|
||||
public:
|
||||
AppManagerMakePtrTest();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "ILog.h"
|
||||
const StatusCode AppManagerTest::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
LogInfo("AppManagerTest::GetAllLeds\n");
|
||||
LogInfo("AppManagerTest::SetAppMonitor\n");
|
||||
StatusCode code = SetAppMonitorTrace(monitor);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppManager::SetAppMonitor(monitor);
|
||||
|
|
|
@ -51,9 +51,27 @@ void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
|
|||
auto getAppMonitor = [=](std::shared_ptr<VAppMonitor> &monitor) {
|
||||
LogInfo("mAppMonitorMock get.\n");
|
||||
mAppMonitorMock = std::dynamic_pointer_cast<AppMonitorMock>(monitor);
|
||||
AppManagerTestTool::AppMonitorInit(mAppMonitorMock);
|
||||
};
|
||||
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))));
|
||||
}
|
||||
std::shared_ptr<VAppMonitor> AppManagerTestTool::MakeMonitorMock(void)
|
||||
{
|
||||
auto monitor = std::make_shared<AppMonitorMock>();
|
||||
EXPECT_CALL(*monitor.get(), GetProductInfoTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*monitor.get(), UploadFileTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
return monitor;
|
||||
}
|
||||
void AppManagerTestTool::AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(vMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), UploadFileTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@ void ServersMock::MockUploadFiles(void)
|
|||
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
||||
if (http) {
|
||||
http->filePath = (char *)PLATFORM_PATH "/output_files/test/bin/AppManagerTest";
|
||||
LogInfo("http post file:%s\n", http->filePath);
|
||||
HttpPostFile(http);
|
||||
if (http->reply) {
|
||||
char *replyStr = (char *)malloc(http->replyLength + 1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user