Path: blob/master/test/jdk/javax/sound/midi/Track/bug6416024.java
41155 views
/*1* Copyright (c) 2006, 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 javax.sound.midi.InvalidMidiDataException;24import javax.sound.midi.MetaMessage;25import javax.sound.midi.MidiEvent;26import javax.sound.midi.Sequence;27import javax.sound.midi.Track;2829/**30* @test31* @bug 641602432* @summary Tests that sequence correctly handle removing of EndOfTrack event33* @run main bug641602434*/35public class bug6416024 {3637boolean test() {38Sequence sequence = null;39Track track = null;40MidiEvent event = null;4142log("creating sequence...");43try {44sequence = new Sequence(Sequence.PPQ, 10);45log(" - OK: " + sequence);46} catch(InvalidMidiDataException e ) {47log(" - FAILED: got exception");48e.printStackTrace(System.out);49return false;50}5152log("creating track...");53track = sequence.createTrack();54log(" - OK: " + track);55log("initial track size=" + track.size());5657log("removing all track events...");58while (track.size() > 0) {59try {60event = track.get(0);61log(" ..removing event " + event);62track.remove(event);63log(" - OK, track size=" + track.size());64} catch (Exception e) {65log(" - FAILED: got exception");66e.printStackTrace(System.out);67return false;68}69}7071MetaMessage newMsg = new MetaMessage();72MidiEvent newEvent = new MidiEvent(newMsg, 10);73log("adding new event...");74try {75if (!track.add(newEvent)) {76log("event hasn't been added");77return false;78}79log(" - OK, track size=" + track.size());80} catch (Exception e) {81log(" - FAILED: got exception");82e.printStackTrace(System.out);83return false;84}8586return true;87}8889public static void main(String args[]) throws Exception {90bug6416024 This = new bug6416024();91if (This.test()) {92log("Test passed sucessfully.");93} else {94log("Test FAILED!");95delay(1000);96throw new RuntimeException("Test failed!");97}98}99100// helper routines101static long startTime = currentTimeMillis();102static long currentTimeMillis() {103//return System.nanoTime() / 1000000L;104return System.currentTimeMillis();105}106static void log(String s) {107long time = currentTimeMillis() - startTime;108long ms = time % 1000;109time /= 1000;110long sec = time % 60;111time /= 60;112long min = time % 60;113time /= 60;114System.out.println(""115+ (time < 10 ? "0" : "") + time116+ ":" + (min < 10 ? "0" : "") + min117+ ":" + (sec < 10 ? "0" : "") + sec118+ "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms119+ " (" + Thread.currentThread().getName() + ") " + s);120}121static void delay(int millis) {122try {123Thread.sleep(millis);124} catch (InterruptedException e) {}125}126}127128129