mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-17 01:37:13 +02:00
friend_test macro
This commit is contained in:
@ -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}"
|
||||
|
@ -5,6 +5,10 @@
|
||||
#include "aare/RawMasterFile.hpp"
|
||||
#include "aare/RawSubFile.hpp"
|
||||
|
||||
#ifdef AARE_TESTS
|
||||
#include "../tests/friend_test.hpp"
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
|
||||
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<std::unique_ptr<RawSubFile>> 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
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
// #include "aare/RawFile.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
#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]") {
|
||||
|
||||
|
@ -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})
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
tests/friend_test.hpp
Normal file
4
tests/friend_test.hpp
Normal file
@ -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
|
20
tests/test_macros.hpp
Normal file
20
tests/test_macros.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
|
||||
#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<test_name##_Invoker>(), \
|
||||
Catch::SourceLineInfo(__FILE__, __LINE__), "", \
|
||||
Catch::NameAndTags{test_name_str, test_tags_str}); \
|
||||
} \
|
||||
void test_name##_impl()
|
Reference in New Issue
Block a user