Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java (revision 0) @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import javax.sound.sampled.BooleanControl; + +import junit.framework.TestCase; + +public class BooleanControlTest extends TestCase { + + public void testEnumControl() { + + BooleanControl control = new MyControl(BooleanControl.Type.MUTE, true, + "ON", "OFF"); + assertTrue(control.getValue()); + control.setValue(false); + assertFalse(control.getValue()); + assertEquals("ON", control.getStateLabel(true)); + assertEquals("OFF", control.getStateLabel(false)); + assertEquals("Mute Control with current value: OFF", control + .toString()); + + control = new MyControl(BooleanControl.Type.APPLY_REVERB, false); + assertFalse(control.getValue()); + control.setValue(true); + assertTrue(control.getValue()); + assertEquals("true", control.getStateLabel(true)); + assertEquals("false", control.getStateLabel(false)); + assertEquals("Apply Reverb Control with current value: true", control + .toString()); + } + + private class MyControl extends BooleanControl { + public MyControl(BooleanControl.Type type, boolean initialValue, + String trueStateLabel, String falseStateLabel) { + super(type, initialValue, trueStateLabel, falseStateLabel); + } + + public MyControl(BooleanControl.Type type, boolean initialValue) { + super(type, initialValue); + } + } + +} \ No newline at end of file Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java (revision 0) @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import javax.sound.sampled.Line; + +import junit.framework.TestCase; + +public class LineInfoTest extends TestCase { + + public void testMatches() { + + Line.Info info1 = new Line.Info("aaaa".getClass()); + Line.Info info2 = new Line.Info(new Object().getClass()); + + assertTrue(info1.matches(info1)); + assertFalse(info1.matches(info2)); + assertTrue(info2.matches(info1)); + } + +} Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java (revision 0) @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import java.util.Arrays; + +import javax.sound.sampled.EnumControl; + +import junit.framework.TestCase; + +public class EnumControlTest extends TestCase { + + public void testEnumControl() { + Object[] values = new Object[] { "val1", "val2" }; + EnumControl control = new MyControl(EnumControl.Type.REVERB, values, + "val1"); + + assertEquals("val1", control.getValue()); + assertTrue(Arrays.equals(values, control.getValues())); + assertEquals("Reverb with current value: val1", control.toString()); + + control.setValue("val2"); + assertEquals("val2", control.getValue()); + assertTrue(Arrays.equals(values, control.getValues())); + assertEquals("Reverb with current value: val2", control.toString()); + + try { + control.setValue("val3"); + fail("No expected IllegalArgumentException"); + } catch (IllegalArgumentException expected) { + } + } + + private class MyControl extends EnumControl { + public MyControl(EnumControl.Type type, Object[] values, Object value) { + super(type, values, value); + } + } + +} Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java (revision 0) @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import java.util.HashMap; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; + +import junit.framework.TestCase; + +public class AudioFormatTest extends TestCase { + + public void testAudioFormat() { + AudioFormat format = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, + 3, 4, 5f, true); + + assertEquals(AudioFormat.Encoding.ALAW, format.getEncoding()); + assertEquals(1f, format.getSampleRate()); + assertEquals(2, format.getSampleSizeInBits()); + assertEquals(3, format.getChannels()); + assertEquals(4, format.getFrameSize()); + assertEquals(5f, format.getFrameRate()); + assertTrue(format.isBigEndian()); + assertTrue(format.properties().isEmpty()); + + HashMap prop = new HashMap(); + prop.put("bitrate", Integer.valueOf(100)); + prop.put("vbr", Boolean.TRUE); + format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 5f, 4, 3, 2, + 1f, false, prop); + assertEquals(5f, format.getSampleRate()); + assertEquals(4, format.getSampleSizeInBits()); + assertEquals(3, format.getChannels()); + assertEquals(2, format.getFrameSize()); + assertEquals(1f, format.getFrameRate()); + assertFalse(format.isBigEndian()); + assertEquals(2, format.properties().size()); + assertEquals(Integer.valueOf(100), format.properties().get("bitrate")); + assertEquals(Boolean.TRUE, format.properties().get("vbr")); + try { + format.properties().put("aa", 1); + fail("No expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + + format = new AudioFormat(1f, 10, 2, true, false); + assertEquals(AudioFormat.Encoding.PCM_SIGNED, format.getEncoding()); + assertEquals(1f, format.getSampleRate()); + assertEquals(10, format.getSampleSizeInBits()); + assertEquals(2, format.getChannels()); + assertEquals(4, format.getFrameSize()); + assertEquals(1f, format.getFrameRate()); + assertFalse(format.isBigEndian()); + assertTrue(format.properties().isEmpty()); + + } + + public void testMatches() { + AudioFormat format; + AudioFormat format1; + + format = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 4, 5f, + true); + assertTrue(format.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 4, 5f, + true); + assertTrue(format.matches(format1)); + + format1 = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 1f, 2, 3, 4, + 5f, true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 2f, 2, 3, 4, 5f, + true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 3, 3, 4, 5f, + true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 4, 4, 5f, + true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 5, 5f, + true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 4, 6f, + true); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 4, 5f, + false); + assertTrue(format.matches(format1)); + assertTrue(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, + AudioSystem.NOT_SPECIFIED, 2, 3, 4, 5f, true); + assertTrue(format.matches(format1)); + assertFalse(format1.matches(format)); + + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, 4, + AudioSystem.NOT_SPECIFIED, true); + assertTrue(format.matches(format1)); + assertFalse(format1.matches(format)); + + format = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 10, 3, 4, 5f, + true); + format1 = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 10, 3, 4, 5f, + false); + assertFalse(format.matches(format1)); + assertFalse(format1.matches(format)); + } + +} \ No newline at end of file Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java (revision 0) @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import java.util.HashMap; + +import javax.sound.sampled.AudioFileFormat; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; + +import junit.framework.TestCase; + +public class AudioFileFormatTest extends TestCase { + + public void testAudioFileFormat() { + AudioFormat af = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3, + 4, 5f, true); + + AudioFileFormat aff = new MyAudioFileFormat(AudioFileFormat.Type.AIFC, + AudioSystem.NOT_SPECIFIED, af, 100); + assertEquals(AudioFileFormat.Type.AIFC, aff.getType()); + assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength()); + assertEquals(af, aff.getFormat()); + assertEquals(100, aff.getFrameLength()); + assertNull(aff.properties()); + assertNull(aff.getProperty("key")); + + aff = new AudioFileFormat(AudioFileFormat.Type.WAVE, af, 10); + assertEquals(AudioFileFormat.Type.WAVE, aff.getType()); + assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength()); + assertEquals(af, aff.getFormat()); + assertEquals(10, aff.getFrameLength()); + assertNull(aff.properties()); + assertNull(aff.getProperty("key")); + + HashMap prop = new HashMap(); + prop.put("duration", Long.valueOf(100)); + prop.put("title", "Title String"); + aff = new AudioFileFormat(AudioFileFormat.Type.AU, af, + AudioSystem.NOT_SPECIFIED, prop); + assertEquals(AudioFileFormat.Type.AU, aff.getType()); + assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength()); + assertEquals(af, aff.getFormat()); + assertEquals(AudioSystem.NOT_SPECIFIED, aff.getFrameLength()); + assertEquals(2, aff.properties().size()); + assertEquals(Long.valueOf(100), aff.properties().get("duration")); + assertNull(aff.getProperty("key")); + assertEquals("Title String", aff.getProperty("title")); + try { + aff.properties().put("aa", 1); + fail("No expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + + } + + private class MyAudioFileFormat extends AudioFileFormat { + public MyAudioFileFormat(AudioFileFormat.Type type, int byteLength, + AudioFormat format, int frameLength) { + super(type, byteLength, format, frameLength); + } + } + +} \ No newline at end of file Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java (revision 0) @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.IOException; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioFormat; + +import junit.framework.TestCase; + +public class AudioInputStreamTest extends TestCase { + + public void testAudioInputStream() throws Exception { + InputStream is = new ByteArrayInputStream(new byte[1001]); + AudioFormat format = new AudioFormat(1f, 16, 2, true, false); + + AudioInputStream ais = new AudioInputStream(is, format, 10); + + assertEquals(format, ais.getFormat()); + assertEquals(10, ais.getFrameLength()); + assertEquals(40, ais.available()); + assertEquals(8, ais.read(new byte[10])); + assertEquals(32, ais.available()); + assertTrue(ais.markSupported()); + ais.mark(1000); + assertEquals(8, ais.read(new byte[10])); + assertEquals(24, ais.available()); + assertEquals(0, ais.skip(2)); + assertEquals(8, ais.skip(10)); + ais.reset(); + assertEquals(32, ais.available()); + assertEquals(0, ais.read(new byte[10], -1, 2)); + assertEquals(8, ais.read(new byte[10], 0, 11)); + try { + ais.read(); + fail("No expected IOException"); + } catch (IOException expected) { + } + ais.close(); // no exception expected + + is = new ByteArrayInputStream(new byte[1001]); + ais = new AudioInputStream(is, format, 500); + + assertEquals(format, ais.getFormat()); + assertEquals(500, ais.getFrameLength()); + assertEquals(1001, ais.available()); + assertEquals(8, ais.read(new byte[10])); + assertEquals(993, ais.available()); + ais.mark(1000); + assertEquals(8, ais.read(new byte[10])); + assertEquals(985, ais.available()); + assertEquals(0, ais.skip(2)); + assertEquals(8, ais.skip(10)); + ais.reset(); + assertEquals(993, ais.available()); + assertEquals(0, ais.read(new byte[10], -1, 2)); + assertEquals(8, ais.read(new byte[10], 0, 11)); + try { + ais.read(); + fail("No expected IOException"); + } catch (IOException expected) { + } + ais.close(); // no exception expected + } + +} Index: modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java =================================================================== --- modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java (revision 0) +++ modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java (revision 0) @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.sound.tests.javax.sound.sampled; + +import java.util.Arrays; + +import javax.sound.sampled.DataLine; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; + +import junit.framework.TestCase; + +public class DataLineInfoTest extends TestCase { + + public void testDataLineInfo() { + AudioFormat format = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 8, + 3, 4, 5f, true); + AudioFormat format1 = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, + 1f, 8, 3, 4, 5f, true); + + DataLine.Info info = new DataLine.Info("aaaa".getClass(), format, 5); + assertEquals(1, info.getFormats().length); + assertEquals(format, info.getFormats()[0]); + assertTrue(info.isFormatSupported(format)); + assertFalse(info.isFormatSupported(format1)); + assertEquals(5, info.getMinBufferSize()); + assertEquals(5, info.getMaxBufferSize()); + + info = new DataLine.Info("aaaa".getClass(), format); + assertEquals(1, info.getFormats().length); + assertEquals(format, info.getFormats()[0]); + assertTrue(info.isFormatSupported(format)); + assertFalse(info.isFormatSupported(format1)); + assertEquals(AudioSystem.NOT_SPECIFIED, info.getMinBufferSize()); + assertEquals(AudioSystem.NOT_SPECIFIED, info.getMaxBufferSize()); + assertEquals( + "class java.lang.String supporting format ALAW 1.0 Hz, 8 bit, 3 channels, 4 bytes/frame, 5.0 frames/second, ", + info.toString()); + + AudioFormat[] formats = new AudioFormat[] { format, format1 }; + info = new DataLine.Info(new Object().getClass(), formats, 1, 10); + assertEquals(2, info.getFormats().length); + assertTrue(Arrays.equals(formats, info.getFormats())); + assertTrue(info.isFormatSupported(format)); + assertTrue(info.isFormatSupported(format1)); + assertEquals(1, info.getMinBufferSize()); + assertEquals(10, info.getMaxBufferSize()); + assertEquals( + "class java.lang.Object supporting 2 audio formats, and buffers of 1 to 10 bytes", + info.toString()); + + } + + public void testMatches() { + AudioFormat format = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 8, + 3, 4, 5f, true); + DataLine.Info info1 = new DataLine.Info("aaaa".getClass(), format); + DataLine.Info info2 = new DataLine.Info(new Object().getClass(), format); + + assertTrue(info1.matches(info1)); + assertFalse(info1.matches(info2)); + assertTrue(info2.matches(info1)); + + info2 = new DataLine.Info("aaaa".getClass(), format, 5); + assertTrue(info1.matches(info2)); + assertTrue(info2.matches(info1)); + + info1 = new DataLine.Info("aaaa".getClass(), format, 4); + assertFalse(info1.matches(info2)); + assertFalse(info2.matches(info1)); + + info2 = new DataLine.Info("aaaa".getClass(), + new AudioFormat[] { format }, 3, 5); + assertTrue(info1.matches(info2)); + assertFalse(info2.matches(info1)); + + AudioFormat format1 = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, + 1f, 8, 3, 4, 5f, true); + info1 = new DataLine.Info("aaaa".getClass(), new AudioFormat[] { + format, format1 }, 3, 5); + assertFalse(info1.matches(info2)); + assertTrue(info2.matches(info1)); + + } + +}