@@ -542,6 +542,8 @@ fn test_issue_14() {
542
542
// data is treated as invalid.
543
543
#[ test]
544
544
fn test_issue_7 ( ) {
545
+ use std:: io:: ErrorKind :: UnexpectedEof ;
546
+
545
547
let mut c = Cursor :: new ( Vec :: new ( ) ) ;
546
548
let test_arr = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
547
549
let test_arr_2 = [ 2 , 4 , 8 , 16 , 32 , 64 , 128 , 127 , 126 , 125 , 124 ] ;
@@ -564,17 +566,54 @@ fn test_issue_7() {
564
566
assert ! ( r. read_packet( ) . unwrap( ) . is_none( ) ) ;
565
567
}
566
568
567
- // Non-Ogg data should return an error.
569
+ // Truncated data should return the UnexpectedEof error.
568
570
let c = Cursor :: new ( vec ! [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
569
571
{
570
572
let mut r = PacketReader :: new ( c) ;
571
- assert ! ( matches!( r. read_packet( ) , Err ( OggReadError :: NoCapturePatternFound ) ) ) ;
573
+ assert ! ( matches!( r. read_packet( ) ,
574
+ Err ( OggReadError :: ReadError ( e) ) if e. kind( ) == UnexpectedEof ) ) ;
572
575
}
573
576
574
- // Empty data is considered non-Ogg data .
577
+ // Empty data should return the UnexpectedEof error .
575
578
let c = Cursor :: new ( & [ ] ) ;
576
579
{
577
580
let mut r = PacketReader :: new ( c) ;
578
- assert ! ( matches!( r. read_packet( ) , Err ( OggReadError :: NoCapturePatternFound ) ) ) ;
581
+ assert ! ( matches!( r. read_packet( ) ,
582
+ Err ( OggReadError :: ReadError ( e) ) if e. kind( ) == UnexpectedEof ) ) ;
579
583
}
580
584
}
585
+
586
+ #[ test]
587
+ fn test_read_with_append ( ) {
588
+ use std:: io:: ErrorKind :: UnexpectedEof ;
589
+
590
+ let first_chunk =
591
+ [ 79 , 103 , 103 , 83 , 0 , 2 , 0 , 0 , 0 ,
592
+ 0 , 0 , 0 , 0 , 0 , 14 , 247 , 95 , 68 , 0 ] ;
593
+ let second_chunk =
594
+ [ 0 , 0 , 0 , 139 , 130 , 226 , 240 , 1 , 30 , 1 , 118 , 111 , 114 ,
595
+ 98 , 105 , 115 , 0 , 0 , 0 , 0 , 1 , 128 , 187 , 0 , 0 , 0 , 0 , 0 ,
596
+ 0 , 128 , 56 , 1 , 0 , 0 , 0 , 0 , 0 , 184 , 1 ] ;
597
+
598
+ let c = Cursor :: new ( Vec :: new ( ) ) ;
599
+ let mut r = PacketReader :: new ( c) ;
600
+
601
+ // Add the first chunk
602
+ let c = r. get_mut ( ) ;
603
+ c. get_mut ( ) . extend ( first_chunk) ;
604
+ // Attempt to read an incomplete page
605
+ assert ! ( matches!( r. read_packet_expected( ) ,
606
+ Err ( OggReadError :: ReadError ( ref e) ) if e. kind( ) == UnexpectedEof
607
+ ) ) ;
608
+
609
+ // Add the second chunk
610
+ let c = r. get_mut ( ) ;
611
+ c. get_mut ( ) . extend ( second_chunk) ;
612
+ // Attempt to read a complete page
613
+ assert ! ( matches!( r. read_packet_expected( ) , Ok ( _) ) ) ;
614
+
615
+ // No data left in the buffer
616
+ assert ! ( matches!( r. read_packet_expected( ) ,
617
+ Err ( OggReadError :: ReadError ( ref e) ) if e. kind( ) == UnexpectedEof
618
+ ) ) ;
619
+ }
0 commit comments