You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/11/29 06:49:08 UTC
svn commit: r480422 - in /harmony/enhanced/classlib/trunk/modules/sound/src:
main/java/javax/sound/sampled/
test/java/org/apache/harmony/sound/tests/javax/sound/sampled/
Author: smishura
Date: Tue Nov 28 21:49:05 2006
New Revision: 480422
URL: http://svn.apache.org/viewvc?view=rev&rev=480422
Log:
Apply patch for HARMONY-2329 ([classlib][sound] javax.sound.sampled unit tests)
Added:
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java (with props)
harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFileFormat.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFormat.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioInputStream.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/BooleanControl.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/DataLine.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/EnumControl.java
harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/Line.java
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFileFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFileFormat.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFileFormat.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFileFormat.java Tue Nov 28 21:49:05 2006
@@ -81,6 +81,13 @@
return Collections.unmodifiableMap(prop);
}
+ public Object getProperty(String key) {
+ if (prop == null) {
+ return null;
+ }
+ return prop.get(key);
+ }
+
public String toString() {
return type + " (." + type.getExtension() + ") file, data format: " + format + //$NON-NLS-1$ //$NON-NLS-2$
" frame length: " + frameLength; //$NON-NLS-1$
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFormat.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFormat.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioFormat.java Tue Nov 28 21:49:05 2006
@@ -129,9 +129,10 @@
this.sampleSizeInBits = sampleSizeInBits;
this.channels = channels;
this.frameSize = sampleSizeInBits >> 3;
- if ((sampleSizeInBits & 0x7) == 0) {
+ if ((sampleSizeInBits & 0x7) != 0) {
this.frameSize++;
}
+ this.frameSize *= channels;
this.frameRate = sampleRate;
this.bigEndian = bigEndian;
@@ -194,6 +195,11 @@
if (format.getFrameRate() != AudioSystem.NOT_SPECIFIED &&
frameRate != format.getFrameRate()) {
+ return false;
+ }
+
+ if ((sampleSizeInBits > 8)
+ && (bigEndian != format.isBigEndian())) {
return false;
}
return true;
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioInputStream.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioInputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/AudioInputStream.java Tue Nov 28 21:49:05 2006
@@ -38,6 +38,8 @@
private byte[] oneByte = new byte[1];
+ private long marketFramePos;
+
public AudioInputStream(InputStream stream, AudioFormat format, long length) {
this.stream = stream;
this.format = format;
@@ -67,11 +69,14 @@
}
int res;
if (stream != null) { // InputStream
+ if (framePos == frameLength) {
+ return 0;
+ }
res = stream.read();
if (res == -1) {
return -1;
}
- framePos = +1;
+ framePos += 1;
return res;
} else { // TargetDataLine
if (line.read(oneByte, 0, 1) == 0) {
@@ -87,7 +92,11 @@
}
public int read(byte[] b, int off, int len) throws IOException {
- int l = len - (len % frameSize);
+ int l = Math.min(len, (int) ((frameLength - framePos) * frameSize));
+ l = l - (l % frameSize);
+ if (l == 0) {
+ return 0;
+ }
int res;
if (stream != null) { // InputStream
res = stream.read(b, off, l);
@@ -130,7 +139,8 @@
public int available() throws IOException {
if (stream != null) { // InputStream
- return stream.available();
+ return Math.min(stream.available(),
+ (int)((frameLength - framePos) * frameSize));
} else { // TargetDataLine
return line.available();
}
@@ -145,8 +155,9 @@
}
public void mark(int readlimit) {
- if (stream != null) { //I nputStream
+ if (stream != null) { //InputStream
stream.mark(readlimit);
+ marketFramePos = framePos;
} else { // TargetDataLine
// do nothing
}
@@ -155,6 +166,7 @@
public void reset() throws IOException {
if (stream != null) { //InputStream
stream.reset();
+ framePos = marketFramePos;
} else { // TargetDataLine
// do nothing
}
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/BooleanControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/BooleanControl.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/BooleanControl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/BooleanControl.java Tue Nov 28 21:49:05 2006
@@ -64,6 +64,6 @@
}
public String toString() {
- return getType() + " Control with current value: " + value; //$NON-NLS-1$
+ return getType() + " Control with current value: " + getStateLabel(value); //$NON-NLS-1$
}
}
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/DataLine.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/DataLine.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/DataLine.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/DataLine.java Tue Nov 28 21:49:05 2006
@@ -80,8 +80,12 @@
}
DataLine.Info inf = (DataLine.Info)info;
- if (minBufferSize < inf.getMinBufferSize() ||
- maxBufferSize > inf.getMaxBufferSize()) {
+ if ((minBufferSize != AudioSystem.NOT_SPECIFIED
+ && inf.getMinBufferSize() != AudioSystem.NOT_SPECIFIED
+ && minBufferSize < inf.getMinBufferSize())
+ || (maxBufferSize != AudioSystem.NOT_SPECIFIED
+ && inf.getMaxBufferSize() != AudioSystem.NOT_SPECIFIED
+ && maxBufferSize > inf.getMaxBufferSize())) {
return false;
}
@@ -96,14 +100,14 @@
@Override
public String toString() {
- String formatStr = (formats.length == 1? formats[0].toString()
+ String formatStr = (formats.length == 1? "format " + formats[0].toString() //$NON-NLS-1$
: formats.length + " audio formats"); //$NON-NLS-1$
String bufStr = ""; //$NON-NLS-1$
if (minBufferSize != AudioSystem.NOT_SPECIFIED) {
- bufStr = ", and buffers of " + minBufferSize + //$NON-NLS-1$
- "to " + maxBufferSize + " bytes"; //$NON-NLS-1$ //$NON-NLS-2$
+ bufStr = "and buffers of " + minBufferSize + //$NON-NLS-1$
+ " to " + maxBufferSize + " bytes"; //$NON-NLS-1$ //$NON-NLS-2$
}
- return getLineClass() + " supporting " + formatStr + bufStr; //$NON-NLS-1$
+ return getLineClass() + " supporting " + formatStr + ", " + bufStr; //$NON-NLS-1$
}
}
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/EnumControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/EnumControl.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/EnumControl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/EnumControl.java Tue Nov 28 21:49:05 2006
@@ -21,7 +21,7 @@
public abstract class EnumControl extends Control {
public static class Type extends Control.Type {
- public static final Type REVERB = new Type("REVERB"); //$NON-NLS-1$
+ public static final Type REVERB = new Type("Reverb"); //$NON-NLS-1$
protected Type(String name) {
super(name);
Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/Line.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/Line.java?view=diff&rev=480422&r1=480421&r2=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/Line.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/sampled/Line.java Tue Nov 28 21:49:05 2006
@@ -33,7 +33,7 @@
}
public boolean matches(Line.Info info) throws NotImplementedException {
- throw new NotImplementedException("not yet implemented");
+ return lineClass.isAssignableFrom(info.getLineClass());
}
@Override
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java Tue Nov 28 21:49:05 2006
@@ -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<String, Object> prop = new HashMap<String, Object>();
+ 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
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFileFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java Tue Nov 28 21:49:05 2006
@@ -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<String, Object> prop = new HashMap<String, Object>();
+ 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
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java Tue Nov 28 21:49:05 2006
@@ -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
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/AudioInputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java Tue Nov 28 21:49:05 2006
@@ -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
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/BooleanControlTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java Tue Nov 28 21:49:05 2006
@@ -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));
+
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/DataLineInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java Tue Nov 28 21:49:05 2006
@@ -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);
+ }
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/EnumControlTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java?view=auto&rev=480422
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java Tue Nov 28 21:49:05 2006
@@ -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));
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/sampled/LineInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native