Add Log & ReturnCode.

This commit is contained in:
xiaojiazhu 2023-07-20 08:18:17 -07:00
parent c82df95b02
commit a91c04d9d4
37 changed files with 9380 additions and 164 deletions

View File

@ -46,9 +46,10 @@ if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
endif() endif()
# #
add_subdirectory(application) # add_subdirectory(application)
add_subdirectory(component) # add_subdirectory(component)
add_subdirectory(hal) # add_subdirectory(hal)
add_subdirectory(utils)
add_subdirectory(test) add_subdirectory(test)

View File

@ -11,6 +11,7 @@ set(TEST_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/out/test")
set(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}") set(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}")
set(APPLICATION_SOURCE_PATH "${CMAKE_SOURCE_DIR}/application") set(APPLICATION_SOURCE_PATH "${CMAKE_SOURCE_DIR}/application")
set(COMPONENT_SOURCE_PATH "${CMAKE_SOURCE_DIR}/component") set(COMPONENT_SOURCE_PATH "${CMAKE_SOURCE_DIR}/component")
set(UTILS_SOURCE_PATH "${CMAKE_SOURCE_DIR}/utils")
set(HAL_SOURCE_PATH "${CMAKE_SOURCE_DIR}/hal") set(HAL_SOURCE_PATH "${CMAKE_SOURCE_DIR}/hal")
set(TEST_SOURCE_PATH "${CMAKE_SOURCE_DIR}/test") set(TEST_SOURCE_PATH "${CMAKE_SOURCE_DIR}/test")
set(EXTERNAL_SOURCE_PATH "${CMAKE_SOURCE_DIR}/external") set(EXTERNAL_SOURCE_PATH "${CMAKE_SOURCE_DIR}/external")

View File

@ -125,8 +125,13 @@ libLogAbstract.a -->> -User:return
##### 1.4.2.4.3. 返回码管理库 ##### 1.4.2.4.3. 返回码管理库
###### 1.4.2.4.3.1. 返回码管理库概述 ###### 1.4.2.4.3.1. 返回码管理库概述
   提供整个应用程序的返回码管理功能例如打印返回码的字符串含义。提供C语言接口内部实现不限于C或者C++,形成项目内部唯一返回码标准。    提供整个应用程序的返回码管理功能例如打印返回码的字符串含义。提供C语言接口纯C语言开发的模块,形成项目内部唯一返回码标准。
1. 创建返回码操作“句柄”; 1. 创建返回码操作“句柄”;
2. 打印返回码/获取返回码(字符串); 2. 打印返回码/获取返回码(字符串);
3. 不同的模块可继承实现各自的返回码处理接口; 3. 不同的模块可继承实现各自的返回码处理接口;
##### 1.4.2.4.4. 系统标准接口库
   对系统标准接口的套壳封装,主要是为了对系统标准打桩满足测试需求。
   使用普通的C语言接口封装即可通过使用gcc编译参数在Linux x86系统中满足打桩需求在交叉编译担心工具链兼容问题测试程序中无法对系统标准接口进行打桩。

8
external/gtest/Makefile vendored Normal file
View File

@ -0,0 +1,8 @@
all:
./build_gtest.sh
clean:
@rm -rf googletest-release-1.11.0/googlemock/CMakeCache.txt \
googletest-release-1.11.0/googlemock/CMakeFiles/ \
googletest-release-1.11.0/googlemock/cmake_install.cmake \
googletest-release-1.11.0/googlemock/Makefile \
googletest-release-1.11.0/googlemock/lib

35
external/gtest/build_gtest.sh vendored Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#编译gtest库
platform=$1
CMAKE_SOURCE_DIR=$2
echo "Compile gtest, platform = $platform, cmake source dir = $CMAKE_SOURCE_DIR."
export ROOT_PATH=$PWD
if [ ! -d "./googletest-release-1.11.0" ];then
echo "tar zxvf googletest-release-1.11.0.tar.gz"
tar zxvf googletest-release-1.11.0.tar.gz
cp ./modify/CMakeList_gmock.txt ./googletest-release-1.11.0/googlemock/CMakeLists.txt
cp ./modify/CMakeList_gtest.txt ./googletest-release-1.11.0/googletest/CMakeLists.txt
fi
if [ ! -f "./googletest-release-1.11.0/googlemock/lib/libgtest.a" ] || [ ! -f "./googletest-release-1.11.0/googlemock/lib/libgmock.a" ];then
echo "make gtest"
cd ./googletest-release-1.11.0/googlemock/
rm CMakeCache.txt CMakeFiles/ cmake_install.cmake Makefile lib/ -rf
case $platform in
"linux")
echo "==Compile linux."
cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_SOURCE_DIR/build/cmake/toolchain/linux.toolchain.cmake .
make
;;
"sigmastart_333DE")
echo "==Compile sigmastart_333DE."
cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_SOURCE_DIR/333DE/build/cmake/toolchain/sigmastart_333DE.toolchain.cmake .
make
;;
*)
echo "Compile gtest failed."
;;
esac
fi
cd $ROOT_PATH
echo "Exit build_gtest.sh."

Binary file not shown.

View File

@ -0,0 +1,224 @@
########################################################################
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.
#
# CMake build script for Google Mock.
#
# To run the tests for Google Mock itself on Linux, use 'make test' or
# ctest. You can select which tests to run using 'ctest -R regex'.
# For more options, run 'ctest --help'.
option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
# A directory to find Google Test sources.
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
set(gtest_dir gtest)
else()
set(gtest_dir ../googletest)
endif()
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
if (COMMAND pre_project_set_up_hermetic_build)
# Google Test also calls hermetic setup functions from add_subdirectory,
# although its changes will not affect things at the current scope.
pre_project_set_up_hermetic_build()
endif()
#交叉编译工具链
#set(CMAKE_SYSTEM_NAME Linux)
#set(CMAKE_SYSTEM_PROCESSOR arm)
#set(CMAKE_C_COMPILER /home/beal.wu/sip/ssd20x_awtk/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
#set(CMAKE_CXX_COMPILER /home/beal.wu/sip/ssd20x_awtk/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
########################################################################
#
# Project-wide settings
# Name of the project.
#
# CMake files in this project can refer to the root source directory
# as ${gmock_SOURCE_DIR} and to the root binary directory as
# ${gmock_BINARY_DIR}.
# Language "C" is required for find_package(Threads).
if (CMAKE_VERSION VERSION_LESS 3.0)
project(gmock CXX C)
else()
cmake_policy(SET CMP0048 NEW)
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
endif()
cmake_minimum_required(VERSION 2.8.12)
if (COMMAND set_up_hermetic_build)
set_up_hermetic_build()
endif()
# Instructs CMake to process Google Test's CMakeLists.txt and add its
# targets to the current scope. We are placing Google Test's binary
# directory in a subdirectory of our own as VC compilation may break
# if they are the same (the default).
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
# These commands only run if this is the main project
if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
else()
mark_as_advanced(gmock_build_tests)
endif()
# Although Google Test's CMakeLists.txt calls this function, the
# changes there don't affect the current scope. Therefore we have to
# call it again here.
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
# Adds Google Mock's and Google Test's header directories to the search path.
set(gmock_build_include_dirs
"${gmock_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}"
"${gtest_SOURCE_DIR}/include"
# This directory is needed to build directly from Google Test sources.
"${gtest_SOURCE_DIR}")
include_directories(${gmock_build_include_dirs})
########################################################################
#
# Defines the gmock & gmock_main libraries. User tests should link
# with one of them.
# Google Mock libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings.
if (MSVC)
cxx_library(gmock
"${cxx_strict}"
"${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc)
cxx_library(gmock_main
"${cxx_strict}"
"${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc
src/gmock_main.cc)
else()
cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
target_link_libraries(gmock PUBLIC gtest)
#set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION})
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
target_link_libraries(gmock_main PUBLIC gmock)
#set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
endif()
# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(gmock SYSTEM INTERFACE
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
########################################################################
#
# Install rules
install_project(gmock gmock_main)
########################################################################
#
# Google Mock's own tests.
#
# You can skip this section if you aren't interested in testing
# Google Mock itself.
#
# The tests are not built by default. To build them, set the
# gmock_build_tests option to ON. You can do it by running ccmake
# or specifying the -Dgmock_build_tests=ON flag when running cmake.
if (gmock_build_tests)
# This must be set in the root directory for the tests to be run by
# 'make test' or ctest.
enable_testing()
if (MINGW OR CYGWIN)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
add_compile_options("-Wa,-mbig-obj")
else()
add_definitions("-Wa,-mbig-obj")
endif()
endif()
############################################################
# C++ tests built with standard compiler flags.
cxx_test(gmock-actions_test gmock_main)
cxx_test(gmock-cardinalities_test gmock_main)
cxx_test(gmock_ex_test gmock_main)
cxx_test(gmock-function-mocker_test gmock_main)
cxx_test(gmock-internal-utils_test gmock_main)
cxx_test(gmock-matchers_test gmock_main)
cxx_test(gmock-more-actions_test gmock_main)
cxx_test(gmock-nice-strict_test gmock_main)
cxx_test(gmock-port_test gmock_main)
cxx_test(gmock-spec-builders_test gmock_main)
cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
cxx_test(gmock_test gmock_main)
if (DEFINED GTEST_HAS_PTHREAD)
cxx_test(gmock_stress_test gmock)
endif()
# gmock_all_test is commented to save time building and running tests.
# Uncomment if necessary.
# cxx_test(gmock_all_test gmock_main)
############################################################
# C++ tests built with non-standard compiler flags.
if (MSVC)
cxx_library(gmock_main_no_exception "${cxx_no_exception}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
else()
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_exception PUBLIC gmock)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
endif()
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
gmock_main_no_exception test/gmock-more-actions_test.cc)
cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
gmock_main_no_rtti test/gmock-spec-builders_test.cc)
cxx_shared_library(shared_gmock_main "${cxx_default}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
# Tests that a binary can be built with Google Mock as a shared library. On
# some system configurations, it may not possible to run the binary without
# knowing more details about the system configurations. We do not try to run
# this binary. To get a more robust shared library coverage, configure with
# -DBUILD_SHARED_LIBS=ON.
cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
shared_gmock_main test/gmock-spec-builders_test.cc)
set_target_properties(shared_gmock_test_
PROPERTIES
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
############################################################
# Python tests.
cxx_executable(gmock_leak_test_ test gmock_main)
py_test(gmock_leak_test)
cxx_executable(gmock_output_test_ test gmock)
py_test(gmock_output_test)
endif()

View File

@ -0,0 +1,329 @@
########################################################################
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.
#
# CMake build script for Google Test.
#
# To run the tests for Google Test itself on Linux, use 'make test' or
# ctest. You can select which tests to run using 'ctest -R regex'.
# For more options, run 'ctest --help'.
# When other libraries are using a shared version of runtime libraries,
# Google Test also has to use one.
option(
gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
OFF)
option(gtest_build_tests "Build all of gtest's own tests." OFF)
option(gtest_build_samples "Build gtest's sample programs." OFF)
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
option(
gtest_hide_internal_symbols
"Build gtest with internal symbols hidden in shared libraries."
OFF)
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
include(cmake/hermetic_build.cmake OPTIONAL)
if (COMMAND pre_project_set_up_hermetic_build)
pre_project_set_up_hermetic_build()
endif()
########################################################################
#
# Project-wide settings
# Name of the project.
#
# CMake files in this project can refer to the root source directory
# as ${gtest_SOURCE_DIR} and to the root binary directory as
# ${gtest_BINARY_DIR}.
# Language "C" is required for find_package(Threads).
# Project version:
if (CMAKE_VERSION VERSION_LESS 3.0)
project(gtest CXX C)
set(PROJECT_VERSION ${GOOGLETEST_VERSION})
else()
cmake_policy(SET CMP0048 NEW)
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
endif()
cmake_minimum_required(VERSION 2.8.12)
#交叉编译工具链
#set(CMAKE_SYSTEM_NAME Linux)
#set(CMAKE_SYSTEM_PROCESSOR arm)
#set(CMAKE_C_COMPILER /home/beal.wu/sip/ssd20x_awtk/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
#set(CMAKE_CXX_COMPILER /home/beal.wu/sip/ssd20x_awtk/gcc-arm-8.2-2018.08-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
if (POLICY CMP0063) # Visibility
cmake_policy(SET CMP0063 NEW)
endif (POLICY CMP0063)
if (COMMAND set_up_hermetic_build)
set_up_hermetic_build()
endif()
# These commands only run if this is the main project
if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
else()
mark_as_advanced(
gtest_force_shared_crt
gtest_build_tests
gtest_build_samples
gtest_disable_pthreads
gtest_hide_internal_symbols)
endif()
if (gtest_hide_internal_symbols)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()
# Define helper functions and macros used by Google Test.
include(cmake/internal_utils.cmake)
config_compiler_and_linker() # Defined in internal_utils.cmake.
# Needed to set the namespace for both the export targets and the
# alias libraries
set(cmake_package_name GTest CACHE INTERNAL "")
# Create the CMake package file descriptors.
if (INSTALL_GTEST)
include(CMakePackageConfigHelpers)
set(targets_export_name ${cmake_package_name}Targets CACHE INTERNAL "")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "")
set(cmake_files_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${cmake_package_name}")
set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake")
write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion)
install(EXPORT ${targets_export_name}
NAMESPACE ${cmake_package_name}::
DESTINATION ${cmake_files_install_dir})
set(config_file "${generated_dir}/${cmake_package_name}Config.cmake")
configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in"
"${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir})
install(FILES ${version_file} ${config_file}
DESTINATION ${cmake_files_install_dir})
endif()
# Where Google Test's .h files can be found.
set(gtest_build_include_dirs
"${gtest_SOURCE_DIR}/include"
"${gtest_SOURCE_DIR}")
include_directories(${gtest_build_include_dirs})
########################################################################
#
# Defines the gtest & gtest_main libraries. User tests should link
# with one of them.
# Google Test libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that gtest can be compiled by a user
# aggressive about warnings.
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
#set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION})
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
#set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(gtest SYSTEM INTERFACE
"$<BUILD_INTERFACE:${gtest_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gtest_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${gtest_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
target_link_libraries(gtest_main PUBLIC gtest)
########################################################################
#
# Install rules
install_project(gtest gtest_main)
########################################################################
#
# Samples on how to link user tests with gtest or gtest_main.
#
# They are not built by default. To build them, set the
# gtest_build_samples option to ON. You can do it by running ccmake
# or specifying the -Dgtest_build_samples=ON flag when running cmake.
if (gtest_build_samples)
cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc)
cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc)
cxx_executable(sample3_unittest samples gtest_main)
cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc)
cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc)
cxx_executable(sample6_unittest samples gtest_main)
cxx_executable(sample7_unittest samples gtest_main)
cxx_executable(sample8_unittest samples gtest_main)
cxx_executable(sample9_unittest samples gtest)
cxx_executable(sample10_unittest samples gtest)
endif()
########################################################################
#
# Google Test's own tests.
#
# You can skip this section if you aren't interested in testing
# Google Test itself.
#
# The tests are not built by default. To build them, set the
# gtest_build_tests option to ON. You can do it by running ccmake
# or specifying the -Dgtest_build_tests=ON flag when running cmake.
if (gtest_build_tests)
# This must be set in the root directory for the tests to be run by
# 'make test' or ctest.
enable_testing()
############################################################
# C++ tests built with standard compiler flags.
cxx_test(googletest-death-test-test gtest_main)
cxx_test(gtest_environment_test gtest)
cxx_test(googletest-filepath-test gtest_main)
cxx_test(googletest-listener-test gtest_main)
cxx_test(gtest_main_unittest gtest_main)
cxx_test(googletest-message-test gtest_main)
cxx_test(gtest_no_test_unittest gtest)
cxx_test(googletest-options-test gtest_main)
cxx_test(googletest-param-test-test gtest
test/googletest-param-test2-test.cc)
cxx_test(googletest-port-test gtest_main)
cxx_test(gtest_pred_impl_unittest gtest_main)
cxx_test(gtest_premature_exit_test gtest
test/gtest_premature_exit_test.cc)
cxx_test(googletest-printers-test gtest_main)
cxx_test(gtest_prod_test gtest_main
test/production.cc)
cxx_test(gtest_repeat_test gtest)
cxx_test(gtest_sole_header_test gtest_main)
cxx_test(gtest_stress_test gtest)
cxx_test(googletest-test-part-test gtest_main)
cxx_test(gtest_throw_on_failure_ex_test gtest)
cxx_test(gtest-typed-test_test gtest_main
test/gtest-typed-test2_test.cc)
cxx_test(gtest_unittest gtest_main)
cxx_test(gtest-unittest-api_test gtest)
cxx_test(gtest_skip_in_environment_setup_test gtest_main)
cxx_test(gtest_skip_test gtest_main)
############################################################
# C++ tests built with non-standard compiler flags.
# MSVC 7.1 does not support STL with exceptions disabled.
if (NOT MSVC OR MSVC_VERSION GREATER 1310)
cxx_library(gtest_no_exception "${cxx_no_exception}"
src/gtest-all.cc)
cxx_library(gtest_main_no_exception "${cxx_no_exception}"
src/gtest-all.cc src/gtest_main.cc)
endif()
cxx_library(gtest_main_no_rtti "${cxx_no_rtti}"
src/gtest-all.cc src/gtest_main.cc)
cxx_test_with_flags(gtest-death-test_ex_nocatch_test
"${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0"
gtest test/googletest-death-test_ex_test.cc)
cxx_test_with_flags(gtest-death-test_ex_catch_test
"${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1"
gtest test/googletest-death-test_ex_test.cc)
cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}"
gtest_main_no_rtti test/gtest_unittest.cc)
cxx_shared_library(gtest_dll "${cxx_default}"
src/gtest-all.cc src/gtest_main.cc)
cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}"
gtest_dll test/gtest_all_test.cc)
set_target_properties(gtest_dll_test_
PROPERTIES
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
############################################################
# Python tests.
cxx_executable(googletest-break-on-failure-unittest_ test gtest)
py_test(googletest-break-on-failure-unittest)
py_test(gtest_skip_check_output_test)
py_test(gtest_skip_environment_check_output_test)
# Visual Studio .NET 2003 does not support STL with exceptions disabled.
if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003
cxx_executable_with_flags(
googletest-catch-exceptions-no-ex-test_
"${cxx_no_exception}"
gtest_main_no_exception
test/googletest-catch-exceptions-test_.cc)
endif()
cxx_executable_with_flags(
googletest-catch-exceptions-ex-test_
"${cxx_exception}"
gtest_main
test/googletest-catch-exceptions-test_.cc)
py_test(googletest-catch-exceptions-test)
cxx_executable(googletest-color-test_ test gtest)
py_test(googletest-color-test)
cxx_executable(googletest-env-var-test_ test gtest)
py_test(googletest-env-var-test)
cxx_executable(googletest-filter-unittest_ test gtest)
py_test(googletest-filter-unittest)
cxx_executable(gtest_help_test_ test gtest_main)
py_test(gtest_help_test)
cxx_executable(googletest-list-tests-unittest_ test gtest)
py_test(googletest-list-tests-unittest)
cxx_executable(googletest-output-test_ test gtest)
py_test(googletest-output-test --no_stacktrace_support)
cxx_executable(googletest-shuffle-test_ test gtest)
py_test(googletest-shuffle-test)
# MSVC 7.1 does not support STL with exceptions disabled.
if (NOT MSVC OR MSVC_VERSION GREATER 1310)
cxx_executable(googletest-throw-on-failure-test_ test gtest_no_exception)
set_target_properties(googletest-throw-on-failure-test_
PROPERTIES
COMPILE_FLAGS "${cxx_no_exception}")
py_test(googletest-throw-on-failure-test)
endif()
cxx_executable(googletest-uninitialized-test_ test gtest)
py_test(googletest-uninitialized-test)
cxx_executable(gtest_list_output_unittest_ test gtest)
py_test(gtest_list_output_unittest)
cxx_executable(gtest_xml_outfile1_test_ test gtest_main)
cxx_executable(gtest_xml_outfile2_test_ test gtest_main)
py_test(gtest_xml_outfiles_test)
py_test(googletest-json-outfiles-test)
cxx_executable(gtest_xml_output_unittest_ test gtest)
py_test(gtest_xml_output_unittest --no_stacktrace_support)
py_test(googletest-json-output-unittest --no_stacktrace_support)
endif()

13
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
# cmake_minimum_required(VERSION 2.8.0)
# Mock Linux api.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_LINUX_MOCK}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_LINUX_MOCK}")
# Compile gtest for test code.
execute_process(COMMAND sh build_gtest.sh ${TARGET_PLATFORM} ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/gtest/)
# add_subdirectory(test_utils)
# add_subdirectory(application)
# add_subdirectory(component)
add_subdirectory(utils)
# add_subdirectory(hal)

View File

@ -0,0 +1,6 @@
# cmake_minimum_required(VERSION 2.8.0)
#Compile gtest for test code.
add_subdirectory(ReturnCode)

View File

@ -0,0 +1,31 @@
# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake)
set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin)
include_directories(
${UTILS_SOURCE_PATH}/ReturnCode/include
${UTILS_SOURCE_PATH}/Log/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}
)
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 ReturnCodeTest)
add_executable(${TARGET_NAME} ${SRC_FILES})
target_link_libraries(${TARGET_NAME} gtest gmock pthread Log)
if(${COVERAGE_ON} MATCHES "true")
target_link_libraries(${TARGET_NAME} gcov)
endif()

View 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();
}

View File

@ -0,0 +1,14 @@
#include "ReturnCode.h"
#include "Log.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace ReturnCodeTest
{
// ../out/test/bin/ReturnCodeTest --gtest_filter=ReturnCodeTest.Demo
TEST(ReturnCodeTest, Demo)
{
InitLog(LOG_EASYLOGGING, nullptr);
LogInfo("hello world.\n");
UnInitLog();
}
}

4
utils/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
# cmake_minimum_required(VERSION 2.8.0)
add_subdirectory(ReturnCode)
add_subdirectory(Log)

24
utils/Log/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
${UTILS_SOURCE_PATH}/Log/src/easyloggingpp
)
#do not rely on any other library
#link_directories(
#)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(./src SRC_FILES)
aux_source_directory(./src/easyloggingpp SRC_FILES)
set(TARGET_NAME Log)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})

112
utils/Log/include/Log.h Normal file
View File

@ -0,0 +1,112 @@
/**
* @brief
* The only one header file for the other modules to use log module.
*/
#ifndef LOG_H
#define LOG_H
#define LogVerbose(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_VERBOSE, __VA_ARGS__)
#define LogDebug(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_DEBUG, __VA_ARGS__)
#define LogInfo(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_INFORMATION, __VA_ARGS__)
#define LogWarning(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_WARNING, __VA_ARGS__)
#define LogError(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_ERROR, __VA_ARGS__)
#define LogTrace(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_TRACE, __VA_ARGS__)
// For test code, never using in release version.
// #define LogTestTips(...) TestTips(LOG_TYPE_TEST_TIPS, __VA_ARGS__)
// TODO:
#if 1 // For wifi log, should delete finally.
#define LOGD(...)
#define LOGI(...)
#define LOGW(...)
#define LOGE(...)
#define LOGF(...)
#endif
/**
* @brief
* log type.
*/
enum LogType
{
LOG_TYPE_VERBOSE = 0,
LOG_TYPE_DEBUG,
LOG_TYPE_INFORMATION,
LOG_TYPE_WARNING,
LOG_TYPE_ERROR,
LOG_TYPE_TRACE,
LOG_TYPE_TEST_TIPS,
LOG_TYPE_END
};
/**
* @brief
* instance type of log module.
*/
enum LogInstanceType
{
LOG_SERIAL_PRINT = 0, // for serial print.
LOG_EASYLOGGING, // for easylogging++.
LOG_CAPTURE_LOG, // capture log to other who need it
LOG_INSTANCE_TYPE_END
};
/**
* @brief
* Log setting
*/
typedef struct LogSetting
{
const char *fileName; // File name of saving log.
const char *maxSize; // Max size of saving log.
const int (*callback)(const char *); //
const int (*callback_InFo)(const char *);
const int (*callback_Warning)(const char *);
const int (*callback_Error)(const char *);
const int (*callback_Debug)(const char *);
const int (*callback_Trace)(const char *);
} LogSetting;
/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief
* Init what type of log to run, see LogInstanceType in this file.
* @param logInstanceType
* @param setting Setting of log module, See LogSetting.
* @return true
* @return false
*/
int InitLog(const int logInstanceType, const LogSetting *setting);
int UnInitLog();
/**
* @brief
* Print log
* TODO: Crash will happen if print a string without '\0'.
* @param function
* @param line
* @param type
* @param format
* @param ...
* @return int
*/
int Log(const char *function, int line, int type, const char *format, ...);
/**
* @brief
* Only for test code.
* @param format
* @param ...
* @return const char*
*/
// const char *TestTips(int type, const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif

32
utils/Log/src/ILog.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "ILog.h"
#include <thread>
std::shared_ptr<ILog> &ILog::GetInstance(std::shared_ptr<ILog> *impl)
{
static std::shared_ptr<ILog> instance = std::make_shared<ILog>();
static bool instanceChanging = false;
if (impl && false == instanceChanging)
{
// Don't use std::mutex for runing faster.
// Sleep for difference thread to release instance.
instanceChanging = true;
//std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (instance.use_count() == 1) // bug?
{
instance->Log("Instance change succeed.\n");
instance->UnInit();
(*impl)->Init();
instance = *impl;
}
else
{
instance->Log("[ error ] instance change failed, using by some one.\n");
}
instanceChanging = false;
}
if (instanceChanging)
{
static std::shared_ptr<ILog> tmporaryInstance = std::make_shared<ILog>();
return tmporaryInstance;
}
return instance;
}

48
utils/Log/src/ILog.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef I_LOG_H
#define I_LOG_H
// #include "VReturnCode.h"
#include <iostream>
#include <memory>
class ILog
{
public:
/**
* @brief Get the Instance object
* Return reference for runing faster. Usage : ILog::GetInstance()->Init();
* Don't use ILog like this:
* std::shared_ptr<ILog> &log = ILog::GetInstance(); or std::shared_ptr<ILog> log = ILog::GetInstance();
* log->Log("Your log.");
* @param impl Change the instance.
* @return std::shared_ptr<ILog>&
*/
static std::shared_ptr<ILog> &GetInstance(std::shared_ptr<ILog> *impl = nullptr);
ILog() = default;
virtual ~ILog() = default;
virtual bool Init() { return false; }
virtual bool UnInit() { return false; }
/**
* @brief
* If the Log module is working.
* @return true
* @return false
*/
virtual bool IsWorking() { return false; }
/**
* @brief
* Virtual log function.
* @param buff
* @return int
*/
virtual int Log(const char *buff) { return 0; }
virtual int InFo(const char *buff) { return 0; }
virtual int Warning(const char *buff) { return 0; }
virtual int Error(const char *buff) { return 0; }
virtual int Trace(const char *buff) { return 0; }
virtual int Debug(const char *buff) { return 0; }
};
#endif

View File

@ -0,0 +1,19 @@
#include "ILogMakePtr.h"
#include "LogImpl.h"
#include "LogEasylogging.h"
#include "LogCapture.h"
std::shared_ptr<ILog> ILogMakePtr::MakeLogImplPtr()
{
std::shared_ptr<ILog> logImpl = std::make_shared<LogImpl>();
return logImpl;
}
std::shared_ptr<ILog> ILogMakePtr::MakeLogEasylogging(const LogSetting *setting)
{
std::shared_ptr<ILog> logImpl = std::make_shared<LogEasylogging>(setting);
return logImpl;
}
std::shared_ptr<ILog> ILogMakePtr::MakeLongCapture(const LogSetting *setting)
{
std::shared_ptr<ILog> logImpl = std::make_shared<LogCapture>(*setting);
return logImpl;
}

View File

@ -0,0 +1,25 @@
#ifndef ILOG_MAKE_PTR_H
#define ILOG_MAKE_PTR_H
#include "ILog.h"
#include "Log.h"
#include <iostream>
#include <memory>
class ILogMakePtr
{
public:
static std::shared_ptr<ILogMakePtr> &GetInstance(std::shared_ptr<ILogMakePtr> *impl = nullptr)
{
static std::shared_ptr<ILogMakePtr> instance = std::make_shared<ILogMakePtr>();
if (impl)
{
instance = *impl;
}
return instance;
}
ILogMakePtr() = default;
virtual ~ILogMakePtr() = default;
virtual std::shared_ptr<ILog> MakeLogImplPtr();
virtual std::shared_ptr<ILog> MakeLogEasylogging(const LogSetting *setting);
virtual std::shared_ptr<ILog> MakeLongCapture(const LogSetting *setting);
};
#endif

109
utils/Log/src/Log.cpp Normal file
View File

@ -0,0 +1,109 @@
#include "Log.h"
#include "ILog.h"
#include "LogImpl.h"
#include "ILogMakePtr.h"
#include <stdarg.h>
#include <stdio.h>
#include <iostream>
#include <memory>
#include <string.h>
int InitLog(const int logInstanceType, const LogSetting *setting)
{
switch (logInstanceType)
{
case LOG_SERIAL_PRINT:
{
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLogImplPtr();
ILog::GetInstance(&logImpl);
break;
}
case LOG_EASYLOGGING:
{
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLogEasylogging(setting);
ILog::GetInstance(&logImpl);
break;
}
case LOG_CAPTURE_LOG:
{
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLongCapture(setting);
ILog::GetInstance(&logImpl);
break;
}
default:
{
LogError("Log module init error.\n");
return -1;
}
}
return 0;
}
int UnInitLog()
{
std::shared_ptr<ILog> logImpl = std::make_shared<ILog>();
ILog::GetInstance(&logImpl);
return 0;
}
// static void LogTypeToString(const int type)
// {
// switch (type)
// {
// case LOG_TYPE_ERROR:
// {
// ILog::GetInstance()->Log("[ ERROR ]");
// break;
// }
// case LOG_TYPE_TEST_TIPS:
// {
// ILog::GetInstance()->Log("[ FAILURE ]");
// break;
// }
// default:
// break;
// }
// }
int Log(const char *function, int line, int type, const char *format, ...)
{
if (!ILog::GetInstance()->IsWorking())
{
return -1;
}
// TODO:
// LogTypeToString(type);
constexpr int SEND_TRACE_BUFF_SIZE = 2048;
char buff[SEND_TRACE_BUFF_SIZE] = {0};
snprintf(buff, SEND_TRACE_BUFF_SIZE, "[%s][line:%d]:", function, line);
// ILog::GetInstance()->Log(buff);
const int headLen = strlen(buff);
va_list vargs;
va_start(vargs, format);
int len = vsnprintf(buff + headLen, SEND_TRACE_BUFF_SIZE - headLen, format, vargs);
va_end(vargs);
switch (type)
{
case LOG_TYPE_INFORMATION:
ILog::GetInstance()->InFo(buff);
break;
case LOG_TYPE_WARNING:
ILog::GetInstance()->Warning(buff);
break;
case LOG_TYPE_ERROR:
ILog::GetInstance()->Error(buff);
break;
case LOG_TYPE_DEBUG:
ILog::GetInstance()->Debug(buff);
break;
case LOG_TYPE_TRACE:
ILog::GetInstance()->Trace(buff);
break;
default:
break;
}
return len;
}

View File

@ -0,0 +1,81 @@
#include "LogCapture.h"
#include <thread>
#include <stdio.h>
LogCapture::LogCapture(const LogSetting setting) : mLogCapture(setting.callback),
mLogCapture_InFo(setting.callback_InFo), mLogCapture_Warning(setting.callback_Warning),
mLogCapture_Error(setting.callback_Error), mLogCapture_Debug(setting.callback_Debug),
mLogCapture_Trace(setting.callback_Trace)
{
if (!setting.callback)
{
return;
}
}
bool LogCapture::Init()
{
return true;
}
bool LogCapture::UnInit()
{
return true;
}
bool LogCapture::IsWorking()
{
return true;
}
int LogCapture::Log(const char *buff)
{
if (mLogCapture)
{
mLogCapture(buff);
}
return 0;
}
int LogCapture::InFo(const char *buff)
{
if (mLogCapture_InFo)
{
mLogCapture_InFo(buff);
}
return 0;
}
int LogCapture::Warning(const char *buff)
{
if (mLogCapture_Warning)
{
mLogCapture_Warning(buff);
}
return 0;
}
int LogCapture::Error(const char *buff)
{
if (mLogCapture_Error)
{
mLogCapture_Error(buff);
}
return 0;
}
int LogCapture::Debug(const char *buff)
{
if (mLogCapture_Debug)
{
mLogCapture_Debug(buff);
}
return 0;
}
int LogCapture::Trace(const char *buff)
{
if (mLogCapture_Trace)
{
mLogCapture_Trace(buff);
}
return 0;
}

View File

@ -0,0 +1,31 @@
#ifndef LOG_CAPTURE_H
#define LOG_CAPTURE_H
#include "ILog.h"
#include "Log.h"
class LogCapture : public ILog
{
public:
LogCapture(const LogSetting settings); // settings may it should add (*)?
virtual ~LogCapture() = default;
bool Init() override;
bool UnInit() override;
bool IsWorking() override;
int Log(const char *buff) override;
int InFo(const char *buff) override;
int Warning(const char *buff) override;
int Error(const char *buff) override;
int Trace(const char *buff) override;
int Debug(const char *buff) override;
private:
std::string mFileName; // File name of saving log.
std::string mMaxSize; // Max size of saving log.
const int (*mLogCapture)(const char *buff); // For other modules to capture what to print.
const int (*mLogCapture_InFo)(const char *buff);
const int (*mLogCapture_Warning)(const char *buff);
const int (*mLogCapture_Error)(const char *buff);
const int (*mLogCapture_Debug)(const char *buff);
const int (*mLogCapture_Trace)(const char *buff);
};
#endif

View File

@ -0,0 +1,89 @@
#include "LogEasylogging.h"
#include "easylogging++.h"
#include <thread>
// #define ELPP_UNICODE // Define for easylogging
INITIALIZE_EASYLOGGINGPP // Init easylogging
// static bool initFlag = false; // Only used for init easyloggingpp
bool test = false;
LogEasylogging::LogEasylogging(const LogSetting *setting)
{
if (!setting)
{
return;
}
if (setting->fileName)
{
mFileName = setting->fileName;
}
if (setting->maxSize)
{
mMaxSize = setting->maxSize;
}
}
bool LogEasylogging::Init()
{
#if 0
el::Configurations conf("/home/xiaojiazhu/project/OS/OSThings/test/out/bin/default-logger.conf");
el::Loggers::reconfigureAllLoggers(conf);
#endif
// Set the log path.
if (mFileName.size() > 0)
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, mFileName.c_str());
}
// Set the max size of log file.
// el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, "1048576");
if (mMaxSize.size() > 0)
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, mMaxSize.c_str());
}
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "true");
return true;
}
bool LogEasylogging::UnInit()
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "false");
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
return true;
}
bool LogEasylogging::IsWorking()
{
return true;
}
int LogEasylogging::Log(const char *buff)
{
// LOG(INFO) << buff;
return 0;
}
int LogEasylogging::InFo(const char *buff)
{
LOG(INFO) << buff;
return 0;
}
int LogEasylogging::Warning(const char *buff)
{
LOG(WARNING) << buff;
return 0;
}
int LogEasylogging::Error(const char *buff)
{
LOG(ERROR) << buff;
return 0;
}
int LogEasylogging::Debug(const char *buff)
{
LOG(DEBUG) << buff;
return 0;
}
int LogEasylogging::Trace(const char *buff)
{
LOG(TRACE) << buff;
return 0;
}

View File

@ -0,0 +1,24 @@
#ifndef LOG_EASYLOGGING_H
#define LOG_EASYLOGGING_H
#include "ILog.h"
#include "Log.h"
class LogEasylogging : public ILog
{
public:
LogEasylogging(const LogSetting *setting);
virtual ~LogEasylogging() = default;
bool Init() override;
bool UnInit() override;
bool IsWorking() override;
int Log(const char *buff) override;
int InFo(const char *buff) override;
int Warning(const char *buff) override;
int Error(const char *buff) override;
int Trace(const char *buff) override;
int Debug(const char *buff) override;
private:
std::string mFileName; // File name of saving log.
std::string mMaxSize; // Max size of saving log.
};
#endif

View File

@ -0,0 +1,9 @@
#include "LogImpl.h"
bool LogImpl::IsWorking()
{
return true;
}
int LogImpl::Log(const char *buff)
{
return printf("%s", buff);
}

12
utils/Log/src/LogImpl.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef LOG_IMPL_H
#define LOG_IMPL_H
#include "ILog.h"
class LogImpl : public ILog
{
public:
LogImpl() = default;
virtual ~LogImpl() = default;
bool IsWorking() override;
int Log(const char *buff) override;
};
#endif

View File

@ -0,0 +1,9 @@
这是一个开源库的源码。
注意:
//1. 需要定义宏
//#define ELPP_UNICODE // Define for easylogging
2. 初始化
INITIALIZE_EASYLOGGINGPP // Init easylogging
//3. 支持多线程,在源码头文件"easyloggingpp.h"定义宏
//#define ELPP_THREAD_SAFE // Working in threads. Added by xiaojiazhu
4. ELPP_NO_DEFAULT_LOG_FILE 此宏屏蔽生成默认的log文件

View File

@ -0,0 +1,25 @@
* GLOBAL:
FORMAT = "%datetime | %level | %logger | %msg"
FILENAME = "/tmp/logs/myeasylog-configuration.cpp.log"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
SUBSECOND_PRECISION = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 2097152 ## Throw log files away after 2MB
* DEBUG:
FILENAME = "/tmp/logs/myeasylog-configuration.cpp-debug.log"
TO_STANDARD_OUTPUT = true
ENABLED = true ## We will set it to false after development completed
* WARNING:
FILENAME = "/tmp/logs/filename-with-time-%datetime{%H:%m}"
* TRACE:
TO_FILE = true ## Unnecessary configuration cuz its already true in GLOBAL but doing it anyway!
* VERBOSE:
FORMAT = "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
## Error logs
* ERROR:
ENABLED = false
FILENAME = "/tmp/logs/myeasylog-configuration.cpp-error.log"
* FATAL:
ENABLED = false

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
${UTILS_SOURCE_PATH}/ReturnCode/include
${UTILS_SOURCE_PATH}/Log/include
)
#do not rely on any other library
#link_directories(
#)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(./src SRC_FILES)
set(TARGET_NAME ReturnCode)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
target_link_libraries(${TARGET_NAME} Log)

View File

@ -0,0 +1,28 @@
#ifndef RETURN_CODE_H
#define RETURN_CODE_H
enum C_RETURN_CODE
{
C_RETURN_CODE_OK = 0,
C_RETURN_CODE_NOT_OK,
C_RETURN_CODE_INVALID_PARAMENTER,
C_RETURN_CODE_END
};
typedef struct returnCodeC RETURN_CODE_C;
typedef struct returnCodeC
{
const char *(*printStringCode)(const RETURN_CODE_C);
const long int mCode;
} RETURN_CODE_C;
/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern "C"
{
#endif
const RETURN_CODE_C CreateReturnCode(const long int code);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,54 @@
#ifndef V_RETURN_CODE_H
#define V_RETURN_CODE_H
#include <iostream>
#include <memory>
/**
* @brief
* The base return code.
* Attention: VReturnCOdeDefineStr must be added one item when define one new code.
*/
enum class VReturnCodeDefine
{
OK = 0,
NOT_OK_UNDEFINE_REASON,
NOT_OK_VIRTUAL_FUNCTION,
MAKE_SHARED_PTR_FAILED,
END
};
class VReturnCode
{
protected:
VReturnCode(const int &code) : mCode(code)
{
}
public:
virtual ~VReturnCode() = default;
virtual const int GetIntCode() { return mCode; }
bool IsCodeOK();
/**
* @brief
* Print the code translate into a readable string.
* @return int
*/
virtual std::string PrintStringCode();
void SetTips(const std::string &tips) { mTips = tips; }
const std::string &GetTips() { return mTips; }
/**
* @brief
* Create a new return code, which is the only way to create a code shared ptr.
* @param code
* @return std::make_shared<VReturnCode>
*/
static std::shared_ptr<VReturnCode> NewCode(const VReturnCodeDefine &code);
private:
const int mCode; // Can't be reset.
std::string mTips; // Give some tips for return code, such as the not OK detail.
};
/**
* @brief
* Define the VReturnCode as shared ptr, which other modules can redefine VReturnCode.
*/
using RETURN_CODE = std::shared_ptr<VReturnCode>;
#endif

View File

@ -0,0 +1,35 @@
#include "ReturnCode.h"
#include "Log.h"
#include <stdio.h>
static const char *RETRUN_CODE_STRING[C_RETURN_CODE_END + 1]={
"C_RETURN_CODE_OK",
"C_RETURN_CODE_NOT_OK",
"C_RETURN_CODE_INVALID_PARAMENTER",
"C_RETURN_CODE_END"
};
static const char *PrintStringCode(const RETURN_CODE_C this)
{
if (C_RETURN_CODE_OK <= this.mCode && this.mCode <= C_RETURN_CODE_END)
{
LogInfo("Return code = [ %s ]\n", RETRUN_CODE_STRING[this.mCode]);
return RETRUN_CODE_STRING[this.mCode];
}
LogError("Return code = [ %s ]\n", RETRUN_CODE_STRING[C_RETURN_CODE_INVALID_PARAMENTER]);
return RETRUN_CODE_STRING[C_RETURN_CODE_INVALID_PARAMENTER];
}
const RETURN_CODE_C CreateReturnCode(const long int code)
{
if (C_RETURN_CODE_OK <= code && code <= C_RETURN_CODE_END)
{
RETURN_CODE_C result = {NULL, code};
result.printStringCode = PrintStringCode;
return result;
}
else
{
LogError("undefined code.\n");
RETURN_CODE_C result = {NULL, C_RETURN_CODE_INVALID_PARAMENTER};
result.printStringCode = PrintStringCode;
return result;
}
}

View File

@ -0,0 +1,44 @@
#include "VReturnCode.h"
#include "Log.h"
const std::string VReturnCOdeDefineStr[static_cast<int>(VReturnCodeDefine::END) + 1] = {
"OK",
"NOT_OK_UNDEFINE_REASON, undefine reason",
"NOT_OK_VIRTUAL_FUNCTION, do nothing function",
"MAKE_SHARED_PTR_FAILED, std::make_shared<T> failed",
"END"};
std::shared_ptr<VReturnCode> VReturnCode::NewCode(const VReturnCodeDefine &code)
{
// return std::make_shared<VReturnCode>(static_cast<int>(code));
class MakeShared : public VReturnCode
{
public:
MakeShared(const int &code) : VReturnCode(code) {}
};
return std::make_shared<MakeShared>(static_cast<int>(code));
}
bool VReturnCode::IsCodeOK()
{
bool result = mCode == static_cast<int>(VReturnCodeDefine::OK) ? true : false;
// if (!result)
// {
// PrintStringCode(); // Don't print code when run ok.
// }
return result;
}
std::string VReturnCode::PrintStringCode()
{
if (mCode < static_cast<long int>(VReturnCodeDefine::OK) || mCode > static_cast<long int>(VReturnCodeDefine::END))
{
LogError("Illegal code, cross the border.\n");
return "Illegal code.";
}
if (mCode > static_cast<long int>(VReturnCodeDefine::OK))
{
LogError("Return code:[ %s ]\n", VReturnCOdeDefineStr[mCode].c_str());
}
else
{
LogInfo("Return code:[ %s %s]\n", VReturnCOdeDefineStr[mCode].c_str(), GetTips().c_str());
}
return VReturnCOdeDefineStr[mCode];
}