Path: blob/master/test/jdk/javax/sound/midi/ShortMessage/FastShortMessage2.java
41152 views
/*1* Copyright (c) 2004, 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 501130636* @summary FastShortMessage.setMessage does not use the data2 parameter37*/38public class FastShortMessage2 {3940public static void main(String args[]) throws Exception {41int[] dataMes = {ShortMessage.NOTE_ON | 9, 0x24, 0x50};4243Sequence midiData = new Sequence(Sequence.PPQ, 240);44Track track = midiData.createTrack();45ShortMessage msg = new ShortMessage();46msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);47track.add(new MidiEvent(msg, 0));48// save sequence to outputstream49ByteArrayOutputStream baos = new ByteArrayOutputStream();50MidiSystem.write(midiData, 0, baos);51// reload that sequence52InputStream is = new ByteArrayInputStream(baos.toByteArray());53Sequence seq = MidiSystem.getSequence(is);54track = seq.getTracks()[0];55msg = (ShortMessage) (track.get(0).getMessage());56if (!msg.getClass().toString().contains("FastShortMessage")) {57System.out.println("msg is not FastShortMessage, this test is useless then..."+msg.getClass());58}5960msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);61byte[] msgData = msg.getMessage();6263if (msgData.length != dataMes.length64|| (msgData[0] & 0xFF) != dataMes[0]65|| (msgData[1] & 0xFF) != dataMes[1]66|| (msgData[2] & 0xFF) != dataMes[2]) {67System.out.println("status="+(msgData[0] & 0xFF)+" and expected "+dataMes[0]);68System.out.println("data1="+(msgData[1] & 0xFF)+" and expected "+dataMes[1]);69System.out.println("data2="+(msgData[2] & 0xFF)+" and expected "+dataMes[2]);70throw new Exception("Test FAILED!");71}72System.out.println("Test Passed.");73}74}757677