Mercurial > hg > pulseaudio
changeset 66:8f4e01b67c92
2008-08-12 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java: fixed notification of line listeners multiple times during a close(). cleared all the line listeners when a close is done(). fixed getControl() to throw an exception because no controls are supported. fixed getControls() to return an array of length 0.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java: if the line hasnt been opened, getControl() now throws an exception and getControls() returns an array of length 0
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java: fixed the listener tests to make sure that the listeners are called only once
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Tue, 12 Aug 2008 11:28:22 -0400 |
parents | 573735d22e54 |
children | 856e11044f24 |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java |
diffstat | 3 files changed, 40 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Tue Aug 12 10:51:02 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Tue Aug 12 11:28:22 2008 -0400 @@ -265,24 +265,23 @@ // System.out.println(this.getClass().getName() + ": closed"); this.isOpen = false; - fireEvent(new LineEvent(this, LineEvent.Type.CLOSE, - AudioSystem.NOT_SPECIFIED)); - /* - * FIXME need to clean up the listeners on close without a race - * condition - */ + synchronized (lineListeners) { + lineListeners.clear(); + } } @Override public Control getControl(Type control) { - return null; + // mixer supports no controls + throw new IllegalArgumentException(); } @Override public Control[] getControls() { - return null; + // mixer supports no controls; return an array of length 0 + return new Control[] {}; } @Override @@ -293,7 +292,7 @@ @Override public boolean isControlSupported(Type control) { - // FIXME + // mixer supports no controls return false; }
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Tue Aug 12 10:51:02 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Tue Aug 12 11:28:22 2008 -0400 @@ -544,6 +544,11 @@ } public Control getControl(Type control) { + if (!isOpen) { + throw new IllegalArgumentException( + "Controls only supported when line is open"); + } + for (int i = 0; i < controls.length; i++) { if (controls[i].getType().getClass() == control.getClass()) { return controls[i]; @@ -553,7 +558,12 @@ } public Control[] getControls() { - return controls; + if (isOpen) { + return controls; + } else { + return new Control[] {}; + } + } public javax.sound.sampled.Line.Info getLineInfo() { @@ -562,7 +572,7 @@ } public boolean isControlSupported(Type control) { - for (Control myControl: controls) { + for (Control myControl : controls) { if (myControl.getType().getClass() == control.getClass()) { return true; }
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Tue Aug 12 10:51:02 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Tue Aug 12 11:28:22 2008 -0400 @@ -52,6 +52,7 @@ import junit.framework.JUnit4TestAdapter; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -157,8 +158,8 @@ @Test public void testOpeningAgain() throws LineUnavailableException, UnsupportedOperationException { - selectedMixer.open(); - selectedMixer.open(); + selectedMixer.open(); + selectedMixer.open(); } @Test @@ -172,14 +173,12 @@ 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 + * 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 * */ Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo(); @@ -196,9 +195,14 @@ @Test public void testOpenEvent() throws LineUnavailableException { LineListener listener = new LineListener() { + private int called = 0; + @Override public void update(LineEvent event) { assert (event.getType() == LineEvent.Type.OPEN); + called++; + // assert listener is called exactly once + Assert.assertEquals(1,called); } }; @@ -212,9 +216,15 @@ @Test public void testCloseEvent() throws LineUnavailableException { LineListener listener = new LineListener() { + private int count = 0; + @Override public void update(LineEvent event) { - assert (event.getType() == LineEvent.Type.CLOSE); + Assert.assertTrue(event.getType() == LineEvent.Type.CLOSE); + count++; + // assert listener is called exactly once + Assert.assertEquals(1, count); + } };