* Date: 1/15/11
*/
public class BufferTest {
@Test
public void testRW() {
Buffer buffer = new Buffer();
byte[] buf = new byte[100];
Track t = new Track();
Arrays.fill(buf, (byte) 1);
t.getTrackData().setBitrate(5);
buffer.addNextTrack(t, null, 0, false);
buffer.write(buf, 0, buf.length);
buffer.write(buf, 0, buf.length);
t = new Track();
t.getTrackData().setBitrate(10);
buffer.addNextTrack(t, null, 0, false);
t = new Track();
t.getTrackData().setBitrate(20);
buffer.addNextTrack(t, null, 0, false);
buffer.write(buf, 0, buf.length);
t = new Track();
t.getTrackData().setBitrate(30);
buffer.addNextTrack(t, null, 0, false);
assertEquals(-1, buffer.read(buf, 0, 100));
Buffer.NextEntry nextTrack = buffer.pollNextTrack();
assertEquals(5, nextTrack.track.getTrackData().getBitrate());
assertEquals(55, buffer.read(buf, 0, 55));
assertEquals(100, buffer.read(buf, 0, 100));
assertEquals(45, buffer.read(buf, 0, 100));
assertEquals(-1, buffer.read(buf, 0, 100));
nextTrack = buffer.pollNextTrack();
assertEquals(10, nextTrack.track.getTrackData().getBitrate());
assertEquals(-1, buffer.read(buf, 0, 100));
nextTrack = buffer.pollNextTrack();
assertEquals(20, nextTrack.track.getTrackData().getBitrate());
assertEquals(100, buffer.read(buf, 0, 100));
assertEquals(-1, buffer.read(buf, 0, 100));
}