From 75f63607fc003ace9b3c73399c8827cb07d9c88f Mon Sep 17 00:00:00 2001 From: Alice Date: Thu, 12 Jun 2025 17:46:10 +0200 Subject: [PATCH] friend_test macro --- CMakeLists.txt | 9 +++++---- include/aare/RawFile.hpp | 25 +++++++++++++++++-------- include/aare/RawMasterFile.hpp | 3 +-- src/RawFile.cpp | 1 + src/RawFile.test.cpp | 12 +++++++++--- tests/CMakeLists.txt | 5 ++++- tests/friend_test.hpp | 4 ++++ tests/test_macros.hpp | 20 ++++++++++++++++++++ 8 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 tests/friend_test.hpp create mode 100644 tests/test_macros.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fa9838e..f0bd5d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,13 +335,10 @@ if(AARE_ASAN) ) endif() - - - - if(AARE_TESTS) enable_testing() add_subdirectory(tests) + target_compile_definitions(tests PRIVATE AARE_TESTS) endif() ###------------------------------------------------------------------------------MAIN LIBRARY @@ -424,6 +421,10 @@ target_link_libraries( ) +if(AARE_TESTS) + target_compile_definitions(aare_core PRIVATE AARE_TESTS) +endif() + set_target_properties(aare_core PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} PUBLIC_HEADER "${PUBLICHEADERS}" diff --git a/include/aare/RawFile.hpp b/include/aare/RawFile.hpp index 78ebf4c..6d90931 100644 --- a/include/aare/RawFile.hpp +++ b/include/aare/RawFile.hpp @@ -5,6 +5,10 @@ #include "aare/RawMasterFile.hpp" #include "aare/RawSubFile.hpp" +#ifdef AARE_TESTS +#include "../tests/friend_test.hpp" +#endif + #include namespace aare { @@ -21,6 +25,9 @@ struct ModuleConfig { return true; } }; +#ifdef AARE_TESTS +TEST_CASE_PRIVATE_FWD(check_find_geometry) // forward declaration +#endif /** * @brief Class to read .raw files. The class will parse the master file @@ -30,7 +37,9 @@ struct ModuleConfig { */ class RawFile : public FileInterface { - friend class RawMasterFile; +#ifdef AARE_TESTS + FRIEND_TEST(check_find_geometry) +#endif std::vector> m_subfiles; ModuleConfig cfg{0, 0}; RawMasterFile m_master; @@ -81,6 +90,13 @@ class RawFile : public FileInterface { DetectorType detector_type() const override; + /** + * @brief read the header of the file + * @param fname path to the data subfile + * @return DetectorHeader + */ + static DetectorHeader read_header(const std::filesystem::path &fname); + private: /** * @brief read the frame at the given frame index into the image buffer @@ -102,13 +118,6 @@ class RawFile : public FileInterface { protected: void find_geometry(); - - /** - * @brief read the header of the file - * @param fname path to the data subfile - * @return DetectorHeader - */ - static DetectorHeader read_header(const std::filesystem::path &fname); }; } // namespace aare \ No newline at end of file diff --git a/include/aare/RawMasterFile.hpp b/include/aare/RawMasterFile.hpp index ffcae66..ba052dc 100644 --- a/include/aare/RawMasterFile.hpp +++ b/include/aare/RawMasterFile.hpp @@ -1,5 +1,4 @@ #pragma once -// #include "aare/RawFile.hpp" #include "aare/defs.hpp" #include #include @@ -63,7 +62,7 @@ class ScanParameters { void increment_stop(); }; -class RawFile; // forward declaration +// class RawFile; // forward declaration /** * @brief Class for parsing a master file either in our .json format or the old diff --git a/src/RawFile.cpp b/src/RawFile.cpp index 9e78a7f..1ddbebf 100644 --- a/src/RawFile.cpp +++ b/src/RawFile.cpp @@ -148,6 +148,7 @@ RawMasterFile RawFile::master() const { return m_master; } */ void RawFile::find_geometry() { + m_geometry.reserve(n_modules()); for (size_t col = 0; col < m_master.geometry().col; col += m_master.udp_interfaces_per_module().col) for (size_t row = 0; row < m_master.geometry().row; diff --git a/src/RawFile.test.cpp b/src/RawFile.test.cpp index c6b6623..aaf84d8 100644 --- a/src/RawFile.test.cpp +++ b/src/RawFile.test.cpp @@ -7,6 +7,7 @@ #include #include "test_config.hpp" +#include "test_macros.hpp" using aare::File; using aare::RawFile; @@ -184,7 +185,8 @@ struct TestParameters { const DetectorGeometry geometry{}; }; -TEST_CASE("check find_geometry", "[.integration][.files][.rawfile]") { +TEST_CASE_PRIVATE(aare, check_find_geometry, "check find_geometry", + "[.integration][.files][.rawfile]") { auto test_parameters = GENERATE( TestParameters{ @@ -223,9 +225,11 @@ TEST_CASE("check find_geometry", "[.integration][.files][.rawfile]") { REQUIRE(std::filesystem::exists(fpath)); - RawFileTestWrapper f(fpath, "r"); + RawFile f(fpath, "r"); - auto geometry = f.get_geometry(); + f.find_geometry(); + + auto geometry = f.m_geometry; CHECK(geometry.modules_x == test_parameters.geometry.modules_x); CHECK(geometry.modules_y == test_parameters.geometry.modules_y); @@ -257,6 +261,8 @@ TEST_CASE("check find_geometry", "[.integration][.files][.rawfile]") { } } +} // close the namespace + TEST_CASE("Open multi module file with ROI", "[.integration][.files][.rawfile]") { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1906508..994dc47 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,5 +40,8 @@ target_sources(tests PRIVATE ${TestSources} ) #configure a header to pass test file paths get_filename_component(TEST_FILE_PATH ${PROJECT_SOURCE_DIR}/data ABSOLUTE) configure_file(test_config.hpp.in test_config.hpp) -target_include_directories(tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + + + diff --git a/tests/friend_test.hpp b/tests/friend_test.hpp new file mode 100644 index 0000000..7d16000 --- /dev/null +++ b/tests/friend_test.hpp @@ -0,0 +1,4 @@ +#define FRIEND_TEST(test_name) friend void test_name##_impl(); + +#define TEST_CASE_PRIVATE_FWD(test_name) \ + void test_name##_impl(); // foward declaration diff --git a/tests/test_macros.hpp b/tests/test_macros.hpp new file mode 100644 index 0000000..4e89923 --- /dev/null +++ b/tests/test_macros.hpp @@ -0,0 +1,20 @@ +#include + +#include +#include +#include + +#define TEST_CASE_PRIVATE(namespace_name, test_name, test_name_str, \ + test_tags_str) \ + namespace namespace_name { \ + void test_name##_impl(); \ + namespace { \ + struct test_name##_Invoker : Catch::ITestInvoker { \ + void invoke() const override { test_name##_impl(); } \ + }; \ + Catch::AutoReg \ + autoReg_##test_name(Catch::Detail::make_unique(), \ + Catch::SourceLineInfo(__FILE__, __LINE__), "", \ + Catch::NameAndTags{test_name_str, test_tags_str}); \ + } \ + void test_name##_impl()