Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aligned cmake built system with recommendations in googletest docs (#415
) * Aligned cmake built system with recommendations in googletest docs * Copied etc/vzlogger.conf to build directory for testing. Path in test is relative to build dir * Changed working directory of test to build dir * Added cmake command to copy missing images for OCR Test to build dir * Added constructor accepting a std::string as value to class Options * * Made tests independent from working directory upon execution * Fixed some 'dirty hacks' by moving object dependencies from test sources to cmake script * Changed design to collect all variable path names in a single header file in tests/include * Added missing source file * Fixed some build errors caused by missing source files. * * Fixed missing path delimiter in path generator for OCR sample files * renamed test helper pathTo to ocrTestImage * Fixed coding style with clang-format * Beautified CMakeLists files (with tabs\!)
- Loading branch information
Showing
13 changed files
with
222 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 2.8.2) | ||
|
||
project(gtest-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(googletest | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG master | ||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/gtest-src" | ||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/gtest-build" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,108 @@ | ||
include_directories( | ||
${GMOCK_INCLUDE_DIRS} | ||
${GTEST_INCLUDE_DIRS} | ||
) | ||
|
||
# all *.cpp files here will be used. | ||
file(GLOB test_sources *.cpp) | ||
if(NOT SML_FOUND) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/MeterSML.cpp) | ||
endif(NOT SML_FOUND) | ||
|
||
# remove meterOCR.cpp if not defined | ||
if( NOT OCR_SUPPORT ) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/ut_MeterOCR.cpp) | ||
endif( NOT OCR_SUPPORT) | ||
|
||
if( NOT OCR_TESSERACT_SUPPORT ) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/ut_MeterOCRTesseract.cpp) | ||
endif( NOT OCR_TESSERACT_SUPPORT) | ||
|
||
|
||
if( NOT ENABLE_SML ) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/MeterSML.cpp) | ||
endif( NOT ENABLE_SML) | ||
|
||
if(ENABLE_MQTT) | ||
set(MQTT_SOURCES ../src/mqtt.cpp) | ||
else(ENABLE_MQTT) | ||
set(MQTT_SOURCES "") | ||
endif(ENABLE_MQTT) | ||
|
||
if( OMS_SUPPORT ) | ||
set(oms_sources ../src/protocols/MeterOMS.cpp) | ||
elseif( OMS_SUPPORT ) | ||
set(oms_sources "") | ||
endif( OMS_SUPPORT ) | ||
|
||
add_executable(vzlogger_unit_tests ${test_sources} ../src/CurlSessionProvider.cpp ../src/protocols/MeterW1therm.cpp ${oms_sources} ${MQTT_SOURCES}) | ||
|
||
add_dependencies(vzlogger_unit_tests googlemock) | ||
# add required source files | ||
list(APPEND test_sources | ||
../src/Buffer.cpp | ||
../src/Channel.cpp | ||
../src/Config_Options.cpp | ||
../src/api/Volkszaehler.cpp | ||
../src/CurlSessionProvider.cpp | ||
../src/protocols/MeterW1therm.cpp | ||
) | ||
|
||
target_link_libraries(vzlogger_unit_tests | ||
${GTEST_LIBS_DIR}/libgtest.a | ||
${GMOCK_LIBS_DIR}/libgmock.a | ||
set(test_libraries | ||
gtest | ||
gmock | ||
${JSON_LIBRARY} | ||
${LIBUUID} | ||
dl | ||
pthread) | ||
target_link_libraries(vzlogger_unit_tests ${CURL_STATIC_LIBRARIES} ${CURL_LIBRARIES} unistring ${GNUTLS_LIBRARIES} ${OCR_LIBRARIES}) | ||
|
||
if( OMS_SUPPORT ) | ||
target_link_libraries(vzlogger_unit_tests ${MBUS_LIBRARY} ${OPENSSL_LIBRARIES}) | ||
endif( OMS_SUPPORT ) | ||
pthread | ||
${CURL_STATIC_LIBRARIES} | ||
${CURL_LIBRARIES} | ||
unistring | ||
${GNUTLS_LIBRARIES} | ||
${OCR_LIBRARIES} | ||
) | ||
|
||
if(SML_FOUND) | ||
target_link_libraries(vzlogger_unit_tests ${SML_LIBRARY}) | ||
endif(SML_FOUND) | ||
if(SML_FOUND AND ENABLE_SML) | ||
list(APPEND test_sources ../src/protocols/MeterSML.cpp) | ||
list(APPEND test_libraries ${SML_LIBRARY}) | ||
else(SML_FOUND AND ENABLE_SML) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/MeterSML.cpp) | ||
endif(SML_FOUND AND ENABLE_SML) | ||
|
||
if(OCR_SUPPORT) | ||
list(APPEND test_sources ../src/protocols/MeterOCR.cpp) | ||
else(OCR_SUPPORT) | ||
list(REMOVE_ITEM test_sources ${CMAKE_CURRENT_SOURCE_DIR}/ut_MeterOCR.cpp) | ||
endif(OCR_SUPPORT) | ||
|
||
if(OCR_TESSERACT_SUPPORT) | ||
list(APPEND test_sources ../src/protocols/MeterOCR.cpp) | ||
else(OCR_TESSERACT_SUPPORT) | ||
list(REMOVE_ITEM test_sources | ||
${CMAKE_CURRENT_SOURCE_DIR}/ut_MeterOCRTesseract.cpp) | ||
endif(OCR_TESSERACT_SUPPORT) | ||
|
||
if(ENABLE_MQTT) | ||
target_link_libraries(vzlogger_unit_tests ${MQTT_LIBRARY}) | ||
list(APPEND test_sources ../src/mqtt.cpp) | ||
list(APPEND test_libraries ${MQTT_LIBRARY}) | ||
endif(ENABLE_MQTT) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") | ||
|
||
add_subdirectory(mocks) | ||
|
||
FIND_PROGRAM( GCOV_PATH gcov ) | ||
FIND_PROGRAM( LCOV_PATH lcov ) | ||
FIND_PROGRAM( GENHTML_PATH genhtml ) | ||
|
||
IF(GCOV_PATH AND LCOV_PATH AND GENHTML_PATH) | ||
MESSAGE("gcov found. Adding target test_coverage ...") | ||
if(OMS_SUPPORT) | ||
list(APPEND test_sources ../src/protocols/MeterOMS.cpp) | ||
list(APPEND test_libraries ${MBUS_LIBRARY} ${OPENSSL_LIBRARIES}) | ||
endif(OMS_SUPPORT) | ||
|
||
# Setup target for coverage | ||
# we need to add each single test binary into the command list | ||
add_executable(vzlogger_unit_tests ${test_sources}) | ||
target_link_libraries(vzlogger_unit_tests ${test_libraries}) | ||
|
||
ADD_CUSTOM_TARGET(test_coverage | ||
|
||
# Cleanup lcov | ||
${LCOV_PATH} --rc lcov_branch_coverage=1 --directory . --zerocounters | ||
|
||
# Run tests | ||
COMMAND vzlogger_unit_tests | ||
COMMAND mock_metermap | ||
COMMAND mock_MeterW1therm | ||
COMMAND mock_MeterOMS | ||
COMMAND mock_MeterS0 | ||
configure_file(include/test_config.hpp.in include/test_config.hpp) | ||
target_include_directories(vzlogger_unit_tests | ||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include | ||
) | ||
|
||
# Capturing lcov counters and generating report | ||
COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory . --capture --output-file coverage.info | ||
COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --remove coverage.info 'tests/*' '/usr/*' --output-file coverage.info.cleaned | ||
COMMAND ${GENHTML_PATH} --rc lcov_branch_coverage=1 -o coverage coverage.info.cleaned | ||
COMMAND ${CMAKE_COMMAND} -E remove coverage.info coverage.info.cleaned | ||
|
||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." | ||
) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") | ||
|
||
# Show info where to find the report | ||
ADD_CUSTOM_COMMAND(TARGET test_coverage POST_BUILD | ||
COMMAND ; | ||
COMMENT "Open ./coverage/index.html in your browser to view the coverage report." | ||
) | ||
add_subdirectory(mocks) | ||
|
||
ENDIF() # NOT GCOV_PATH | ||
FIND_PROGRAM(GCOV_PATH gcov) | ||
FIND_PROGRAM(LCOV_PATH lcov) | ||
FIND_PROGRAM(GENHTML_PATH genhtml) | ||
|
||
IF(GCOV_PATH AND LCOV_PATH AND GENHTML_PATH) | ||
MESSAGE("gcov found. Adding target test_coverage ...") | ||
|
||
# Setup target for coverage | ||
# we need to add each single test binary into the command list | ||
|
||
ADD_CUSTOM_TARGET(test_coverage | ||
# Cleanup lcov | ||
${LCOV_PATH} --rc lcov_branch_coverage=1 --directory . --zerocounters | ||
# Run tests | ||
COMMAND vzlogger_unit_tests | ||
COMMAND mock_metermap | ||
COMMAND mock_MeterW1therm | ||
COMMAND mock_MeterOMS | ||
COMMAND mock_MeterS0 | ||
|
||
# Capturing lcov counters and generating report | ||
COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory . --capture --output-file coverage.info | ||
COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --remove coverage.info 'tests/*' '/usr/*' --output-file coverage.info.cleaned | ||
COMMAND ${GENHTML_PATH} --rc lcov_branch_coverage=1 -o coverage coverage.info.cleaned | ||
COMMAND ${CMAKE_COMMAND} -E remove coverage.info coverage.info.cleaned | ||
|
||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." | ||
) | ||
|
||
# Show info where to find the report | ||
ADD_CUSTOM_COMMAND(TARGET test_coverage POST_BUILD | ||
COMMAND ; | ||
COMMENT "Open ./coverage/index.html in your browser to view the coverage report." | ||
) | ||
|
||
ENDIF(GCOV_PATH AND LCOV_PATH AND GENHTML_PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef TEST_CONFIG_HPP | ||
#define TEST_CONFIG_HPP | ||
|
||
#include<string> | ||
|
||
inline std::string ocrTestImage(const char* file) { | ||
return std::string("@CMAKE_SOURCE_DIR@/tests/meterOCR/") + file; | ||
} | ||
|
||
inline constexpr const char* config_file() { | ||
return "@CMAKE_SOURCE_DIR@/etc/vzlogger.conf"; | ||
} | ||
|
||
|
||
#endif // TEST_CONFIG_HPP |
Oops, something went wrong.