Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:43

0001 
0002 #include <catch.hpp>
0003 #include <JANA/Topology/JArrow.h>
0004 
0005 namespace jana::topology::jarrowtests {
0006 
0007 struct TestData { int x; };
0008 
0009 struct BasicParallelArrow : public JArrow {
0010 
0011     BasicParallelArrow() {
0012         create_ports(1, 1);
0013         set_is_parallel(true);
0014     }
0015 
0016     void fire(JEvent* input, OutputData& outputs, size_t& output_count, JArrow::FireResult& process_status) {
0017 
0018         input->Insert(new TestData {.x=22});
0019 
0020         outputs[0] = {input, 1};
0021         output_count = 1;
0022         process_status = JArrow::FireResult::KeepGoing;
0023 
0024     }
0025 };
0026 
0027 
0028 TEST_CASE("BasicParallelArrow_Fire") {
0029 
0030     JApplication app;
0031     app.Initialize();
0032     auto event = std::make_shared<JEvent>(&app);
0033 
0034     BasicParallelArrow sut;
0035     JArrow::OutputData outputs;
0036     size_t output_count;
0037     JArrow::FireResult status;
0038 
0039     sut.fire(event.get(), outputs, output_count, status);
0040 
0041     REQUIRE(event->GetSingle<TestData>()->x == 22);
0042     REQUIRE(output_count == 1);
0043     REQUIRE(outputs[0].first == event.get());
0044     REQUIRE(outputs[0].second == 1);
0045     REQUIRE(status == JArrow::FireResult::KeepGoing);
0046 }
0047 
0048 
0049 
0050 TEST_CASE("BasicParallelArrow_ExecuteSucceeds") {
0051 
0052     JApplication app;
0053     app.Initialize();
0054 
0055     BasicParallelArrow sut;
0056     JEventPool input_pool(app.GetService<JComponentManager>(), 10, 1);
0057     JEventQueue output_queue(10, 1);
0058 
0059     sut.attach(&input_pool, 0);
0060     sut.attach(&output_queue, 1);
0061 
0062     auto result = sut.execute( 0);
0063 
0064     REQUIRE(result == JArrow::FireResult::KeepGoing);
0065     REQUIRE(output_queue.GetSize(0) == 1);
0066     JEvent* event = output_queue.Pop(0);
0067     REQUIRE(event->GetSingle<TestData>()->x == 22);
0068 }
0069 
0070 
0071 TEST_CASE("BasicParallelArrow_ExecuteFails") {
0072 
0073     JApplication app;
0074     app.Initialize();
0075 
0076     BasicParallelArrow sut;
0077     JEventQueue input_queue(10, 1);
0078     JEventQueue output_queue(10, 1);
0079 
0080     sut.attach(&input_queue, 0);
0081     sut.attach(&output_queue, 1);
0082 
0083     auto result = sut.execute(0);
0084 
0085     REQUIRE(result == JArrow::FireResult::NotRunYet);
0086     REQUIRE(output_queue.GetSize(0) == 0);
0087 }
0088 
0089 
0090 
0091 } // namespace jana::topology::jarrowtests