changeset 64:748e7984cd83

2008-08-12 Omair Majid <omajid@redhat.com> * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java: fixed getControl(); implemented isControlSupported() * unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java: added two tests for checking controls
author Omair Majid <omajid@redhat.com>
date Tue, 12 Aug 2008 10:31:11 -0400
parents 3887b2fc72a5
children 573735d22e54
files src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
diffstat 2 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Tue Aug 12 10:09:01 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Tue Aug 12 10:31:11 2008 -0400
@@ -47,7 +47,6 @@
 
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.BooleanControl;
 import javax.sound.sampled.Control;
 import javax.sound.sampled.DataLine;
 import javax.sound.sampled.LineEvent;
@@ -395,13 +394,15 @@
 			defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 22050, 8, 2,
 					2, AudioSystem.NOT_SPECIFIED, false);
 		}
-		
+
 		open(defaultFormat, DEFAULT_BUFFER_SIZE);
 	}
 
 	@Override
 	public int write(byte[] data, int offset, int length) {
 
+		// TODO add check that the data is an integral number of frames
+
 		int position = offset;
 		int remainingLength = length;
 		int availableSize;
@@ -543,8 +544,7 @@
 
 	public Control getControl(Type control) {
 		for (int i = 0; i < controls.length; i++) {
-			if (controls[i].getType() == control) {
-
+			if (controls[i].getType().getClass() == control.getClass()) {
 				return controls[i];
 			}
 		}
@@ -561,7 +561,11 @@
 	}
 
 	public boolean isControlSupported(Type control) {
-		// TODO Auto-generated method stub
+		for (Control myControl: controls) {
+			if (myControl.getType().getClass() == control.getClass()) {
+				return true;
+			}
+		}
 		return false;
 	}
 
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java	Tue Aug 12 10:09:01 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java	Tue Aug 12 10:31:11 2008 -0400
@@ -106,7 +106,8 @@
 
 	@Test
 	public void testFindLineWithFormat() throws LineUnavailableException {
-		System.out.println("This test tries to find a line with a valid format");
+		System.out
+				.println("This test tries to find a line with a valid format");
 		AudioFormat wantedFormat = new AudioFormat(
 				AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
 		System.out.println(wantedFormat);
@@ -131,16 +132,8 @@
 
 	@Test
 	public void testVolumeAndMute() throws Exception {
-		Mixer.Info mixerInfos[] = AudioSystem.getMixerInfo();
-		Mixer.Info selectedMixerInfo = null;
-		for (Mixer.Info info : mixerInfos) {
-			if (info.getName().contains("PulseAudio")) {
-				selectedMixerInfo = info;
-				System.out.println(selectedMixerInfo);
-			}
-		}
 
-		Mixer selectedMixer = AudioSystem.getMixer(selectedMixerInfo);
+		Mixer selectedMixer = mixer;
 
 		selectedMixer.open();
 		SourceDataLine line = (SourceDataLine) selectedMixer
@@ -179,6 +172,24 @@
 
 	}
 
+	@Test
+	public void testFindControl() throws LineUnavailableException {
+		SourceDataLine sourceLine = (SourceDataLine) mixer
+				.getLine(new Line.Info(SourceDataLine.class));
+		Assert.assertTrue(sourceLine.getControls().length > 0);
+	}
+
+	
+	@Test
+	public void testSupportedControls() throws LineUnavailableException {
+		SourceDataLine sourceLine = (SourceDataLine) mixer
+				.getLine(new Line.Info(SourceDataLine.class));
+		sourceLine.open();
+		Assert.assertTrue(sourceLine.isControlSupported(FloatControl.Type.VOLUME));
+		Assert.assertTrue(sourceLine.isControlSupported(BooleanControl.Type.MUTE));
+	}
+
+	
 	@After
 	public void tearDown() throws Exception {