File indexing completed on 2025-01-18 10:17:41
0001
0002 #include "catch.hpp"
0003
0004 #include <JANA/JEventSource.h>
0005
0006 struct MyEventSource : public JEventSource {
0007 int open_count = 0;
0008 int emit_count = 0;
0009 int close_count = 0;
0010 size_t events_in_file = 5;
0011
0012 void Open() override {
0013 REQUIRE(GetApplication() != nullptr);
0014 LOG_INFO(GetLogger()) << "Open() called" << LOG_END;
0015 open_count++;
0016 }
0017 Result Emit(JEvent&) override {
0018 emit_count++;
0019 REQUIRE(GetApplication() != nullptr);
0020 if (GetEmittedEventCount() >= events_in_file) {
0021 LOG_INFO(GetLogger()) << "Emit() called, returning FailureFinished" << LOG_END;
0022 return Result::FailureFinished;
0023 }
0024 LOG_INFO(GetLogger()) << "Emit() called, returning Success" << LOG_END;
0025 return Result::Success;
0026 }
0027 void Close() override {
0028 REQUIRE(GetApplication() != nullptr);
0029 LOG_INFO(GetLogger()) << "Close() called" << LOG_END;
0030 close_count++;
0031 }
0032 };
0033
0034 TEST_CASE("JEventSource_ExpertMode_EmitCount") {
0035
0036 auto sut = new MyEventSource;
0037 sut->SetCallbackStyle(MyEventSource::CallbackStyle::ExpertMode);
0038 sut->SetTypeName("MyEventSource");
0039
0040 JApplication app;
0041 app.SetParameterValue("jana:loglevel", "off");
0042 app.Add(sut);
0043
0044 SECTION("ShutsSelfOff") {
0045 LOG << "Running test: JEventSource_ExpertMode_EmitCount :: ShutsSelfOff" << LOG_END;
0046 app.Run();
0047 REQUIRE(sut->open_count == 1);
0048 REQUIRE(sut->emit_count == 6);
0049 REQUIRE(sut->GetEmittedEventCount() == 5);
0050 REQUIRE(sut->close_count == 1);
0051 }
0052
0053 SECTION("LimitedByNEvents") {
0054 LOG << "Running test: JEventSource_ExpertMode_EmitCount :: LimitedByNEvents" << LOG_END;
0055 app.SetParameterValue("jana:nevents", 3);
0056 app.Run();
0057 REQUIRE(sut->open_count == 1);
0058 REQUIRE(sut->emit_count == 3);
0059 REQUIRE(sut->GetEmittedEventCount() == 3);
0060 REQUIRE(sut->close_count == 1);
0061 }
0062
0063 SECTION("LimitedByNSkip") {
0064 LOG << "Running test: JEventSource_ExpertMode_EmitCount :: LimitedByNSkip" << LOG_END;
0065 app.SetParameterValue("jana:nskip", 3);
0066 app.Run();
0067 REQUIRE(sut->open_count == 1);
0068 REQUIRE(sut->emit_count == 6);
0069 REQUIRE(sut->GetEmittedEventCount() == 5);
0070 REQUIRE(sut->close_count == 1);
0071 }
0072 }
0073
0074