@@ -64,7 +64,9 @@ BOOST_AUTO_TEST_CASE(test_forwardparser_header_and_trailer)
6464 auto checkHeader = [](const typename FrameT::HeaderType& header) {
6565 return header.identifier == 0xdeadbeef ;
6666 };
67- auto checkTrailer = [](const typename FrameT::TrailerType& trailer) {
67+ int trailerCheckCount = 0 ;
68+ auto checkTrailer = [&trailerCheckCount](const typename FrameT::TrailerType& trailer) {
69+ ++trailerCheckCount;
6870 return trailer.identifier == 0xaaffee00 ;
6971 };
7072 auto getFrameSize = [](const typename ParserT::HeaderType& header) {
@@ -88,9 +90,62 @@ BOOST_AUTO_TEST_CASE(test_forwardparser_header_and_trailer)
8890 BOOST_REQUIRE (result == 3 );
8991 BOOST_REQUIRE (frames.size () == 3 );
9092
93+ // verify the trailer check callback was actually invoked for each frame
94+ BOOST_CHECK (trailerCheckCount == 3 );
95+
9196 BOOST_CHECK (memcmp (frames[0 ].payload , " lotsofsillydata" , frames[0 ].length ) == 0 );
9297 BOOST_CHECK (memcmp (frames[1 ].payload , " test" , frames[1 ].length ) == 0 );
9398 BOOST_CHECK (memcmp (frames[2 ].payload , " dummydata" , frames[2 ].length ) == 0 );
99+
100+ // verify trailer pointers are valid and fields correctly extracted from the buffer
101+ BOOST_REQUIRE (frames[0 ].trailer != nullptr );
102+ BOOST_CHECK (frames[0 ].trailer ->flags == 0xaa );
103+ BOOST_REQUIRE (frames[1 ].trailer != nullptr );
104+ BOOST_CHECK (frames[1 ].trailer ->flags == 0xcc );
105+ BOOST_REQUIRE (frames[2 ].trailer != nullptr );
106+ BOOST_CHECK (frames[2 ].trailer ->flags == 0x33 );
107+ }
108+
109+ BOOST_AUTO_TEST_CASE (test_forwardparser_trailer_check_rejection)
110+ {
111+ // verify that when checkTrailer returns false the parser reports a format error
112+ using FrameT = o2::algorithm::Composite<Header, Trailer>;
113+ using TestFrame = o2::algorithm::StaticSequenceAllocator;
114+ TestFrame tf (FrameT (16 , " lotsofsillydata" , 0xaa ),
115+ FrameT (5 , " test" , 0xcc ),
116+ FrameT (10 , " dummydata" , 0x33 ));
117+
118+ using ParserT = o2::algorithm::ForwardParser<typename FrameT::HeaderType,
119+ typename FrameT::TrailerType>;
120+
121+ auto checkHeader = [](const typename FrameT::HeaderType& header) {
122+ return header.identifier == 0xdeadbeef ;
123+ };
124+ // reject the second frame by its flags value
125+ auto checkTrailer = [](const typename FrameT::TrailerType& trailer) {
126+ return trailer.flags != 0xcc ;
127+ };
128+ auto getFrameSize = [](const typename ParserT::HeaderType& header) {
129+ return header.payloadSize + ParserT::totalOffset;
130+ };
131+
132+ std::vector<typename ParserT::FrameInfo> frames;
133+ auto insert = [&frames](typename ParserT::FrameInfo& info) {
134+ frames.emplace_back (info);
135+ return true ;
136+ };
137+
138+ ParserT parser;
139+ auto result = parser.parse (tf.buffer .get (), tf.size (),
140+ checkHeader,
141+ checkTrailer,
142+ getFrameSize,
143+ insert);
144+
145+ // the second frame's trailer is rejected, so parsing must signal a format error
146+ BOOST_REQUIRE (result == -1 );
147+ // insert is only called for a fully consistent buffer, so frames must be empty
148+ BOOST_CHECK (frames.empty ());
94149}
95150
96151BOOST_AUTO_TEST_CASE (test_forwardparser_header_and_void_trailer)
0 commit comments