From 4cf29418ad777d92dcac33c114707ac83dc91143 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Sat, 5 Jun 2021 14:14:54 +0200 Subject: [PATCH] fix --- CMakeModules/testing_cpp.cmake | 8 ++++++-- common/cpp/src/database/CMakeLists.txt | 2 +- common/cpp/src/database/encoding.cpp | 11 ++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake index 95364659d..413b20be1 100644 --- a/CMakeModules/testing_cpp.cmake +++ b/CMakeModules/testing_cpp.cmake @@ -105,8 +105,10 @@ function(gtest target test_source_files linktarget) set_tests_properties(test-${target} PROPERTIES LABELS "unit;all") message(STATUS "Added test 'test-${target}'") - - if (CMAKE_COMPILER_IS_GNUCXX) + if (ARGN) + LIST(GET ${ARGN} 0 NOCOV) + endif() + if (CMAKE_COMPILER_IS_GNUCXX AND NOT 1${NOCOV} STREQUAL "1nocov") set(COVERAGE_EXCLUDES "*/unittests/*" "*/3d_party/*" "*/python/*") if (ARGN) set(COVERAGE_EXCLUDES ${COVERAGE_EXCLUDES} ${ARGN}) @@ -116,6 +118,8 @@ function(gtest target test_source_files linktarget) COMMAND ${CMAKE_MODULE_PATH}/check_test.sh coverage-${target} ${CMAKE_BINARY_DIR} ${ASAPO_MINIMUM_COVERAGE}) set_tests_properties(coveragetest-${target} PROPERTIES LABELS "coverage;all") + message(STATUS "Added test 'test-${target}-coverage'") + SET_TESTS_PROPERTIES(coveragetest-${target} PROPERTIES DEPENDS test-${target}) set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) diff --git a/common/cpp/src/database/CMakeLists.txt b/common/cpp/src/database/CMakeLists.txt index 7de3686fd..eda63f850 100644 --- a/common/cpp/src/database/CMakeLists.txt +++ b/common/cpp/src/database/CMakeLists.txt @@ -27,5 +27,5 @@ set(TEST_SOURCE_FILES ../../unittests/database/test_encoding.cpp) set(TEST_LIBRARIES "${TARGET_NAME}") include_directories(${ASAPO_CXX_COMMON_INCLUDE_DIR}) -gtest(${TARGET_NAME} "${TEST_SOURCE_FILES}" "${TEST_LIBRARIES}" "*mongodb_client*" "*database.*") +gtest(${TARGET_NAME} "${TEST_SOURCE_FILES}" "${TEST_LIBRARIES}" "nocov") diff --git a/common/cpp/src/database/encoding.cpp b/common/cpp/src/database/encoding.cpp index c8cf596f0..0ce365ea2 100644 --- a/common/cpp/src/database/encoding.cpp +++ b/common/cpp/src/database/encoding.cpp @@ -85,9 +85,14 @@ std::string EncodeColName(const std::string &colname) { } std::string DecodeName(const std::string &name) { - std::unique_ptr<char>decoded{new char(name.size())}; - auto res = decode(name.c_str(), decoded.get()); - return res >= 0 ? decoded.get() : ""; + char* decoded = new char[name.size() + 1]; + auto res = decode(name.c_str(), decoded); + if (res < 0) { + return ""; + } + std::string str = std::string{decoded}; + delete[] decoded; + return str; } bool ShouldEscapeQuery(char c) { -- GitLab