From 2266a60c67030823770f3d69a0ae74a98f1685be Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 19 Sep 2022 14:24:43 +0200 Subject: [PATCH] Add basic tests for the EmptyEventCreator source --- .../include/TestEmptyEventCreator.h | 28 +++++++++ test/marlintest/src/TestEmptyEventCreator.cc | 59 +++++++++++++++++++ test/testmarlin/CMakeLists.txt | 13 ++++ test/testmarlin/empty_event_creator.xml | 22 +++++++ 4 files changed, 122 insertions(+) create mode 100644 test/marlintest/include/TestEmptyEventCreator.h create mode 100644 test/marlintest/src/TestEmptyEventCreator.cc create mode 100644 test/testmarlin/empty_event_creator.xml diff --git a/test/marlintest/include/TestEmptyEventCreator.h b/test/marlintest/include/TestEmptyEventCreator.h new file mode 100644 index 00000000..5850cd30 --- /dev/null +++ b/test/marlintest/include/TestEmptyEventCreator.h @@ -0,0 +1,28 @@ +#ifndef TestEmptyEventCreator_h +#define TestEmptyEventCreator_h 1 + +#include "marlin/Processor.h" + +#include "lcio.h" + +/** Test processor to check that the EmptyEventCreator data source produces the + * expected empty events + */ +class TestEmptyEventCreator : public marlin::Processor { + +public: + TestEmptyEventCreator *newProcessor() override { + return new TestEmptyEventCreator; + } + + TestEmptyEventCreator(); + + void processRunHeader(lcio::LCRunHeader *run) override; + + void processEvent(lcio::LCEvent *evt) override; + +private: + int m_expectedEvt{0}; +}; + +#endif diff --git a/test/marlintest/src/TestEmptyEventCreator.cc b/test/marlintest/src/TestEmptyEventCreator.cc new file mode 100644 index 00000000..17d4cf00 --- /dev/null +++ b/test/marlintest/src/TestEmptyEventCreator.cc @@ -0,0 +1,59 @@ +#include "TestEmptyEventCreator.h" + +#include +#include + +TestEmptyEventCreator aTestEmptyEventCreator; + +TestEmptyEventCreator::TestEmptyEventCreator() + : marlin::Processor("TestEmptyEventCreator") { + _description = "Processor to test whether the EmptyEventCreator data source " + "works as expected"; +} + +void TestEmptyEventCreator::processRunHeader(lcio::LCRunHeader *run) { + if (run->getRunNumber() != 0) { + throw lcio::Exception("Run number from EmptyEventCreator is not 0 (" + + std::to_string(run->getRunNumber()) + ")"); + } +} + +void TestEmptyEventCreator::processEvent(lcio::LCEvent *evt) { + if (evt->getEventNumber() != m_expectedEvt) { + throw lcio::Exception( + "Event number from EmptyEventCreator is not as expected (expected: " + + std::to_string(m_expectedEvt) + + ", actual: " + std::to_string(evt->getEventNumber()) + ")"); + } + + if (!evt->getCollectionNames()->empty()) { + throw lcio::Exception( + "EmptyEventCreator should create empty events, but LCEvent contains " + + std::to_string(evt->getCollectionNames()->size()) + " collections"); + } + + const auto ¶ms = evt->getParameters(); + + std::vector keys; + params.getIntKeys(keys); + if (!keys.empty()) { + throw lcio::Exception( + "EmptyEventCreator should create empty events, but has int parameters"); + } + keys.clear(); + + params.getFloatKeys(keys); + if (!keys.empty()) { + throw lcio::Exception("EmptyEventCreator should create empty events, but " + "has float parameters"); + } + keys.clear(); + + params.getStringKeys(keys); + if (!keys.empty()) { + throw lcio::Exception("EmptyEventCreator should create empty events, but " + "has string parameters"); + } + + m_expectedEvt++; +} diff --git a/test/testmarlin/CMakeLists.txt b/test/testmarlin/CMakeLists.txt index 3921e9df..c844ea7b 100644 --- a/test/testmarlin/CMakeLists.txt +++ b/test/testmarlin/CMakeLists.txt @@ -63,3 +63,16 @@ SET_TESTS_PROPERTIES( t_includeandconstants PROPERTIES PASS_REGULAR_EXPRESSION " #--------------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------------- +SET( MARLIN_STEERING_FILE empty_event_creator.xml ) +SET( MARLIN_INPUT_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/${MARLIN_STEERING_FILE} + ${CMAKE_CURRENT_SOURCE_DIR}/gear_simjob.xml + ${CMAKE_CURRENT_SOURCE_DIR}/simjob.slcio +) +CONFIGURE_FILE( runmarlin.cmake.in empty_event_creator.cmake @ONLY ) + +ADD_TEST( t_empty_event_creator "${CMAKE_COMMAND}" -P empty_event_creator.cmake ) +SET_TESTS_PROPERTIES( t_empty_event_creator PROPERTIES FAIL_REGULAR_EXPRESSION "Marlin will have to be terminated, sorry." ) +#--------------------------------------------------------------------------------------- diff --git a/test/testmarlin/empty_event_creator.xml b/test/testmarlin/empty_event_creator.xml new file mode 100644 index 00000000..c9825d17 --- /dev/null +++ b/test/testmarlin/empty_event_creator.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +