Backup:test code.

This commit is contained in:
Fancy code 2024-03-04 17:39:19 -08:00
parent 0c4f039918
commit 50be3bf21b
12 changed files with 332 additions and 8 deletions

View File

@ -52,13 +52,15 @@ StatusCode MainThread::UnInit(void)
}
StatusCode MainThread::CreateAllModules(void)
{
// CreateLogModule();
// CreateHalModule();
CreateHalCppModule();
CreateMissionManagerModule();
return CreateStatusCode(STATUS_CODE_OK);
}
void MainThread::DestoryAllModules(void) {}
void MainThread::DestoryAllModules(void)
{
DestroyMissionManagerModule();
DestroyHalCppModule();
}
void MainThread::ResetAllPtrMaker(void) {}
void MainThread::Runing(void)
{

View File

@ -18,6 +18,7 @@
#include <functional>
#include <memory>
bool CreateMissionManagerModule(void);
bool DestroyMissionManagerModule(void);
enum class MissionEvent
{
TEST = 0,
@ -54,7 +55,7 @@ public:
IMissionManager() = default;
virtual ~IMissionManager() = default;
static std::shared_ptr<IMissionManager> &GetInstance(std::shared_ptr<IMissionManager> *impl = nullptr);
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
virtual const StatusCode Init(void);
virtual const StatusCode UnInit(void);
};
#endif

View File

@ -27,4 +27,6 @@ std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<I
}
}
return instance;
}
}
const StatusCode IMissionManager::Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
const StatusCode IMissionManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }

View File

@ -60,9 +60,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_LINUX_MOCK}")
# DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libgmock.a
# )
# add_subdirectory(test_utils)
add_subdirectory(all)
add_subdirectory(application)
add_subdirectory(middleware)
add_subdirectory(utils)
add_subdirectory(hal)
add_subdirectory(all)

View File

@ -0,0 +1,2 @@
add_subdirectory(HunttingCamera)

View File

@ -0,0 +1,75 @@
# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake)
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
include(${APPLICATION_SOURCE_PATH}/HunttingCamera/build/huntting_camera.cmake)
set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin)
include_directories(
./src
./tool/include
${HUNTTING_MAIN_INCLUDE_PATH}
${TEST_SOURCE_PATH}
${TEST_SOURCE_PATH}/utils/TestManager/include
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
)
link_directories(
${LIBS_OUTPUT_PATH}
${EXTERNAL_LIBS_OUTPUT_PATH}
)
aux_source_directory(. SRC_FILES_MAIN)
aux_source_directory(./src SRC_FILES)
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
aux_source_directory(./src_mock SRC_FILES)
endif()
set(TARGET_NAME HunttingCameraTest)
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
target_link_libraries(${TARGET_NAME} HunttingMainLib TestManager gtest gmock pthread)
if(${TEST_COVERAGE} MATCHES "true")
target_link_libraries(${TARGET_NAME} gcov)
endif()
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
add_custom_target(
HunttingCameraTest_code_check
COMMAND ${CLANG_TIDY_EXE}
-checks='${CLANG_TIDY_CHECKS}'
--header-filter=.*
--system-headers=false
${SRC_FILES}
${SRC_FILES_MAIN}
${CLANG_TIDY_CONFIG}
# --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]'
--line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]'
-p ${PLATFORM_PATH}/cmake-shell
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/application/HunttingCamera
)
add_custom_command(
TARGET ${TARGET_NAME}
PRE_BUILD
COMMAND make HunttingCameraTest_code_check
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
)
file(GLOB_RECURSE HEADER_FILES *.h)
add_custom_target(
HunttingCameraTest_code_format
COMMAND ${CLANG_FORMAT_EXE}
-style=file
-i ${SRC_FILES} ${SRC_FILES_MAIN} ${HEADER_FILES}
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/application/HunttingCamera
)
add_custom_command(
TARGET ${TARGET_NAME}
PRE_BUILD
COMMAND make HunttingCameraTest_code_check
COMMAND make HunttingCameraTest_code_format
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
)
endif()
define_file_name(${TARGET_NAME})
# add_subdirectory(tool)

View File

@ -0,0 +1,23 @@
/*
* 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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <thread>
#include <unistd.h>
int main(int argc, char *argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,59 @@
/*
* 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 "GtestUsing.h"
#include "ILog.h"
#include "MainThread.h"
#include "TestManager.h"
#include <thread>
namespace HunttingCameraTest
{
class HunttingCameraTest : public testing::Test, public TestManager
{
public:
HunttingCameraTest() {}
virtual ~HunttingCameraTest() {}
static void SetUpTestCase()
{
CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END);
}
static void TearDownTestCase() { ILogUnInit(); }
virtual void SetUp()
{
// CreateAllKeysMcok();
// HalTestTool::Init();
// HunttingCameraTestTool::Init();
// CreateHalCppModule();
// CreateDeviceManagerModule();
TestManager::Init();
}
virtual void TearDown()
{
// HalTestTool::UnInit();
// HunttingCameraTestTool::UnInit();
// DestroyDeviceManagerModule();
// DestroyAllKeysMock();
TestManager::UnInit();
}
};
// ../output_files/test/bin/HunttingCameraTest --gtest_filter=HunttingCameraTest.INTEGRATION_DeviceManager_EXAMPLE_Demo
TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
{
MainThread::GetInstance()->Init();
ResetTimeOut(1000 * 3);
MainThread::GetInstance()->Runing();
MainThread::GetInstance()->UnInit();
}
} // namespace HunttingCameraTest

View File

@ -7,5 +7,6 @@ add_subdirectory(UartDevice)
add_subdirectory(LinuxApiMock)
add_subdirectory(McuProtocol)
add_subdirectory(FxHttpServer)
add_subdirectory(TestManager)

View File

@ -0,0 +1,53 @@
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
${APPLICATION_SOURCE_PATH}/HunttingCamera/src
${UTILS_SOURCE_PATH}/Log/include
${UTILS_SOURCE_PATH}/StatusCode/include
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
)
# link_directories(
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
# )
aux_source_directory(./src SRC_FILES)
set(TARGET_NAME TestManager)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
target_link_libraries(${TARGET_NAME} LinuxApi gtest gmock Log)
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
add_custom_target(
TestManager_code_check
COMMAND ${CLANG_TIDY_EXE}
-checks='${CLANG_TIDY_CHECKS}'
--header-filter=.*
--system-headers=false
${SRC_FILES}
${CLANG_TIDY_CONFIG}
-p ${PLATFORM_PATH}/cmake-shell
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/TestManager
)
file(GLOB_RECURSE HEADER_FILES *.h)
add_custom_target(
TestManager_code_format
COMMAND ${CLANG_FORMAT_EXE}
-style=file
-i ${SRC_FILES} ${HEADER_FILES}
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/TestManager
)
add_custom_command(
TARGET ${TARGET_NAME}
PRE_BUILD
COMMAND make TestManager_code_check
COMMAND make TestManager_code_format
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
)
endif()
define_file_name(${TARGET_NAME})

View File

@ -0,0 +1,38 @@
/*
* 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 TEST_MANAGER_H
#define TEST_MANAGER_H
#include <mutex>
#include <thread>
class TestManager
{
public:
TestManager() = default;
virtual ~TestManager() = default;
void Init(void);
void UnInit(void);
void ResetTimeOut(const unsigned int &timeOutMs);
void StartTimer(void);
void StopTimer(void);
void Timer(void);
private:
std::mutex mMutex;
unsigned int mTimeOutMs;
unsigned int mSleepingTime;
bool mRuning;
std::thread mTimerThread;
};
#endif

View File

@ -0,0 +1,68 @@
/*
* 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 "TestManager.h"
#include "ILog.h"
#include "MainThread.h"
constexpr int TIMER_SLEEP_MS = 100;
void TestManager::Init(void)
{
mSleepingTime = 0;
mTimeOutMs = 0;
mRuning = false;
}
void TestManager::UnInit(void)
{
StopTimer();
if (mTimerThread.joinable()) {
mTimerThread.join();
}
}
void TestManager::ResetTimeOut(const unsigned int &timeOutMs)
{
//
mTimeOutMs = timeOutMs;
StartTimer();
}
void TestManager::StartTimer(void)
{
std::lock_guard<std::mutex> locker(mMutex);
if (mTimerThread.joinable()) {
LogInfo("Timer has started.\n");
return;
}
auto timerThread = [](TestManager *timer) {
//
timer->Timer();
};
mTimerThread = std::thread(timerThread, this);
}
void TestManager::StopTimer(void)
{
//
mRuning = false;
}
void TestManager::Timer(void)
{
mRuning = true;
while (mRuning) {
std::this_thread::sleep_for(std::chrono::milliseconds(TIMER_SLEEP_MS));
mSleepingTime += TIMER_SLEEP_MS;
if (mSleepingTime >= mTimeOutMs) {
LogInfo("Test time out.\n");
mRuning = false;
MainThread::GetInstance()->Exit();
}
}
}