@@ -4,10 +4,10 @@ use std::io::BufReader;
44use itertools:: Itertools ;
55
66use rodio:: source:: ChannelVolume ;
7- use rodio:: { Decoder , Source } ;
7+ use rodio:: { queue , Decoder , Source } ;
88
99#[ test]
10- fn tomato ( ) {
10+ fn no_queue ( ) {
1111 let file = fs:: File :: open ( "assets/music.mp3" ) . unwrap ( ) ;
1212 let decoder = Decoder :: new ( BufReader :: new ( file) ) . unwrap ( ) ;
1313 assert_eq ! ( decoder. channels( ) , 2 ) ;
@@ -17,6 +17,20 @@ fn tomato() {
1717 assert_output_only_on_channel_1_and_2 ( channel_volume) ;
1818}
1919
20+ #[ test]
21+ fn with_queue_in_between ( ) {
22+ let file = fs:: File :: open ( "assets/music.mp3" ) . unwrap ( ) ;
23+ let decoder = Decoder :: new ( BufReader :: new ( file) ) . unwrap ( ) ;
24+ assert_eq ! ( decoder. channels( ) , 2 ) ;
25+ let channel_volume = ChannelVolume :: new ( decoder, vec ! [ 1.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ) ;
26+ assert_eq ! ( channel_volume. channels( ) , 6 ) ;
27+
28+ let ( controls, queue) = queue:: queue ( false ) ;
29+ controls. append ( channel_volume) ;
30+
31+ assert_output_only_on_channel_1_and_2 ( queue) ;
32+ }
33+
2034fn assert_output_only_on_channel_1_and_2 ( source : impl Source < Item = i16 > ) {
2135 for ( frame_number, mut frame) in source. chunks ( 6 ) . into_iter ( ) . enumerate ( ) {
2236 let frame: [ _ ; 6 ] = frame. next_array ( ) . expect ( & format ! (
@@ -25,7 +39,7 @@ fn assert_output_only_on_channel_1_and_2(source: impl Source<Item = i16>) {
2539 assert_eq ! (
2640 & frame[ 2 ..] ,
2741 & [ 0 , 0 , 0 , 0 ] ,
28- "frame number {frame_number} had nonzero volume on channels 3,4,5 & 6 "
42+ "frame {frame_number} had nonzero volume on a channel that should be zero "
2943 )
3044 }
3145}
0 commit comments