From 129e12fd979ae1d2b37cbafdd94fda3899e972d9 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 22 Oct 2018 11:21:18 +0200 Subject: [PATCH] moved test framework --- .clang-format | 6 +++++- CMakeLists.txt | 6 +++++- .../multiSlsDetector/multiSlsDetector.cpp | 9 +++++---- {slsSupportLib => tests}/CMakeLists.txt | 20 ++++++++++--------- .../src}/test-container_utils.cpp | 0 tests/src/test-multiDetector.cpp | 11 ++++++++++ {slsSupportLib/tests => tests/src}/test.cpp | 0 7 files changed, 37 insertions(+), 15 deletions(-) rename {slsSupportLib => tests}/CMakeLists.txt (74%) rename {slsSupportLib/tests => tests/src}/test-container_utils.cpp (100%) create mode 100644 tests/src/test-multiDetector.cpp rename {slsSupportLib/tests => tests/src}/test.cpp (100%) diff --git a/.clang-format b/.clang-format index 5bf2f83a8..b6bcb71ce 100644 --- a/.clang-format +++ b/.clang-format @@ -1,2 +1,6 @@ BasedOnStyle: LLVM -IndentWidth: 4 \ No newline at end of file +IndentWidth: 4 + +UseTab: Never +ColumnLimit: 0 +AlignConsecutiveAssignments: false \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7373a7ea2..8f64cfd1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ option (USE_HDF5 "HDF5 File format" OFF) option (USE_TEXTCLIENT "Text Client" OFF) option (USE_RECEIVER "Receiver" OFF) option (USE_GUI "GUI" OFF) - +option (USE_TESTS "TESTS" ON) if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -Wno-misleading-indentation") @@ -70,5 +70,9 @@ if (CALIBRATE) endif() endif(CALIBRATE) +if (USE_TESTS) + add_subdirectory(tests) +endif(USE_TESTS) + install(FILES ${ZMQ_STATIC_ARCHIVE} DESTINATION lib) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 98eee7127..e4526d374 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -20,9 +20,9 @@ //#include //clock() #include "container_utils.h" +#include #include #include -#include multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) : detId(id), sharedMemory(0), thisMultiDetector(0), @@ -597,7 +597,8 @@ void multiSlsDetector::setDetectorOffset(dimension d, int off, int detPos) { void multiSlsDetector::updateOffsets() { // cannot paralllize due to slsdetector calling this via parentdet-> #ifdef VERBOSE - std::cout << std::endl << "Updating Multi-Detector Offsets" << std::endl; + std::cout << std::endl + << "Updating Multi-Detector Offsets" << std::endl; #endif int offsetX = 0, offsetY = 0, numX = 0, numY = 0; int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X]; @@ -3727,8 +3728,8 @@ void multiSlsDetector::processData() { if (getJoinThreadFlag()) { break; } - //otherwise error when connecting to the receiver too fast - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // otherwise error when connecting to the receiver too fast + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } } diff --git a/slsSupportLib/CMakeLists.txt b/tests/CMakeLists.txt similarity index 74% rename from slsSupportLib/CMakeLists.txt rename to tests/CMakeLists.txt index a6ae2077f..a75a89e5a 100644 --- a/slsSupportLib/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,28 +1,30 @@ MESSAGE( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} ) MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} ) -# set(SOURCES -# slsDetectorClient.cpp -# ) + include_directories( - include - tests ${PROJECT_SOURCE_DIR}/catch + ${PROJECT_SOURCE_DIR}/slsSupportLib/include + ${PROJECT_SOURCE_DIR}/slsDetectorSoftware/multiSlsDetector ) if(USE_TESTS) - set(LOCAL_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) + set(LOCAL_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(TEST_SOURCES - # ${BASE_TEST_DIR}/test-MultiDetectorCaller.cpp ${LOCAL_TEST_DIR}/test-container_utils.cpp + ${LOCAL_TEST_DIR}/test-multiDetector.cpp ${LOCAL_TEST_DIR}/test.cpp # PARENT_SCOPE ) - add_executable(t2 ${TEST_SOURCES}) - set_target_properties(t2 PROPERTIES + add_executable(test ${TEST_SOURCES}) + target_link_libraries(test + slsDetectorShared + pthread + ) + set_target_properties(test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) endif() diff --git a/slsSupportLib/tests/test-container_utils.cpp b/tests/src/test-container_utils.cpp similarity index 100% rename from slsSupportLib/tests/test-container_utils.cpp rename to tests/src/test-container_utils.cpp diff --git a/tests/src/test-multiDetector.cpp b/tests/src/test-multiDetector.cpp new file mode 100644 index 000000000..3131b6462 --- /dev/null +++ b/tests/src/test-multiDetector.cpp @@ -0,0 +1,11 @@ +#include "catch.hpp" +#include "multiSlsDetector.h" + +#include +TEST_CASE("Initialize a detector") { +multiSlsDetector det(0, true, true); + std::cout << "Size: " << det.getNumberOfDetectors() << std::endl; + std::cout << "Hostname: " << det.getHostname() << std::endl; + REQUIRE(false); + +} \ No newline at end of file diff --git a/slsSupportLib/tests/test.cpp b/tests/src/test.cpp similarity index 100% rename from slsSupportLib/tests/test.cpp rename to tests/src/test.cpp