From c5f6aa360c11248de1907d551ab88d77653cc87b Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Mon, 3 Sep 2018 14:08:33 +0200 Subject: [PATCH] fix windows tests --- common/cpp/include/io/io.h | 2 +- common/cpp/include/unittests/MockIO.h | 6 +++--- common/cpp/src/system_io/system_io.cpp | 2 +- common/cpp/src/system_io/system_io.h | 3 ++- common/cpp/src/system_io/system_io_windows.cpp | 2 +- producer/api/unittests/test_producer_impl.cpp | 2 +- producer/event_monitor_producer/src/main_eventmon.cpp | 6 ++++-- .../src/system_folder_watch_windows.cpp | 4 ++-- .../src/system_folder_watch_windows.h | 6 ++++-- .../automatic/system_io/read_subdirectories/CMakeLists.txt | 2 +- .../automatic/system_io/write_data_to_file/CMakeLists.txt | 7 ++++++- 11 files changed, 26 insertions(+), 16 deletions(-) diff --git a/common/cpp/include/io/io.h b/common/cpp/include/io/io.h index 5e281bedb..6d5c7e5c8 100644 --- a/common/cpp/include/io/io.h +++ b/common/cpp/include/io/io.h @@ -90,7 +90,7 @@ class IO { virtual size_t Read (FileDescriptor fd, void* buf, size_t length, Error* err) const = 0; virtual size_t Write (FileDescriptor fd, const void* buf, size_t length, Error* err) const = 0; - virtual Error DeleteFile(const std::string& fname) const = 0; + virtual Error RemoveFile(const std::string& fname) const = 0; virtual Error WriteDataToFile (const std::string& root_folder, const std::string& fname, const FileData& data, size_t length, bool create_directories) const = 0; virtual Error WriteDataToFile (const std::string& root_folder, const std::string& fname, const uint8_t* data, diff --git a/common/cpp/include/unittests/MockIO.h b/common/cpp/include/unittests/MockIO.h index a4b590bbf..2e374027c 100644 --- a/common/cpp/include/unittests/MockIO.h +++ b/common/cpp/include/unittests/MockIO.h @@ -179,7 +179,7 @@ class MockIO : public IO { } - MOCK_CONST_METHOD1(DeleteFile_t, ErrorInterface * (const std::string& fname)); + MOCK_CONST_METHOD1(RemoveFile_t, ErrorInterface * (const std::string& fname)); Error WriteDataToFile(const std::string& root_folder, const std::string& fname, const uint8_t* data, size_t length, bool create_directories) const override { @@ -187,8 +187,8 @@ class MockIO : public IO { } - Error DeleteFile(const std::string& fname) const override { - return Error{DeleteFile_t(fname)}; + Error RemoveFile(const std::string& fname) const override { + return Error{RemoveFile_t(fname)}; } diff --git a/common/cpp/src/system_io/system_io.cpp b/common/cpp/src/system_io/system_io.cpp index 97cef0e86..b49387696 100644 --- a/common/cpp/src/system_io/system_io.cpp +++ b/common/cpp/src/system_io/system_io.cpp @@ -601,7 +601,7 @@ Error SystemIO::CreateDirectoryWithParents(const std::string& root_path, const s return nullptr; } -Error SystemIO::DeleteFile(const std::string& fname) const { +Error SystemIO::RemoveFile(const std::string& fname) const { if(remove(fname.c_str()) == 0) { return nullptr;; } else { diff --git a/common/cpp/src/system_io/system_io.h b/common/cpp/src/system_io/system_io.h index ffcdbc305..314eb74ca 100644 --- a/common/cpp/src/system_io/system_io.h +++ b/common/cpp/src/system_io/system_io.h @@ -110,7 +110,8 @@ class SystemIO final : public IO { size_t length, bool create_directories) const override; SubDirList GetSubDirectories(const std::string& path, Error* err) const override; std::string ReadFileToString(const std::string& fname, Error* err) const override; - Error DeleteFile(const std::string& fname) const override; + Error RemoveFile(const std::string& fname) const override; + }; } diff --git a/common/cpp/src/system_io/system_io_windows.cpp b/common/cpp/src/system_io/system_io_windows.cpp index 506356067..918161d79 100644 --- a/common/cpp/src/system_io/system_io_windows.cpp +++ b/common/cpp/src/system_io/system_io_windows.cpp @@ -154,7 +154,7 @@ void ProcessFileEntity(const WIN32_FIND_DATA& f, const std::string& path, files->push_back(file_info); } -void GetSubDirectoriesRecursively(const std::string& path, SubDirList* subdirs, Error* err) const { +void SystemIO::GetSubDirectoriesRecursively(const std::string& path, SubDirList* subdirs, Error* err) const { WIN32_FIND_DATA find_data; HANDLE handle = FindFirstFile((path + "\\*.*").c_str(), &find_data); if (handle == INVALID_HANDLE_VALUE) { diff --git a/producer/api/unittests/test_producer_impl.cpp b/producer/api/unittests/test_producer_impl.cpp index 0d922f238..bfb2c164f 100644 --- a/producer/api/unittests/test_producer_impl.cpp +++ b/producer/api/unittests/test_producer_impl.cpp @@ -34,7 +34,7 @@ MATCHER_P5(M_CheckSendDataRequest, op_code, beamtime_id, file_id, file_size, mes "Checks if a valid GenericRequestHeader was Send") { return ((asapo::GenericRequestHeader)(arg->header)).op_code == op_code && ((asapo::GenericRequestHeader)(arg->header)).data_id == file_id - && ((asapo::GenericRequestHeader)(arg->header)).data_size == uint(file_size) + && ((asapo::GenericRequestHeader)(arg->header)).data_size == uint64_t(file_size) && arg->beamtime_id == beamtime_id && strcmp(((asapo::GenericRequestHeader)(arg->header)).message, message) == 0; } diff --git a/producer/event_monitor_producer/src/main_eventmon.cpp b/producer/event_monitor_producer/src/main_eventmon.cpp index 6948e3174..e2ff71129 100644 --- a/producer/event_monitor_producer/src/main_eventmon.cpp +++ b/producer/event_monitor_producer/src/main_eventmon.cpp @@ -57,7 +57,7 @@ void ProcessAfterSend(asapo::GenericRequestHeader header, asapo::Error err) { } auto config = GetEventMonConfig(); std::string fname = config->root_monitored_folder + asapo::kPathSeparator + header.message; - auto error = io->DeleteFile(fname); + auto error = io->RemoveFile(fname); if (error) { const auto logger = asapo::GetDefaultEventMonLogger(); logger->Error("cannot delete file: " + fname + "" + error->Explain()); @@ -82,7 +82,9 @@ int main (int argc, char* argv[]) { stop_signal = 0; std::signal(SIGINT, SignalHandler); std::signal(SIGTERM, SignalHandler); - siginterrupt(SIGINT, 1); + #if defined(__linux__) || defined (__APPLE__) + siginterrupt(SIGINT, 1); + #endif const auto logger = asapo::GetDefaultEventMonLogger(); logger->SetLogLevel(GetEventMonConfig()->log_level); diff --git a/producer/event_monitor_producer/src/system_folder_watch_windows.cpp b/producer/event_monitor_producer/src/system_folder_watch_windows.cpp index b4e699f37..c721862cd 100644 --- a/producer/event_monitor_producer/src/system_folder_watch_windows.cpp +++ b/producer/event_monitor_producer/src/system_folder_watch_windows.cpp @@ -7,8 +7,8 @@ Error SystemFolderWatch::StartFolderMonitor(const std::string& root_folder, return nullptr; } -FileEvents SystemFolderWatch::GetFileEventList(Error* err) { - FileEvents events; +FilesToSend SystemFolderWatch::GetFileList(Error* err) { + FilesToSend events; *err = nullptr; return events; } diff --git a/producer/event_monitor_producer/src/system_folder_watch_windows.h b/producer/event_monitor_producer/src/system_folder_watch_windows.h index a271964d6..2cfe53a85 100644 --- a/producer/event_monitor_producer/src/system_folder_watch_windows.h +++ b/producer/event_monitor_producer/src/system_folder_watch_windows.h @@ -8,14 +8,16 @@ #include "preprocessor/definitions.h" #include "asapo_producer.h" #include "common.h" +#include "io/io.h" namespace asapo { class SystemFolderWatch { public: - VIRTUAL Error StartFolderMonitor(const std::vector<std::string>& monitored_folders); - VIRTUAL FileEvents GetFileEventList(Error* err); + VIRTUAL Error StartFolderMonitor(const std::string& root_folder, + const std::vector<std::string>& monitored_folders); + VIRTUAL FilesToSend GetFileList(Error* err); }; } diff --git a/tests/automatic/system_io/read_subdirectories/CMakeLists.txt b/tests/automatic/system_io/read_subdirectories/CMakeLists.txt index 57de0e923..f73702922 100644 --- a/tests/automatic/system_io/read_subdirectories/CMakeLists.txt +++ b/tests/automatic/system_io/read_subdirectories/CMakeLists.txt @@ -21,7 +21,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) add_test_setup_cleanup(${TARGET_NAME}) IF(WIN32) - add_integration_test(${TARGET_NAME} list_folders "test test\\subtest3test\\subtest3\\subtest4test\\subtest1test\\subtest1\\subtest2") + add_integration_test(${TARGET_NAME} list_folders "test test\\subtest1test\\subtest1\\subtest2test\\subtest3test\\subtest3\\subtest4") ELSE() add_integration_test(${TARGET_NAME} list_folders "test test/subtest3test/subtest3/subtest4test/subtest1test/subtest1/subtest2") ENDIF(WIN32) diff --git a/tests/automatic/system_io/write_data_to_file/CMakeLists.txt b/tests/automatic/system_io/write_data_to_file/CMakeLists.txt index dcb279d36..d10f4fcee 100644 --- a/tests/automatic/system_io/write_data_to_file/CMakeLists.txt +++ b/tests/automatic/system_io/write_data_to_file/CMakeLists.txt @@ -15,7 +15,12 @@ set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) ################################ add_test_setup_cleanup(${TARGET_NAME}) add_integration_test(${TARGET_NAME} writeok "test_file ok dummy" nomem) -add_integration_test(${TARGET_NAME} writewithfolder "folder/a/b/c/d/test_file ok dummy" nomem) +if (UNIX) + add_integration_test(${TARGET_NAME} writewithfolder "folder/a/b/c/d/test_file ok dummy" nomem) +else () + add_integration_test(${TARGET_NAME} writewithfolder "folder\\a\\b\\c\\d\\test_file ok dummy" nomem) +endif() + add_integration_test(${TARGET_NAME} writetwice "test_file ok dummy" nomem) add_integration_test(${TARGET_NAME} dirnoaccess "test_noaccess/test_file error Permissiondenied:test_noaccess/test_file" nomem) -- GitLab