Path: blob/master/test/jdk/javax/sound/sampled/Clip/OpenNonIntegralNumberOfSampleframes.java
41153 views
/*1* Copyright (c) 2016, 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*/2223import java.util.ArrayList;24import java.util.List;2526import javax.sound.sampled.AudioFormat;27import javax.sound.sampled.AudioFormat.Encoding;28import javax.sound.sampled.AudioSystem;29import javax.sound.sampled.Clip;30import javax.sound.sampled.LineUnavailableException;3132/**33* @test34* @bug 816743535*/36public final class OpenNonIntegralNumberOfSampleframes {3738/**39* We will try to use all formats, in this case all our providers will be40* covered by supported/unsupported formats.41*/42private static final List<AudioFormat> formats = new ArrayList<>(2900);4344private static final Encoding[] encodings = {45Encoding.ALAW, Encoding.ULAW, Encoding.PCM_SIGNED,46Encoding.PCM_UNSIGNED, Encoding.PCM_FLOAT47};4849private static final int[] sampleRates = {508000, 11025, 16000, 32000, 4410051};5253private static final int[] sampleBits = {544, 8, 11, 16, 20, 24, 32, 48, 64, 12855};5657private static final int[] channels = {581, 2, 3, 4, 5, 659};6061static {62for (final Boolean end : new boolean[]{false, true}) {63for (final int sampleSize : sampleBits) {64for (final int sampleRate : sampleRates) {65for (final int channel : channels) {66final int frameSize = ((sampleSize + 7) / 8) * channel;67if (frameSize == 1) {68// frameSize=1 is ok for any buffers, skip it69continue;70}71for (final Encoding enc : encodings) {72formats.add(73new AudioFormat(enc, sampleRate, sampleSize,74channel, frameSize,75sampleRate, end));76}77}78}79}80}81}8283public static void main(final String[] args) {84for (final AudioFormat af : formats) {85try (Clip clip = AudioSystem.getClip()) {86final int bufferSize = af.getFrameSize() + 1;87try {88clip.open(af, new byte[100], 0, bufferSize);89} catch (final IllegalArgumentException ignored) {90// expected exception91continue;92} catch (final LineUnavailableException e) {93// should not occur, we passed incorrect bufferSize94e.printStackTrace();95}96System.err.println("af = " + af);97System.err.println("bufferSize = " + bufferSize);98throw new RuntimeException("Expected exception is not thrown");99} catch (IllegalArgumentException100| LineUnavailableException ignored) {101// the test is not applicable102}103}104}105}106107108