changeset 156:609dcbe6d5b8

2008-09-30 Omair Majid <omajid@redhat.com> * unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java (testWriteWithoutStart): New function. Checks that writing to line that hasnt been started doesnt play any sound. (testDrainWithoutStart): fixed function. Tries to drain a line with data written to it that hasnt been started. Now writes in a separate thread so that the function doesnt block on write. (testFlushWithoutStart): New test. Tries to flush a line that hasnt been started.
author Omair Majid <omajid@redhat.com>
date Tue, 30 Sep 2008 11:49:05 -0400
parents 0894592be2a2
children 55bb87d31a6f
files unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java
diffstat 1 files changed, 88 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java	Tue Sep 30 10:31:32 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java	Tue Sep 30 11:49:05 2008 -0400
@@ -230,6 +230,59 @@
 	}
 
 	@Test
+	public void testWriteWithoutStart() throws UnsupportedAudioFileException,
+			IOException, LineUnavailableException, InterruptedException {
+
+		System.out
+				.println("This test doesnt play a file; you shouldnt hear anything");
+
+		File soundFile = new File("testsounds/startup.wav");
+		final AudioInputStream audioInputStream = AudioSystem
+				.getAudioInputStream(soundFile);
+		final AudioFormat audioFormat = audioInputStream.getFormat();
+
+		sourceDataLine = (SourceDataLine) mixer.getLine(new DataLine.Info(
+				SourceDataLine.class, audioFormat));
+		Assert.assertNotNull(sourceDataLine);
+
+		Thread writer = new Thread() {
+			@Override
+			public void run() {
+				try {
+					sourceDataLine.open(audioFormat);
+					byte[] abData = new byte[1000];
+					int bytesRead = 0;
+					int total = 0;
+
+					while (bytesRead >= 0 && total < 50) {
+						bytesRead = audioInputStream.read(abData, 0,
+								abData.length);
+						if (bytesRead > 0) {
+							sourceDataLine.write(abData, 0, bytesRead);
+						}
+						total++;
+					}
+				} catch (LineUnavailableException e) {
+					Assert.fail();
+				} catch (IOException e) {
+					Assert.fail();
+				}
+			}
+
+		};
+
+		writer.start();
+
+		Thread.sleep(100);
+
+		writer.join(1000);
+
+		/* assert that the writer is still waiting in write */
+		Assert.assertTrue(writer.isAlive());
+
+	}
+
+	@Test
 	public void testWriteAndClose() throws UnsupportedAudioFileException,
 			IOException, LineUnavailableException, InterruptedException {
 		System.out.println("This test tires to close the line during a write");
@@ -393,6 +446,9 @@
 	public void testStartedStopped() throws LineUnavailableException,
 			UnsupportedAudioFileException, IOException {
 
+		System.out
+				.println("This test check START/STOP events. You should see 1 START and 1 STOP event");
+
 		File soundFile = new File("testsounds/startup.wav");
 		AudioInputStream audioInputStream = AudioSystem
 				.getAudioInputStream(soundFile);
@@ -1013,7 +1069,7 @@
 			UnsupportedAudioFileException, IOException, InterruptedException {
 
 		File soundFile = new File("testsounds/logout.wav");
-		AudioInputStream audioInputStream = AudioSystem
+		final AudioInputStream audioInputStream = AudioSystem
 				.getAudioInputStream(soundFile);
 		AudioFormat audioFormat = audioInputStream.getFormat();
 
@@ -1024,29 +1080,39 @@
 		int available = sourceDataLine.available();
 		Assert.assertTrue(available > 1000);
 
-		byte[] abData = new byte[1000];
-		int bytesRead = 0;
+		Thread writer = new Thread() {
+			@Override
+			public void run() {
+				try {
+					final byte[] abData = new byte[100000];
+					int bytesRead = 0;
 
-		bytesRead = audioInputStream.read(abData, 0, abData.length);
-		Assert.assertTrue(bytesRead > 0);
-		sourceDataLine.write(abData, 0, bytesRead);
+					bytesRead = audioInputStream.read(abData, 0, abData.length);
+					Assert.assertTrue(bytesRead > 0);
+
+					sourceDataLine.write(abData, 0, bytesRead);
+				} catch (IOException e) {
 
-		Runnable blocker = new Runnable() {
+				}
+			}
+		};
+
+		Thread drainer = new Thread() {
 			@Override
 			public void run() {
 				sourceDataLine.drain();
 			}
 		};
 
-		Thread th = new Thread(blocker);
-		th.start();
+		writer.start();
+		drainer.start();
 
-		th.join(1000);
+		drainer.join(1000);
 
-		if (th.isAlive()) {
+		if (drainer.isAlive()) {
 			sourceDataLine.close();
-			th.join(1000);
-			if (th.isAlive()) {
+			drainer.join(1000);
+			if (drainer.isAlive()) {
 				Assert
 						.fail("drain() does not return when the line has been closed");
 			} else {
@@ -1091,6 +1157,15 @@
 	}
 
 	@Test
+	public void testFlushWithoutStart() throws LineUnavailableException {
+		sourceDataLine = (SourceDataLine) mixer.getLine(new DataLine.Info(
+				SourceDataLine.class, aSupportedFormat, 1000));
+		sourceDataLine.open();
+		sourceDataLine.flush();
+
+	}
+
+	@Test
 	public void testMixerKnowsAboutOpenLines() throws LineUnavailableException {
 		sourceDataLine = (SourceDataLine) mixer.getLine(new Line.Info(
 				SourceDataLine.class));