< prev index next >

test/javax/sound/sampled/FileReader/ReadersExceptions.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -19,21 +19,23 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
+import javax.sound.sampled.spi.AudioFileReader;
+
+import static java.util.ServiceLoader.load;
 
 /**
  * @test
- * @bug 7058662 7058666 7058672
+ * @bug 7058662 7058666 7058672 8130305
  * @author Sergey Bylokhov
  */
 public final class ReadersExceptions {
 
     // empty channels

@@ -109,25 +111,42 @@
              0, 0, // sampleSizeInBits
              0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
              0, 0, 0, 0, // dataLength
             };
 
+    static byte[][] data = {wrongAIFFCh, wrongAIFFSSL, wrongAIFFSSH, wrongAUCh,
+                            wrongWAVCh, wrongWAVSSB};
+
     public static void main(final String[] args) throws IOException {
-        test(wrongAIFFCh);
-        test(wrongAIFFSSL);
-        test(wrongAIFFSSH);
-        test(wrongAUCh);
-        test(wrongWAVCh);
-        test(wrongWAVSSB);
+        for (final byte[] bytes : data) {
+            testAS(bytes);
+            testAFR(bytes);
+        }
     }
 
-    private static void test(final byte[] buffer) throws IOException {
+    private static void testAS(final byte[] buffer) throws IOException {
+        // AudioSystem API
         final InputStream is = new ByteArrayInputStream(buffer);
         try {
             AudioSystem.getAudioFileFormat(is);
         } catch (UnsupportedAudioFileException ignored) {
             // Expected.
             return;
         }
         throw new RuntimeException("Test Failed");
     }
+
+    private static void testAFR(final byte[] buffer) throws IOException {
+        // AudioFileReader API
+        final InputStream is = new ByteArrayInputStream(buffer);
+        for (final AudioFileReader afr : load(AudioFileReader.class)) {
+            for (int i = 0; i < 10; ++i) {
+                try {
+                    afr.getAudioFileFormat(is);
+                    throw new RuntimeException("UAFE expected");
+                } catch (final UnsupportedAudioFileException ignored) {
+                    // Expected.
+                }
+            }
+        }
+    }
 }
< prev index next >