Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/sampled/FileReader/ReadersExceptions.java
38855 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324import java.io.ByteArrayInputStream;25import java.io.IOException;26import java.io.InputStream;2728import javax.sound.sampled.AudioSystem;29import javax.sound.sampled.UnsupportedAudioFileException;3031/**32* @test33* @bug 7058662 7058666 705867234* @author Sergey Bylokhov35*/36public final class ReadersExceptions {3738// empty channels39static byte[] wrongAIFFCh =40{0x46, 0x4f, 0x52, 0x4d, // AiffFileFormat.AIFF_MAGIC410, 0, 0, 0, // length420, 0, 0, 0, // iffType430x43, 0x4f, 0x4d, 0x4d, // chunkName440, 0, 0, 100, // chunkLen450, 0, // channels460, 0, 0, 0, //470, 10 // sampleSize48, 0, 0, 0, 0};49// empty sampleSize50static byte[] wrongAIFFSSL =51{0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC520, 0, 0, 0, // length530, 0, 0, 0, // iffType540x43, 0x4f, 0x4d, 0x4d, // chunkName550, 0, 0, 100, // chunkLen560, 10, // channels570, 0, 0, 0, //580, 0 // sampleSize59, 0, 0, 0, 0};60// big sampleSize61static byte[] wrongAIFFSSH =62{0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC630, 0, 0, 0, // length640, 0, 0, 0, // iffType650x43, 0x4f, 0x4d, 0x4d, // chunkName660, 0, 0, 100, // chunkLen670, 10, // channels680, 0, 0, 0, //690, 33 // sampleSize70, 0, 0, 0, 0};71// empty channels72static byte[] wrongAUCh =73{0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC740, 0, 0, 0, // headerSize750, 0, 0, 0, // dataSize760, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8770, 0, 0, 0, // sampleRate780, 0, 0, 0 // channels79};80// empty channels81static byte[] wrongWAVCh =82{0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC831, 1, 1, 1, // fileLength840x57, 0x41, 0x56, 0x45, // waveMagic850x66, 0x6d, 0x74, 0x20, // FMT_MAGIC863, 0, 0, 0, // length871, 0, // wav_type WAVE_FORMAT_PCM880, 0, // channels890, 0, 0, 0, // sampleRate900, 0, 0, 0, // avgBytesPerSec910, 0, // blockAlign921, 0, // sampleSizeInBits930x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC940, 0, 0, 0, // dataLength95};96// empty sampleSizeInBits97static byte[] wrongWAVSSB =98{0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC991, 1, 1, 1, // fileLength1000x57, 0x41, 0x56, 0x45, // waveMagic1010x66, 0x6d, 0x74, 0x20, // FMT_MAGIC1023, 0, 0, 0, // length1031, 0, // wav_type WAVE_FORMAT_PCM1041, 0, // channels1050, 0, 0, 0, // sampleRate1060, 0, 0, 0, // avgBytesPerSec1070, 0, // blockAlign1080, 0, // sampleSizeInBits1090x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC1100, 0, 0, 0, // dataLength111};112113public static void main(final String[] args) throws IOException {114test(wrongAIFFCh);115test(wrongAIFFSSL);116test(wrongAIFFSSH);117test(wrongAUCh);118test(wrongWAVCh);119test(wrongWAVSSB);120}121122private static void test(final byte[] buffer) throws IOException {123final InputStream is = new ByteArrayInputStream(buffer);124try {125AudioSystem.getAudioFileFormat(is);126} catch (UnsupportedAudioFileException ignored) {127// Expected.128return;129}130throw new RuntimeException("Test Failed");131}132}133134135