Mercurial > hg > pulseaudio
changeset 154:59f5e34743f6
2008-09-29 Omair Majid <omajid@redhat.com>
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java
(testWriteAndClose): New test. Tries to close() a SourceDataLine during a
write().
(testWriteAndStop): New test. Tries to stop() a SourceDataLine during a
write().
(testWriteAndFlush): New test. Tries to flush() a SourceDataLine during a
write().
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 29 Sep 2008 17:14:41 -0400 |
parents | 5ab54b0ca4ea |
children | 0894592be2a2 |
files | unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java |
diffstat | 1 files changed, 161 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Mon Sep 29 15:57:43 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Mon Sep 29 17:14:41 2008 -0400 @@ -41,6 +41,7 @@ import java.io.File; import java.io.IOException; +import java.net.UnknownHostException; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; @@ -229,6 +230,166 @@ } @Test + public void testWriteAndClose() throws UnsupportedAudioFileException, + IOException, LineUnavailableException, InterruptedException { + System.out.println("This test tires to close the line during a write"); + + File soundFile = new File("testsounds/startup.wav"); + final AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + AudioFormat audioFormat = audioInputStream.getFormat(); + + sourceDataLine = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, audioFormat)); + Assert.assertNotNull(sourceDataLine); + + sourceDataLine.open(audioFormat); + sourceDataLine.start(); + + Thread writer = new Thread() { + + @Override + public void run() { + try { + final byte[] abData = new byte[10000000]; + + int bytesRead = 0; + while (bytesRead >= 0) { + bytesRead = audioInputStream.read(abData, 0, + abData.length); + if (bytesRead > 0) { + sourceDataLine.write(abData, 0, bytesRead); + } + } + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + }; + + writer.start(); + Thread.sleep(100); + + sourceDataLine.close(); + + writer.join(500); + Assert.assertFalse(writer.isAlive()); + + } + + @Test + public void testWriteAndStop() throws UnsupportedAudioFileException, + IOException, LineUnavailableException, InterruptedException { + System.out.println("This test tires to stop the line during a write"); + + File soundFile = new File("testsounds/startup.wav"); + final AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + AudioFormat audioFormat = audioInputStream.getFormat(); + + sourceDataLine = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, audioFormat)); + Assert.assertNotNull(sourceDataLine); + + sourceDataLine.open(audioFormat); + sourceDataLine.start(); + + Thread writer = new Thread() { + + @Override + public void run() { + try { + final byte[] abData = new byte[10000000]; + + int bytesRead = 0; + while (bytesRead >= 0) { + bytesRead = audioInputStream.read(abData, 0, + abData.length); + if (bytesRead > 0) { + sourceDataLine.write(abData, 0, bytesRead); + } + } + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + }; + + writer.start(); + + Thread.sleep(500); + + sourceDataLine.stop(); + + writer.join(500); + Assert.assertFalse(writer.isAlive()); + + sourceDataLine.close(); + + } + + @Test + public void testWriteAndFlush() throws UnsupportedAudioFileException, + IOException, LineUnavailableException, InterruptedException { + + System.out.println("This test tries to flush a line during a write"); + + File soundFile = new File("testsounds/startup.wav"); + final AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + AudioFormat audioFormat = audioInputStream.getFormat(); + + sourceDataLine = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, audioFormat)); + Assert.assertNotNull(sourceDataLine); + + sourceDataLine.open(audioFormat); + sourceDataLine.start(); + + Thread writer = new Thread() { + + @Override + public void run() { + try { + final byte[] abData = new byte[10000000]; + + int bytesRead = 0; + while (bytesRead >= 0) { + bytesRead = audioInputStream.read(abData, 0, + abData.length); + if (bytesRead > 0) { + sourceDataLine.write(abData, 0, bytesRead); + } + } + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + }; + + writer.start(); + + Thread.sleep(100); + + sourceDataLine.flush(); + + writer.join(500); + Assert.assertFalse(writer.isAlive()); + + sourceDataLine.stop(); + sourceDataLine.close(); + } + + @Test public void testStartedStopped() throws LineUnavailableException, UnsupportedAudioFileException, IOException {