Skip to content

Commit

Permalink
Add basic tests for the EmptyEventCreator source
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 19, 2022
1 parent d694ac6 commit 2266a60
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/marlintest/include/TestEmptyEventCreator.h
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions test/marlintest/src/TestEmptyEventCreator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "TestEmptyEventCreator.h"

#include <string>
#include <vector>

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 &params = evt->getParameters();

std::vector<std::string> 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++;
}
13 changes: 13 additions & 0 deletions test/testmarlin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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." )
#---------------------------------------------------------------------------------------
22 changes: 22 additions & 0 deletions test/testmarlin/empty_event_creator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<marlin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ilcsoft.desy.de/marlin/marlin.xsd">

<execute>
<processor name="EmptyEventCreator"/>
<processor name="MyTestEmptyEventCreator"/>
</execute>

<global>
<parameter name="MaxRecordNumber" value="10"/>
</global>

<processor name="EmptyEventCreator" type="EmptyEventCreator"/>

<processor name="MyTestEmptyEventCreator" type="TestEmptyEventCreator">
<!--Processor to test whether the EmptyEventCreator data source works as expected-->
<!--verbosity level of this processor ("DEBUG0-4,MESSAGE0-4,WARNING0-4,ERROR0-4,SILENT")-->
<!--parameter name="Verbosity" type="string">DEBUG </parameter-->
</processor>

</marlin>

0 comments on commit 2266a60

Please sign in to comment.