11#include " ../msfts_source.h"
22#include " ../msfts_options.h"
3+ #include " fixture_file.h"
34
45#include < cstdint>
5- #include < filesystem>
6- #include < fstream>
76#include < iostream>
87#include < string>
98#include < vector>
@@ -82,17 +81,6 @@ void append_packet(std::vector<std::uint8_t>& bytes,
8281 bytes.insert (bytes.end (), packet.begin (), packet.end ());
8382}
8483
85- std::filesystem::path write_fixture (const std::vector<std::uint8_t >& bytes,
86- const std::string& suffix) {
87- const auto path = std::filesystem::temp_directory_path () /
88- (" openmoq-msfts-" + suffix + " .bin" );
89- std::ofstream output (path, std::ios::binary | std::ios::trunc);
90- output.write (reinterpret_cast <const char *>(bytes.data ()),
91- static_cast <std::streamsize>(bytes.size ()));
92- output.close ();
93- return path;
94- }
95-
9684std::uint16_t packet_pid (const std::uint8_t * packet, std::size_t packet_size) {
9785 const std::uint8_t * ts = packet + (packet_size == 192 ? 4 : 0 );
9886 return static_cast <std::uint16_t >(((ts[1 ] & 0x1f ) << 8 ) | ts[2 ]);
@@ -106,17 +94,15 @@ void test_source_catalog_and_filtering(std::size_t packet_size) {
10694 append_packet (fixture, make_packet (0x101 , 0x11 ), packet_size);
10795 append_packet (fixture, make_packet (0x111 , 0x22 ), packet_size);
10896 append_packet (fixture, make_packet (0x101 , 0x33 ), packet_size);
109- const auto path = write_fixture (fixture, std::to_string (packet_size));
97+ const FixtureFile fixture_file (fixture, std::to_string (packet_size));
11098
11199 std::string error;
112100 auto source = MsftsSource::open (MsftsSourceConfig{
113- .input_path = path,
101+ .input_path = fixture_file. path () ,
114102 .track_name = " transport" ,
115103 .requested_program = 1 ,
116104 .packets_per_object = 2 ,
117105 }, error);
118- std::filesystem::remove (path);
119-
120106 expect (source != nullptr , " expected valid " + std::to_string (packet_size) + " -byte source" );
121107 if (source == nullptr ) {
122108 std::cerr << error << ' \n ' ;
@@ -186,11 +172,11 @@ void test_ambiguous_m2ts_prefix_is_detected_as_192_bytes() {
186172 append_packet (fixture, pat, 192 );
187173 append_packet (fixture, make_pmt (0x100 , 1 , 0x101 ), 192 );
188174 fixture[0 ] = 0x47 ;
189- const auto path = write_fixture (fixture, " ambiguous-192" );
175+ const FixtureFile fixture_file (fixture, " ambiguous-192" );
190176
191177 std::string error;
192- auto source = MsftsSource::open (MsftsSourceConfig{. input_path = path}, error);
193- std::filesystem::remove ( path);
178+ auto source = MsftsSource::open (
179+ MsftsSourceConfig{. input_path = fixture_file. path ()}, error );
194180 expect (source != nullptr && source->info ().packet_size == 192 ,
195181 " expected file-size and sync alignment to disambiguate M2TS" );
196182}
@@ -200,11 +186,11 @@ void test_partial_packet_is_rejected() {
200186 append_packet (fixture, make_pat (), 188 );
201187 append_packet (fixture, make_pmt (0x100 , 1 , 0x101 ), 188 );
202188 fixture.push_back (0x47 );
203- const auto path = write_fixture (fixture, " partial" );
189+ const FixtureFile fixture_file (fixture, " partial" );
204190
205191 std::string error;
206- auto source = MsftsSource::open (MsftsSourceConfig{. input_path = path}, error);
207- std::filesystem::remove ( path);
192+ auto source = MsftsSource::open (
193+ MsftsSourceConfig{. input_path = fixture_file. path ()}, error );
208194
209195 expect (source == nullptr , " expected partial source packet to be rejected" );
210196 expect (error.find (" partial" ) != std::string::npos,
@@ -218,14 +204,13 @@ void test_corrupt_packet_does_not_publish_partial_object() {
218204 auto corrupt = make_packet (0x101 );
219205 corrupt[0 ] = 0 ;
220206 append_packet (fixture, corrupt, 188 );
221- const auto path = write_fixture (fixture, " corrupt" );
207+ const FixtureFile fixture_file (fixture, " corrupt" );
222208
223209 std::string error;
224210 auto source = MsftsSource::open (MsftsSourceConfig{
225- .input_path = path,
211+ .input_path = fixture_file. path () ,
226212 .packets_per_object = 4 ,
227213 }, error);
228- std::filesystem::remove (path);
229214 expect (source != nullptr , " expected discovery before the corrupt packet" );
230215 if (source == nullptr ) {
231216 return ;
@@ -244,10 +229,10 @@ void test_program_discovery_errors() {
244229 std::vector<std::uint8_t > fixture;
245230 append_packet (fixture, make_packet (0x101 ), 188 );
246231 append_packet (fixture, make_packet (0x101 ), 188 );
247- const auto path = write_fixture (fixture, " missing-pat" );
232+ const FixtureFile fixture_file (fixture, " missing-pat" );
248233 std::string error;
249- auto source = MsftsSource::open (MsftsSourceConfig{. input_path = path}, error);
250- std::filesystem::remove ( path);
234+ auto source = MsftsSource::open (
235+ MsftsSourceConfig{. input_path = fixture_file. path ()}, error );
251236 expect (source == nullptr && error.find (" PAT" ) != std::string::npos,
252237 " expected a missing PAT to be rejected" );
253238 }
@@ -256,12 +241,14 @@ void test_program_discovery_errors() {
256241 std::vector<std::uint8_t > fixture;
257242 append_packet (fixture, make_pat (), 188 );
258243 append_packet (fixture, make_pmt (0x100 , 1 , 0x101 ), 188 );
259- const auto path = write_fixture (fixture, " missing-program" );
244+ const FixtureFile fixture_file (fixture, " missing-program" );
260245 std::string error;
261246 auto source = MsftsSource::open (
262- MsftsSourceConfig{.input_path = path, .requested_program = 3 },
247+ MsftsSourceConfig{
248+ .input_path = fixture_file.path (),
249+ .requested_program = 3 ,
250+ },
263251 error);
264- std::filesystem::remove (path);
265252 expect (source == nullptr && error.find (" requested program 3" ) != std::string::npos,
266253 " expected an absent requested program to be rejected" );
267254 }
@@ -270,12 +257,14 @@ void test_program_discovery_errors() {
270257 std::vector<std::uint8_t > fixture;
271258 append_packet (fixture, make_pat (), 188 );
272259 append_packet (fixture, make_pmt (0x100 , 1 , 0x101 ), 188 );
273- const auto path = write_fixture (fixture, " missing-pmt" );
260+ const FixtureFile fixture_file (fixture, " missing-pmt" );
274261 std::string error;
275262 auto source = MsftsSource::open (
276- MsftsSourceConfig{.input_path = path, .requested_program = 2 },
263+ MsftsSourceConfig{
264+ .input_path = fixture_file.path (),
265+ .requested_program = 2 ,
266+ },
277267 error);
278- std::filesystem::remove (path);
279268 expect (source == nullptr && error.find (" PMT" ) != std::string::npos,
280269 " expected a missing selected-program PMT to be rejected" );
281270 }
@@ -290,14 +279,13 @@ void test_declared_psi_interval_is_honored() {
290279 make_packet (0x101 , static_cast <std::uint8_t >(index)),
291280 188 );
292281 }
293- const auto path = write_fixture (fixture, " psi-interval" );
282+ const FixtureFile fixture_file (fixture, " psi-interval" );
294283
295284 std::string error;
296285 auto source = MsftsSource::open (MsftsSourceConfig{
297- .input_path = path,
286+ .input_path = fixture_file. path () ,
298287 .packets_per_object = 2 ,
299288 }, error);
300- std::filesystem::remove (path);
301289 expect (source != nullptr , " expected PSI interval fixture to open" );
302290 if (source == nullptr ) {
303291 return ;
0 commit comments