@@ -853,17 +853,6 @@ mod tests {
853853 assert ! ( ( 1 ..=2 ) . contains( & duration) ) ;
854854 }
855855
856- #[ test]
857- fn test_ccx_options_default ( ) {
858- // let mut ccx_options = CcxOptions.lock().unwrap();
859- {
860- let ccx_options = Options :: default ( ) ;
861-
862- {
863- println ! ( "{ccx_options:?}" ) ;
864- }
865- }
866- }
867856 #[ test]
868857 fn test_sleepandchecktimeout_stdin ( ) {
869858 {
@@ -883,7 +872,7 @@ mod tests {
883872 assert ! ( ( null_mut:: <* mut u8 >( ) ) . is_null( ) ) ;
884873 }
885874 }
886- // #[test] // Uncomment to run
875+ // #[test] // Uncomment to run, needs real file
887876 #[ allow( unused) ]
888877 fn test_switch_to_next_file_success ( ) {
889878 unsafe {
@@ -1149,87 +1138,6 @@ mod tests {
11491138 assert_eq ! ( read_bytes, content. len( ) ) ;
11501139 assert_eq ! ( & out_buf1, content) ;
11511140 }
1152- #[ test]
1153- #[ serial]
1154- fn test_buffered_read_opt_empty_file ( ) {
1155- initialize_logger ( ) ;
1156- let ccx_options = & mut Options :: default ( ) ;
1157- // Use buffering.
1158- ccx_options. buffer_input = true ;
1159- ccx_options. live_stream = Some ( Timestamp :: from_millis ( 0 ) ) ;
1160- ccx_options. input_source = DataSource :: File ;
1161- ccx_options. binary_concat = false ;
1162- // Create an empty temporary file.
1163- let content: & [ u8 ] = b"" ;
1164- let fd = create_temp_file_with_content ( content) ; // file pointer will be at beginning
1165- // Allocate a filebuffer.
1166- let filebuffer = allocate_filebuffer ( ) ;
1167- let mut ctx = CcxDemuxer :: default ( ) ;
1168- ctx. infd = fd;
1169- ctx. past = 0 ;
1170- ctx. filebuffer = filebuffer;
1171- ctx. filebuffer_start = 0 ;
1172- ctx. filebuffer_pos = 0 ;
1173- ctx. bytesinbuffer = 0 ;
1174- // (Other fields can remain default.)
1175-
1176- // Prepare an output buffer with the same length as content (i.e. zero length).
1177- let mut out_buf1 = vec ! [ 0u8 ; content. len( ) ] ;
1178- let out_buf2 = vec ! [ 0u8 ; content. len( ) ] ;
1179- let read_bytes = unsafe {
1180- buffered_read_opt (
1181- & mut ctx,
1182- out_buf1. as_mut_ptr ( ) ,
1183- out_buf2. len ( ) ,
1184- & mut * ccx_options,
1185- )
1186- } ;
1187- assert_eq ! ( read_bytes, 0 ) ;
1188- assert_eq ! ( & out_buf1, content) ;
1189-
1190- // Clean up allocated filebuffer.
1191- unsafe {
1192- let _ = Box :: from_raw ( filebuffer) ;
1193- } ;
1194- }
1195-
1196- #[ test]
1197- #[ serial]
1198- fn test_buffered_read_opt_seek_without_buffer ( ) {
1199- initialize_logger ( ) ;
1200- let ccx_options = & mut Options :: default ( ) ;
1201- // Disable buffering.
1202- ccx_options. buffer_input = false ;
1203- ccx_options. live_stream = Some ( Timestamp :: from_millis ( 0 ) ) ;
1204- ccx_options. input_source = DataSource :: File ;
1205- ccx_options. binary_concat = false ;
1206- // Create a file with some content.
1207- let content = b"Content for seek branch" ;
1208- let fd = create_temp_file_with_content ( content) ;
1209- // For this test we simulate the "seek without a buffer" branch by passing an empty output slice.
1210- let mut ctx = CcxDemuxer :: default ( ) ;
1211- ctx. infd = fd;
1212- ctx. past = 0 ;
1213- // In this branch, the filebuffer is not used.
1214- ctx. filebuffer = ptr:: null_mut ( ) ;
1215- ctx. filebuffer_start = 0 ;
1216- ctx. filebuffer_pos = 0 ;
1217- ctx. bytesinbuffer = 0 ;
1218-
1219- // Pass an empty buffer so that the branch that checks `if !buffer.is_empty()` fails.
1220- let mut out_buf1 = vec ! [ 0u8 ; 0 ] ;
1221- let out_buf2 = [ 0u8 ; 0 ] ;
1222- let read_bytes = unsafe {
1223- buffered_read_opt (
1224- & mut ctx,
1225- out_buf1. as_mut_ptr ( ) ,
1226- out_buf2. len ( ) ,
1227- & mut * ccx_options,
1228- )
1229- } ;
1230- // Expect that no bytes can be read into an empty slice.
1231- assert_eq ! ( read_bytes, 0 ) ;
1232- }
12331141
12341142 // Helper: create a dummy CcxDemuxer with a preallocated filebuffer.
12351143 fn create_ccx_demuxer_with_buffer < ' a > ( ) -> CcxDemuxer < ' a > {
@@ -1301,44 +1209,7 @@ mod tests {
13011209 } ;
13021210 }
13031211
1304- // Test 3: Normal case: no filebuffer_pos; simply copy incoming data.
1305- #[ test]
1306- fn test_return_to_buffer_normal ( ) {
1307- initialize_logger ( ) ;
1308- let mut ctx = create_ccx_demuxer_with_buffer ( ) ;
1309- // Set filebuffer_pos to 0 and bytesinbuffer to some existing data.
1310- ctx. filebuffer_pos = 0 ;
1311- ctx. bytesinbuffer = 4 ;
1312- // Pre-fill the filebuffer with some data.
1313- unsafe {
1314- for i in 0 ..4 {
1315- * ctx. filebuffer . add ( i) = ( i + 10 ) as u8 ; // 10,11,12,13
1316- }
1317- }
1318- // Now call return_to_buffer with an input of 3 bytes.
1319- let input = [ 0x77 , 0x88 , 0x99 ] ;
1320- return_to_buffer ( & mut ctx, & input, 3 ) ;
1321- // Expected behavior:
1322- // - Since filebuffer_pos == 0, it skips the first if blocks.
1323- // - It checks that (bytesinbuffer + bytes) does not exceed FILEBUFFERSIZE.
1324- // - It then shifts the existing data right by 3 bytes.
1325- // - It copies the new input to the front.
1326- // - It increments bytesinbuffer by 3 (so now 7 bytes).
1327- unsafe {
1328- let out = slice:: from_raw_parts ( ctx. filebuffer , ctx. bytesinbuffer as usize ) ;
1329- // First 3 bytes should equal input.
1330- assert_eq ! ( & out[ 0 ..3 ] , & input) ;
1331- // Next 4 bytes should be the old data.
1332- let expected = & [ 10u8 , 11 , 12 , 13 ] ;
1333- assert_eq ! ( & out[ 3 ..7 ] , expected) ;
1334- }
1335- // Clean up.
1336- unsafe {
1337- let _ = Box :: from_raw ( slice:: from_raw_parts_mut ( ctx. filebuffer , FILEBUFFERSIZE ) ) ;
1338- } ;
1339- }
13401212 //buffered_read tests
1341- // Helper: create a dummy CcxDemuxer with a preallocated filebuffer.
13421213
13431214 // Test 1: Direct branch - when requested bytes <= available in filebuffer.
13441215 #[ test]
@@ -1466,33 +1337,9 @@ mod tests {
14661337 assert_eq ! ( ctx. filebuffer_pos, 0 ) ;
14671338 }
14681339
1469- // Test 3: When no available data in filebuffer, forcing call to buffered_read_opt.
1470- #[ test]
1471- #[ serial]
1472- fn test_buffered_read_byte_no_available ( ) {
1473- #[ allow( unused_variables) ]
1474- let ctx = create_ccx_demuxer_with_buffer ( ) ;
1475- let content = b"a" ;
1476- let fd = create_temp_file_with_content ( content) ;
1477- let mut ctx = create_ccx_demuxer_with_buffer ( ) ;
1478- ctx. infd = fd;
1479- ctx. past = 0 ;
1480- let ccx_options = & mut Options :: default ( ) ;
1481- // Set bytesinbuffer to 0 to force the else branch.
1482-
1483- // Set bytesinbuffer to equal filebuffer_pos so that no data is available.
1484- ctx. bytesinbuffer = 10 ;
1485- ctx. filebuffer_pos = 10 ;
1486- let mut out_byte: u8 = 0 ;
1487- // Our dummy buffered_read_opt returns 1 and writes 0xAA.
1488- let read = unsafe { buffered_read_byte ( & mut ctx, Some ( & mut out_byte) , & mut * ccx_options) } ;
1489- assert_eq ! ( read, 1 ) ;
1490- assert_eq ! ( out_byte, 97 ) ;
1491- }
1492-
14931340 // Tests for buffered_get_be16
14941341
1495- // Test 4 : When filebuffer has at least 2 available bytes.
1342+ // Test 1 : When filebuffer has at least 2 available bytes.
14961343 #[ test]
14971344 fn test_buffered_get_be16_from_buffer ( ) {
14981345 let mut ctx = create_ccx_demuxer_with_buffer ( ) ;
@@ -1515,7 +1362,7 @@ mod tests {
15151362 assert_eq ! ( ctx. filebuffer_pos, 2 ) ;
15161363 }
15171364
1518- // Test 5 : When filebuffer is empty, forcing buffered_read_opt for each byte.
1365+ // Test 2 : When filebuffer is empty, forcing buffered_read_opt for each byte.
15191366 #[ test]
15201367 #[ serial]
15211368 fn test_buffered_get_be16_from_opt ( ) {
@@ -1559,27 +1406,6 @@ mod tests {
15591406 // filebuffer_pos should have advanced by 1.
15601407 assert_eq ! ( ctx. filebuffer_pos, 1 ) ;
15611408 }
1562- #[ test]
1563- #[ serial]
1564- fn test_buffered_get_byte_no_available ( ) {
1565- let ccx_options = & mut Options :: default ( ) ;
1566- #[ allow( unused_variables) ]
1567- let ctx = create_ccx_demuxer_with_buffer ( ) ;
1568- let content = b"Network buffered read test!" ;
1569- let fd = create_temp_file_with_content ( content) ;
1570- let mut ctx = create_ccx_demuxer_with_buffer ( ) ;
1571- ctx. infd = fd;
1572- // Force no available data.
1573- ctx. bytesinbuffer = 0 ;
1574- ctx. filebuffer_pos = 0 ;
1575- ctx. past = 0 ;
1576- // In this case, buffered_read_opt (our dummy version) will supply 0xAA for each byte.
1577- let value = unsafe { buffered_get_byte ( & mut ctx, & mut * ccx_options) } ;
1578- // Expect the byte to be 0xAA.
1579- assert_eq ! ( value, 0x4E ) ;
1580- // past should have been incremented.
1581- assert_eq ! ( ctx. past, 1 ) ;
1582- }
15831409
15841410 #[ test]
15851411 fn test_buffered_get_be32_from_buffer ( ) {
0 commit comments