Path: blob/master/test/jdk/javax/sound/midi/File/SMPTESequence.java
41153 views
/*1* Copyright (c) 2011, 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*/2223/**24* @test25* @bug 683539326* @summary Tests that MidiFileReader correctly reads sequences with different division types27* @author Alex Menkov28*/2930import java.io.ByteArrayInputStream;31import java.io.ByteArrayOutputStream;32import java.io.IOException;33import java.io.InputStream;34import javax.sound.midi.InvalidMidiDataException;35import javax.sound.midi.MidiSystem;36import javax.sound.midi.Sequence;3738public class SMPTESequence {3940static int failed = 0;4142public static void main(String[] args) {43test(Sequence.PPQ);44test(Sequence.SMPTE_24);45test(Sequence.SMPTE_25);46test(Sequence.SMPTE_30);47test(Sequence.SMPTE_30DROP);4849if (failed > 0) {50throw new RuntimeException("" + failed + " tests failed");51}52}5354static boolean test(float divisionType) {55boolean result = false;56try {57log("Testing divisionType == " + divisionType);58Sequence sequence = new Sequence(divisionType, 16, 1);59float div1 = sequence.getDivisionType();6061ByteArrayOutputStream outStream = new ByteArrayOutputStream();62MidiSystem.write(sequence, 1, outStream);6364InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());6566sequence = MidiSystem.getSequence(inStream);67float div2 = sequence.getDivisionType();6869log("After write/read got divisionType == " + div2);70if (Math.abs(div2 - div1) < 0.001f) {71result = true;72}73} catch (InvalidMidiDataException ex) {74log(ex);75} catch (IOException ex) {76log(ex);77} catch (IllegalArgumentException ex) {78log(ex);79}80if (result) {81log("OK");82} else {83log("FAIL");84failed++;85}86return result;87}8889static void log(String s) {90System.out.println(s);91}9293static void log(Exception ex) {94log("got exception (" + ex.getClass().getSimpleName() + "): " + ex.getMessage());95}9697}9899100