TestGetSoundbankInputStream2.java revision 9330:8b1f1c2a400f
1139749Simp/* 2218909Sbrucec * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. 340024Sgibbs * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 440024Sgibbs * 540024Sgibbs * This code is free software; you can redistribute it and/or modify it 640024Sgibbs * under the terms of the GNU General Public License version 2 only, as 756979Sgibbs * published by the Free Software Foundation. 840024Sgibbs * 956979Sgibbs * This code is distributed in the hope that it will be useful, but WITHOUT 1040024Sgibbs * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1140024Sgibbs * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1240024Sgibbs * version 2 for more details (a copy is included in the LICENSE file that 1340024Sgibbs * accompanied this code). 1440024Sgibbs * 1540024Sgibbs * You should have received a copy of the GNU General Public License version 1640024Sgibbs * 2 along with this work; if not, write to the Free Software Foundation, 1756979Sgibbs * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1840024Sgibbs * 1940024Sgibbs * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2040024Sgibbs * or visit www.oracle.com if you need additional information or have any 2140024Sgibbs * questions. 2240024Sgibbs */ 2340024Sgibbs 2440024Sgibbs/* @test 2540024Sgibbs @summary Test DLSSoundbankReader getSoundbank(InputStream) method using 2640024Sgibbs very bad InputStream which can only read 1 byte at time */ 2740024Sgibbs 2840024Sgibbsimport java.io.BufferedInputStream; 2940024Sgibbsimport java.io.File; 3040024Sgibbsimport java.io.FileInputStream; 3140024Sgibbsimport java.io.IOException; 3240024Sgibbsimport java.io.InputStream; 3340024Sgibbs 3440024Sgibbsimport javax.sound.midi.Patch; 3540024Sgibbsimport javax.sound.midi.Soundbank; 3640024Sgibbs 3740024Sgibbsimport com.sun.media.sound.DLSSoundbankReader; 3840024Sgibbs 3940024Sgibbspublic class TestGetSoundbankInputStream2 { 4040024Sgibbs 4140024Sgibbs private static class BadInputStream extends InputStream 4240024Sgibbs { 4340024Sgibbs 4440024Sgibbs InputStream is; 4540024Sgibbs 46119418Sobrien public BadInputStream(InputStream is) 47119418Sobrien { 48119418Sobrien this.is = is; 4940024Sgibbs } 50241588Sjhb 5140024Sgibbs public int read() throws IOException { 5240024Sgibbs return is.read(); 5340024Sgibbs } 54117126Sscottl 55165102Smjacob public int read(byte[] b, int off, int len) throws IOException { 56117126Sscottl if(len > 1) len = 1; 5756979Sgibbs return is.read(b, off, len); 5840024Sgibbs } 5940024Sgibbs 6056979Sgibbs public int read(byte[] b) throws IOException { 6140024Sgibbs return read(b, 0, b.length); 6256979Sgibbs } 6356979Sgibbs 6440024Sgibbs public long skip(long n) throws IOException { 6540024Sgibbs if(n > 1) n = 1; 6640024Sgibbs return is.skip(n); 6740024Sgibbs } 6840024Sgibbs 6940024Sgibbs public int available() throws IOException { 7040024Sgibbs int avail = is.available(); 7140024Sgibbs if(avail > 1) avail = 1; 7240024Sgibbs return avail; 7340024Sgibbs } 7440024Sgibbs 7540024Sgibbs public void close() throws IOException { 7640024Sgibbs is.close(); 7740024Sgibbs } 7840024Sgibbs 7940024Sgibbs public synchronized void mark(int readlimit) { 8040024Sgibbs is.mark(readlimit); 8140024Sgibbs } 8240024Sgibbs 8340024Sgibbs public boolean markSupported() { 8440024Sgibbs return is.markSupported(); 8540024Sgibbs } 8640024Sgibbs 8740024Sgibbs public synchronized void reset() throws IOException { 8840024Sgibbs is.reset(); 8940024Sgibbs } 9040024Sgibbs 91241588Sjhb } 9240024Sgibbs 9340024Sgibbs private static void assertTrue(boolean value) throws Exception 9440024Sgibbs { 9540024Sgibbs if(!value) 9640024Sgibbs throw new RuntimeException("assertTrue fails!"); 9740024Sgibbs } 9840024Sgibbs 9940024Sgibbs public static void main(String[] args) throws Exception { 10040024Sgibbs File file = new File(System.getProperty("test.src", "."), "ding.dls"); 10140024Sgibbs FileInputStream fis = new FileInputStream(file); 10240024Sgibbs BufferedInputStream bis = new BufferedInputStream(fis); 10340024Sgibbs try 10440024Sgibbs { 10540024Sgibbs InputStream badis = new BadInputStream(bis); 10640024Sgibbs Soundbank dls = new DLSSoundbankReader().getSoundbank(badis); 107241588Sjhb assertTrue(dls.getInstruments().length == 1); 108241588Sjhb Patch patch = dls.getInstruments()[0].getPatch(); 10940024Sgibbs assertTrue(patch.getProgram() == 0); 11040024Sgibbs assertTrue(patch.getBank() == 0); 11140024Sgibbs } 11240024Sgibbs finally 11340024Sgibbs { 11440024Sgibbs bis.close(); 115241588Sjhb } 11640024Sgibbs } 11740024Sgibbs} 11840024Sgibbs