Ipc config test.
This commit is contained in:
parent
523a6b8b99
commit
395f30e076
|
@ -27,7 +27,7 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME IpcConfig)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} ReturnCode Log)
|
||||
target_link_libraries(${TARGET_NAME} Config StatusCode Log)
|
||||
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef IPCCONFIG_H
|
||||
#define IPCCONFIG_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
enum class IpcConfigKey
|
||||
{
|
||||
TEST_NUM = 0,
|
||||
END
|
||||
};
|
||||
class IpcConfig
|
||||
{
|
||||
public:
|
||||
IpcConfig() = default;
|
||||
virtual ~IpcConfig() = default;
|
||||
static std::shared_ptr<IpcConfig> &GetInstance(std::shared_ptr<IpcConfig> *impl = nullptr);
|
||||
const StatusCode Init(void);
|
||||
const StatusCode UnInit(void);
|
||||
const int GetInt(const IpcConfigKey &key);
|
||||
};
|
||||
#endif
|
|
@ -5,11 +5,17 @@ const StatusCode IpcConfig::Init(void)
|
|||
{
|
||||
memset(&mAllData, 0, sizeof(Config_s));
|
||||
mCfg = OpenConfigFile(IPC_CONFIG_FILE_PATH);
|
||||
if (nullptr == mCfg)
|
||||
{
|
||||
LogError("Open config file failed.\n");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
ReadAllConfigParameters();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode IpcConfig::UnInit(void)
|
||||
{
|
||||
CloseConfigFile(mCfg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const int IpcConfig::GetInt(const IpcConfigKey &key)
|
||||
|
|
|
@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_LINUX_MOCK}")
|
|||
execute_process(COMMAND sh build_gtest.sh ${TARGET_PLATFORM} ${CMAKE_SOURCE_DIR_IPCSDK} ${PLATFORM_PATH} WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/gtest/)
|
||||
# add_subdirectory(test_utils)
|
||||
# add_subdirectory(application)
|
||||
# add_subdirectory(component)
|
||||
add_subdirectory(middleware)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(hal)
|
||||
|
||||
|
|
4
test/middleware/CMakeLists.txt
Normal file
4
test/middleware/CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
# cmake_minimum_required(VERSION 2.8.0)
|
||||
add_subdirectory(IpcConfig)
|
||||
|
58
test/middleware/IpcConfig/CMakeLists.txt
Normal file
58
test/middleware/IpcConfig/CMakeLists.txt
Normal file
|
@ -0,0 +1,58 @@
|
|||
# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin)
|
||||
|
||||
include_directories(
|
||||
.
|
||||
./src
|
||||
./include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/IpcConfig/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}/gtest/googletest-release-1.11.0/googlemock/lib
|
||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/lib
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
aux_source_directory(. SRC_FILES)
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME IpcConfigTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} IpcConfig gtest gmock pthread)
|
||||
if(${COVERAGE_ON} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
IpcConfigTest_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${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 ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell
|
||||
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/IpcConfig
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make IpcConfigTest_code_check
|
||||
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
9
test/middleware/IpcConfig/mainTest.cpp
Normal file
9
test/middleware/IpcConfig/mainTest.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#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();
|
||||
}
|
18
test/middleware/IpcConfig/src/IpcConfig_Test.cpp
Normal file
18
test/middleware/IpcConfig/src/IpcConfig_Test.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "ILog.h"
|
||||
#include "IIpcConfig.h"
|
||||
// #include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
namespace IpcConfigTest
|
||||
{
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.Demo
|
||||
TEST(IpcConfigTest, Demo)
|
||||
{
|
||||
CreateLogModule();
|
||||
CreateIpcConfig();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
IIpcConfig::GetInstance()->Init();
|
||||
IIpcConfig::GetInstance()->UnInit();
|
||||
ILogUnInit();
|
||||
DestroyLogModule();
|
||||
}
|
||||
} // namespace IpcConfigTest
|
|
@ -1,5 +1,6 @@
|
|||
#include "Config.h"
|
||||
#include "ConfigImpl.h"
|
||||
#include "ILog.h"
|
||||
#include <stddef.h>
|
||||
const StatusCode ConfigInit(void)
|
||||
{
|
||||
|
@ -15,6 +16,11 @@ VConfig *OpenConfigFile(const char *fileName)
|
|||
}
|
||||
void CloseConfigFile(VConfig *cfg)
|
||||
{
|
||||
if (NULL == cfg)
|
||||
{
|
||||
LogError("NULL config poniter.\n");
|
||||
return;
|
||||
}
|
||||
((Config *)cfg)->close(cfg);
|
||||
}
|
||||
const StatusCode ConfigGetInt(VConfig *cfg, const char *name, int *value)
|
||||
|
|
|
@ -33,10 +33,10 @@ static StatusCode NewConfigCode(const long int code)
|
|||
}
|
||||
const StatusCode CreateConfigCode(const long int code)
|
||||
{
|
||||
if (STATUS_CODE_OK <= code && code < STATUS_CODE_END)
|
||||
{
|
||||
return CreateStatusCode(code);
|
||||
}
|
||||
// if (STATUS_CODE_OK <= code && code < STATUS_CODE_END)
|
||||
// {
|
||||
// return CreateStatusCode(code);
|
||||
// }
|
||||
if (STATUS_CODE_END <= code && code < CONFIG_CODE_END)
|
||||
{
|
||||
return NewConfigCode(code);
|
||||
|
|
|
@ -39,6 +39,7 @@ static void ConfigImplInit(Config *cfg)
|
|||
}
|
||||
Config *NewConfig(const char *fileName)
|
||||
{
|
||||
LogInfo("Config file name = %s\n", fileName);
|
||||
Config *cfg = (Config *)malloc(sizeof(Config));
|
||||
ConfigImplInit(cfg);
|
||||
config_init(&(cfg->cfg));
|
||||
|
@ -46,10 +47,12 @@ Config *NewConfig(const char *fileName)
|
|||
CONFIG_OPTION_SEMICOLON_SEPARATORS |
|
||||
CONFIG_OPTION_COLON_ASSIGNMENT_FOR_GROUPS |
|
||||
CONFIG_OPTION_OPEN_BRACE_ON_SEPARATE_LINE));
|
||||
if (access(fileName, F_OK))
|
||||
#define FIEL_EXIST 0
|
||||
if (FIEL_EXIST == access(fileName, F_OK))
|
||||
{
|
||||
if (!config_read_file(&(cfg->cfg), fileName))
|
||||
{
|
||||
LogError("Read file failed[%s].\n", fileName);
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&(cfg->cfg)),
|
||||
config_error_line(&(cfg->cfg)), config_error_text(&(cfg->cfg)));
|
||||
// config_destroy(&(cfg->cfg));
|
||||
|
@ -58,6 +61,7 @@ Config *NewConfig(const char *fileName)
|
|||
}
|
||||
else
|
||||
{
|
||||
LogInfo("Config file doesn't exist.\n");
|
||||
/* Write out the new configuration. */
|
||||
if (!config_write_file(&(cfg->cfg), fileName))
|
||||
{
|
||||
|
|
|
@ -19,6 +19,14 @@ static const char *_PrintStringCode_(const StatusCode this)
|
|||
}
|
||||
static const bool CodeEqual(const StatusCode code, const char *value)
|
||||
{
|
||||
if (STATUS_CODE_OK >= code.mStatusCode || code.mStatusCode >= STATUS_CODE_END)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (strlen(value) != strlen(StatusCodeString[code.mStatusCode]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (memcmp(value, StatusCodeString[code.mStatusCode], strlen(value)) == 0)
|
||||
{
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user