Path: blob/master/test/jdk/javax/sound/midi/Track/TrackAddSameTick.java
41155 views
/*1* Copyright (c) 2003, 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.MidiEvent;24import javax.sound.midi.Sequence;25import javax.sound.midi.ShortMessage;26import javax.sound.midi.Track;2728/**29* @test30* @bug 494194431* @summary Track may not have a determined order for inserting events at same32* tick time33*/34public class TrackAddSameTick {3536static boolean failed = false;37static MidiEvent[] evs = new MidiEvent[10];3839public static void main(String argv[]) throws Exception {40Sequence seq = new Sequence(Sequence.PPQ, 240);41Track t = seq.createTrack();4243log("add 10 events in random order");44t.add(createEvent(10, 5));45t.add(createEvent(0, 0));46t.add(createEvent(10, 6));47t.add(createEvent(11, 8));48t.add(createEvent(10, 7));49t.add(createEvent(0, 1));50t.add(createEvent(0, 2));51t.add(createEvent(15, 9));52t.add(createEvent(0, 3));53t.add(createEvent(1, 4));5455// now compare the events.56// The note param will tell us the57// the expected position58long lastTick = 0;59for (int i = 0; i < t.size(); i++) {60MidiEvent ev = t.get(i);61if (ev.getMessage() instanceof ShortMessage) {62ShortMessage msg = (ShortMessage) ev.getMessage();63log(""+i+": ShortMessage at tick "+ev.getTick()64+" with expected position "+msg.getData1());65if (ev.getTick() < lastTick) {66log(" FAILED: last tick is larger than this event's tick!");67failed = true;68}69if (i != msg.getData1()) {70log(" FAILED: Track did not order correctly.");71failed = true;72}73}74}7576if (failed) throw new Exception("Test FAILED!");77log("Test passed.");78}7980public static MidiEvent createEvent(long tick, int expectedPos)81throws Exception {82ShortMessage msg = new ShortMessage();83msg.setMessage(0x90, (int) expectedPos, 00);84MidiEvent ev = new MidiEvent(msg, tick);85return ev;86}8788public static void log(String s) {89System.out.println(s);90}9192public static void log(Exception e) {93//System.out.println(s);94e.printStackTrace();95}96}979899