diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake index 711bc3e7a829a5da8a278391a18324e5e8debe4a..08b832cd57bf3f0ade824eef38ab6268f0e35506 100644 --- a/CMakeModules/testing_cpp.cmake +++ b/CMakeModules/testing_cpp.cmake @@ -36,8 +36,6 @@ function(gtest target test_source_files linktarget) ENDIF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug") target_link_libraries(test-${target} ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT}) - - add_test(NAME test-${target} COMMAND test-${target}) set_tests_properties(test-${target} PROPERTIES LABELS "unit;all") @@ -46,7 +44,7 @@ function(gtest target test_source_files linktarget) if (CMAKE_COMPILER_IS_GNUCXX) include(CodeCoverage) APPEND_COVERAGE_COMPILER_FLAGS() - set(COVERAGE_EXCLUDES '*/unittests/*') + set(COVERAGE_EXCLUDES "*/unittests/*" "*/3d_party/*" ) if (ARGN) set(COVERAGE_EXCLUDES ${COVERAGE_EXCLUDES} ${ARGN}) endif() diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt index 31a9b4afbdbb28dd7769807ffbe05968e5723d8d..288ffe42cafe4dfd30f188059f397715870dd2ba 100644 --- a/common/cpp/CMakeLists.txt +++ b/common/cpp/CMakeLists.txt @@ -2,8 +2,6 @@ add_subdirectory(src/system_io) add_subdirectory(src/data_structs) -add_subdirectory(unittests/data_structs) - if(BUILD_MONGODB_CLIENTLIB) add_subdirectory(src/database) diff --git a/common/cpp/include/unittests/MockIO.h b/common/cpp/include/unittests/MockIO.h index 036da76928f027c5325a30de46167b6a3f9ab1a8..d739483fad6d14d0ad87007822a5cee5d8556cdf 100644 --- a/common/cpp/include/unittests/MockIO.h +++ b/common/cpp/include/unittests/MockIO.h @@ -11,7 +11,7 @@ namespace hidra2 { class MockIO : public IO { public: FileData GetDataFromFile(const std::string& fname, uint64_t fsize, IOErrors* err) const noexcept override { - return GetDataFromFile_t(fname, fsize, err); + return FileData{GetDataFromFile_t(fname, fsize, err)}; } int open(const char* __file, int __oflag) const noexcept override { return 0; @@ -24,7 +24,7 @@ class MockIO : public IO { } MOCK_CONST_METHOD3(GetDataFromFile_t, - FileData(const std::string& fname, uint64_t fsize, IOErrors* err)); + uint8_t*(const std::string& fname, uint64_t fsize, IOErrors* err)); MOCK_CONST_METHOD2(FilesInFolder, FileInfos( const std::string& folder, IOErrors diff --git a/common/cpp/src/data_structs/CMakeLists.txt b/common/cpp/src/data_structs/CMakeLists.txt index 06e9c41d6a82ba190567d39c817f7cbef7503b3d..617f5c89bfc19624534c9a28958aa8e922beeb54 100644 --- a/common/cpp/src/data_structs/CMakeLists.txt +++ b/common/cpp/src/data_structs/CMakeLists.txt @@ -10,3 +10,13 @@ set(SOURCE_FILES add_library(${TARGET_NAME} OBJECT ${SOURCE_FILES}) target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/3d_party/rapidjson/include) + +################################ +# Testing +################################ +set(TEST_SOURCE_FILES ../../unittests/data_structs/test_data_structs.cpp) + +set(TEST_LIBRARIES "${TARGET_NAME}") +include_directories(${HIDRA2_CXX_COMMON_INCLUDE_DIR}) +gtest(${TARGET_NAME} "${TEST_SOURCE_FILES}" "${TEST_LIBRARIES}") + diff --git a/common/cpp/src/data_structs/data_structs.cpp b/common/cpp/src/data_structs/data_structs.cpp index 672a8f70eab0b2d3f3c6c50147da5e2901d944f1..9cde1a4a535d05058ce9d90a259df33ad914e9e7 100644 --- a/common/cpp/src/data_structs/data_structs.cpp +++ b/common/cpp/src/data_structs/data_structs.cpp @@ -36,8 +36,10 @@ bool TimeFromJson(const Document& d, const std::string name, std::chrono::system return false; } - *val = std::chrono::time_point<std::chrono::system_clock> - (std::chrono::nanoseconds(nanoseconds_from_epoch)); + std::chrono::nanoseconds ns = std::chrono::nanoseconds {nanoseconds_from_epoch}; + *val = std::chrono::system_clock::time_point + {std::chrono::duration_cast<std::chrono::system_clock::duration>(ns)}; + return true; } diff --git a/common/cpp/unittests/data_structs/CMakeLists.txt b/common/cpp/unittests/data_structs/CMakeLists.txt deleted file mode 100644 index 7e6630f62f553d5b34c9d856d9df2c7f712feb44..0000000000000000000000000000000000000000 --- a/common/cpp/unittests/data_structs/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(TARGET_NAME data_structs) - - -################################ -# Testing -################################ -set(TEST_SOURCE_FILES test_data_structs.cpp) - -set(TEST_LIBRARIES "${TARGET_NAME}") -include_directories(${HIDRA2_CXX_COMMON_INCLUDE_DIR}) -gtest(${TARGET_NAME} "${TEST_SOURCE_FILES}" "${TEST_LIBRARIES}") - diff --git a/worker/api/cpp/src/server_data_broker.cpp b/worker/api/cpp/src/server_data_broker.cpp index 0cb79fa3758f49223646bbe16faa29451379ae86..ee712f8e07f47b65e91a0c9977ba646f396031fa 100644 --- a/worker/api/cpp/src/server_data_broker.cpp +++ b/worker/api/cpp/src/server_data_broker.cpp @@ -32,18 +32,18 @@ WorkerErrorCode ServerDataBroker::GetNext(FileInfo* info, FileData* data) { return WorkerErrorCode::kErrorReadingSource; } - if (info!= nullptr){ + if (info != nullptr) { *info = file_info; } - if (data == nullptr){ + if (data == nullptr) { return WorkerErrorCode::kOK; } IOErrors ioerr; *data = io__->GetDataFromFile(file_info.relative_path + (file_info.relative_path.empty() ? "" : "/") + - file_info.base_name, file_info.size, &ioerr); + file_info.base_name, file_info.size, &ioerr); return hidra2::MapIOError(ioerr); } diff --git a/worker/api/cpp/unittests/test_server_broker.cpp b/worker/api/cpp/unittests/test_server_broker.cpp index 1a23afd07f8faaa3980db7bb52ecce8e36953eb1..f9cbca9a499c31796df680b3c81846f74451b195 100644 --- a/worker/api/cpp/unittests/test_server_broker.cpp +++ b/worker/api/cpp/unittests/test_server_broker.cpp @@ -72,15 +72,16 @@ TEST_F(ServerDataBrokerTests, GetNextReturnsErrorOnWrongInput) { } TEST_F(ServerDataBrokerTests, GetNextUsesCorrectUri) { - EXPECT_CALL(mock_http_client, Get("test/next?database=database", _)); + EXPECT_CALL(mock_http_client, Get("test/next?database=database", _)).WillOnce(DoAll( + SetArgPointee<1>(WorkerErrorCode::kOK), + Return(""))); data_broker->GetNext(&info, nullptr); } TEST_F(ServerDataBrokerTests, GetNextReturnsErrorFromHttpClient) { EXPECT_CALL(mock_http_client, Get(_, _)).WillOnce(DoAll( SetArgPointee<1>(WorkerErrorCode::kSourceNotFound), - Return("") - )); + Return(""))); auto err = data_broker->GetNext(&info, nullptr); @@ -88,7 +89,7 @@ TEST_F(ServerDataBrokerTests, GetNextReturnsErrorFromHttpClient) { } -FileInfo CreateFI(){ +FileInfo CreateFI() { FileInfo fi; fi.size = 100; fi.id = 1; @@ -99,7 +100,7 @@ FileInfo CreateFI(){ } TEST_F(ServerDataBrokerTests, GetNextReturnsFileInfo) { - auto to_send =CreateFI(); + auto to_send = CreateFI(); auto json = to_send.Json(); EXPECT_CALL(mock_http_client, Get(_, _)).WillOnce(DoAll( SetArgPointee<1>(WorkerErrorCode::kOK), @@ -142,15 +143,16 @@ TEST_F(ServerDataBrokerTests, GetNextReturnsIfNoDtataNeeded) { TEST_F(ServerDataBrokerTests, GetNextCallsReadFromFile) { - auto to_send =CreateFI(); + auto to_send = CreateFI(); auto json = to_send.Json(); EXPECT_CALL(mock_http_client, Get(_, _)).WillOnce(DoAll( - SetArgPointee<1>(WorkerErrorCode::kOK), - Return(json))); + SetArgPointee<1>(WorkerErrorCode::kOK), + Return(json))); - EXPECT_CALL(mock_io, GetDataFromFile_t("relative_path/base_name",100, _)); + EXPECT_CALL(mock_io, GetDataFromFile_t("relative_path/base_name", 100, _)). + WillOnce(DoAll(SetArgPointee<2>(IOErrors::kReadError), testing::Return(nullptr))); FileData data; data_broker->GetNext(&info, &data);