changeset 89:52b513a7e5e9

2008-08-19 Omair Majid <omajid@redhat.com> * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java (testSourceLinesExist): Added more asserts. (testTargetLinesExist): New function. (testGetTargetPortInfo): Likewise. (testGetSourcePortInfo): Likewise. (testHeadphonePortExists): Likewise. (testSpeakerPortExists): Likewise. (testLineInPortExists): Likewise. (testCdPortExists): Likewise. (testLineOutPortExists): Likewise. (testMicrophonePortExists): Likewise. (testSourceLinesOpenAndClose): Fixed test by using a known working format. (testTargetLinesOpenAndClose): New function. Similar to testSourceLinesOpenAndClose.
author Omair Majid <omajid@redhat.com>
date Tue, 19 Aug 2008 11:35:27 -0400
parents 6dd17faac024
children 0ab3515d5074
files unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
diffstat 1 files changed, 115 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Tue Aug 19 10:04:12 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Tue Aug 19 11:35:27 2008 -0400
@@ -41,13 +41,17 @@
 
 import java.net.UnknownHostException;
 
+import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.Line;
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Mixer;
+import javax.sound.sampled.Port;
 import javax.sound.sampled.SourceDataLine;
+import javax.sound.sampled.TargetDataLine;
+import javax.sound.sampled.Line.Info;
 
 import junit.framework.JUnit4TestAdapter;
 
@@ -144,6 +148,8 @@
 	public void testSourceLinesExist() throws LineUnavailableException {
 		selectedMixer.open();
 		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
+		Assert.assertNotNull(allLineInfo);
+		Assert.assertTrue(allLineInfo.length > 0);
 		int j = 0;
 		for (Line.Info lineInfo : allLineInfo) {
 			System.out.println("Source Line " + j++ + ": "
@@ -157,6 +163,90 @@
 	}
 
 	@Test
+	public void testTargetLinesExist() throws LineUnavailableException {
+		selectedMixer.open();
+		Line.Info allLineInfo[] = selectedMixer.getTargetLineInfo();
+		Assert.assertNotNull(allLineInfo);
+		Assert.assertTrue(allLineInfo.length > 0);
+		int j = 0;
+		for (Line.Info lineInfo : allLineInfo) {
+			System.out.println("Target Line " + j++ + ": "
+					+ lineInfo.getLineClass());
+			TargetDataLine targetDataLine = (TargetDataLine) selectedMixer
+					.getLine(lineInfo);
+			assertNotNull(targetDataLine);
+
+		}
+
+	}
+
+	@Test
+	public void testGetTargetPortInfo() throws LineUnavailableException {
+		selectedMixer.open();
+		Line.Info[] lineInfos = selectedMixer.getTargetLineInfo();
+		int i = 0;
+		for (Line.Info info : lineInfos) {
+			if (info instanceof Port.Info) {
+				Port.Info portInfo = (Port.Info) info;
+				System.out.println("Port " + ++i + ": " + portInfo.getName()
+						+ " - " + portInfo.getLineClass());
+			}
+		}
+
+	}
+
+	@Test
+	public void testGetSourcePortInfo() throws LineUnavailableException {
+		selectedMixer.open();
+		Line.Info[] lineInfos = selectedMixer.getSourceLineInfo();
+		int i = 0;
+		for (Line.Info info : lineInfos) {
+			if (info instanceof Port.Info) {
+				Port.Info portInfo = (Port.Info) info;
+				System.out.println("Port " + ++i + ": " + portInfo.getName()
+						+ " - " + portInfo.getLineClass());
+			}
+		}
+
+	}
+
+	@Test
+	public void testHeadphonePortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.HEADPHONE);
+	}
+
+	@Test
+	public void testSpeakerPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.SPEAKER);
+	}
+
+	@Test
+	public void testLineInPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.LINE_IN);
+	}
+
+	@Test
+	public void testCdPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.COMPACT_DISC);
+	}
+
+	@Test
+	public void testLineOutPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.LINE_OUT);
+	}
+
+	@Test
+	public void testMicrophonePortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.MICROPHONE);
+	}
+
+	@Test
 	public void testOpeningAgain() throws LineUnavailableException,
 			UnsupportedOperationException {
 		selectedMixer.open();
@@ -170,30 +260,45 @@
 		selectedMixer.close();
 	}
 
-	@Test @Ignore 
+	@Test
 	public void testSourceLinesOpenAndClose() throws LineUnavailableException {
 		System.out.println("This test checks if source lines open and close");
 		selectedMixer.open();
 
-		/*
-		 * FIXME This test currently fails. The mixer returns information about
-		 * the line which leaves a lot of things as NOT_SPECIFIED when using
-		 * that to do a get line, things match, and the line returned still has
-		 * a few parameters as NOT_SPECIFIED and doing an open() on that fails
-		 * 
-		 */
+		AudioFormat wantedFormat = new AudioFormat(
+				AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
+
 		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
 		for (Line.Info lineInfo : allLineInfo) {
 			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer
 					.getLine(lineInfo);
 			System.out.println("opening line");
-			sourceDataLine.open();
+			sourceDataLine.open(wantedFormat);
 			System.out.println("closing line");
 			sourceDataLine.close();
 		}
 	}
 
 	@Test
+	public void testTargetLinesOpenAndClose() throws LineUnavailableException {
+		System.out.println("This test checks if source lines open and close");
+		selectedMixer.open();
+
+		AudioFormat wantedFormat = new AudioFormat(
+				AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
+
+		Line.Info allLineInfo[] = selectedMixer.getTargetLineInfo();
+		for (Line.Info lineInfo : allLineInfo) {
+			TargetDataLine targetDataLine = (TargetDataLine) selectedMixer
+					.getLine(lineInfo);
+			System.out.println("opening line");
+			targetDataLine.open(wantedFormat);
+			System.out.println("closing line");
+			targetDataLine.close();
+		}
+	}
+
+	@Test
 	public void testOpenEvent() throws LineUnavailableException {
 		LineListener listener = new LineListener() {
 			private int called = 0;
@@ -203,7 +308,7 @@
 				assert (event.getType() == LineEvent.Type.OPEN);
 				called++;
 				// assert listener is called exactly once
-				Assert.assertEquals(1,called);
+				Assert.assertEquals(1, called);
 			}
 		};