jdk/test/javax/sound/midi/ShortMessage/FastShortMessage2.java
changeset 41905 e8e5df013c6e
equal deleted inserted replaced
41904:524d908e49ea 41905:e8e5df013c6e
       
     1 /*
       
     2  * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.io.ByteArrayInputStream;
       
    25 import java.io.ByteArrayOutputStream;
       
    26 import java.io.InputStream;
       
    27 
       
    28 import javax.sound.midi.MidiEvent;
       
    29 import javax.sound.midi.MidiSystem;
       
    30 import javax.sound.midi.Sequence;
       
    31 import javax.sound.midi.ShortMessage;
       
    32 import javax.sound.midi.Track;
       
    33 
       
    34 /**
       
    35  * @test
       
    36  * @bug 5011306
       
    37  * @summary FastShortMessage.setMessage does not use the data2 parameter
       
    38  */
       
    39 public class FastShortMessage2 {
       
    40 
       
    41     public static void main(String args[]) throws Exception {
       
    42         int[] dataMes =  {ShortMessage.NOTE_ON | 9, 0x24, 0x50};
       
    43 
       
    44         Sequence midiData = new Sequence(Sequence.PPQ, 240);
       
    45         Track track = midiData.createTrack();
       
    46         ShortMessage msg = new ShortMessage();
       
    47         msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);
       
    48         track.add(new MidiEvent(msg, 0));
       
    49         // save sequence to outputstream
       
    50         ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    51         MidiSystem.write(midiData, 0, baos);
       
    52         // reload that sequence
       
    53         InputStream is = new ByteArrayInputStream(baos.toByteArray());
       
    54         Sequence seq = MidiSystem.getSequence(is);
       
    55         track = seq.getTracks()[0];
       
    56         msg = (ShortMessage) (track.get(0).getMessage());
       
    57         if (!msg.getClass().toString().contains("FastShortMessage")) {
       
    58             System.out.println("msg is not FastShortMessage, this test is useless then..."+msg.getClass());
       
    59         }
       
    60 
       
    61         msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);
       
    62         byte[] msgData = msg.getMessage();
       
    63 
       
    64         if (msgData.length != dataMes.length
       
    65          || (msgData[0] & 0xFF) != dataMes[0]
       
    66          || (msgData[1] & 0xFF) != dataMes[1]
       
    67          || (msgData[2] & 0xFF) != dataMes[2]) {
       
    68             System.out.println("status="+(msgData[0] & 0xFF)+" and expected "+dataMes[0]);
       
    69             System.out.println("data1="+(msgData[1] & 0xFF)+" and expected "+dataMes[1]);
       
    70             System.out.println("data2="+(msgData[2] & 0xFF)+" and expected "+dataMes[2]);
       
    71             throw new Exception("Test FAILED!");
       
    72         }
       
    73         System.out.println("Test Passed.");
       
    74     }
       
    75 }