From 8014e68cabd004e0e680ab810555a0c04d20d342 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Mon, 29 Jan 2018 18:41:26 +0100
Subject: [PATCH] fix

---
 CMakeModules/testing_cpp.cmake                |  4 +---
 common/cpp/CMakeLists.txt                     |  2 --
 common/cpp/include/unittests/MockIO.h         |  4 ++--
 common/cpp/src/data_structs/CMakeLists.txt    | 10 ++++++++++
 common/cpp/src/data_structs/data_structs.cpp  |  6 ++++--
 .../cpp/unittests/data_structs/CMakeLists.txt | 12 -----------
 worker/api/cpp/src/server_data_broker.cpp     |  6 +++---
 .../api/cpp/unittests/test_server_broker.cpp  | 20 ++++++++++---------
 8 files changed, 31 insertions(+), 33 deletions(-)
 delete mode 100644 common/cpp/unittests/data_structs/CMakeLists.txt

diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake
index 711bc3e7a..08b832cd5 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 31a9b4afb..288ffe42c 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 036da7692..d739483fa 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 06e9c41d6..617f5c89b 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 672a8f70e..9cde1a4a5 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 7e6630f62..000000000
--- 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 0cb79fa37..ee712f8e0 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 1a23afd07..f9cbca9a4 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);
-- 
GitLab