Path: blob/master/test/jdk/javax/sound/midi/ShortMessage/FastShortMessage.java
41152 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 java.io.ByteArrayInputStream;24import java.io.ByteArrayOutputStream;25import java.io.InputStream;2627import javax.sound.midi.MidiEvent;28import javax.sound.midi.MidiSystem;29import javax.sound.midi.Sequence;30import javax.sound.midi.ShortMessage;31import javax.sound.midi.Track;3233/**34* @test35* @bug 485101836* @summary MidiMessage.getLength and .getData return wrong values.37* also: 4890405: Reading MidiMessage byte array fails in 1.4.238*/39public class FastShortMessage {40public static void main(String args[]) throws Exception {41int[] dataMes = {ShortMessage.NOTE_ON | 9, 0x24, 0x50};42int res = 240;43Sequence midiData = new Sequence(Sequence.PPQ, res);4445Track track = midiData.createTrack();46ShortMessage msg = new ShortMessage();47msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);48track.add(new MidiEvent(msg, 0));4950// save sequence to outputstream51ByteArrayOutputStream baos = new ByteArrayOutputStream();52MidiSystem.write(midiData, 0, baos);5354// reload that sequence55InputStream is = new ByteArrayInputStream(baos.toByteArray());56Sequence seq = MidiSystem.getSequence(is);5758track = seq.getTracks()[0];59msg = (ShortMessage) (track.get(0).getMessage());60byte[] msgData = msg.getMessage();6162if (msgData.length != dataMes.length63|| (msgData[0] & 0xFF) != dataMes[0]64|| (msgData[1] & 0xFF) != dataMes[1]65|| (msgData[2] & 0xFF) != dataMes[2]) {66throw new Exception("test failed. read length="+msgData.length);67}68System.out.println("Test Passed.");69}70}717273