jdk/test/javax/sound/midi/Sequence/SMPTEDuration.java
author serb
Mon, 31 Oct 2016 14:50:09 +0300
changeset 41905 e8e5df013c6e
permissions -rw-r--r--
8167615: Opensource unit/regression tests for JavaSound Reviewed-by: amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41905
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     1
/*
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     2
 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     4
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     8
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    13
 * accompanied this code).
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    14
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    18
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    21
 * questions.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    22
 */
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    23
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    24
import javax.sound.midi.InvalidMidiDataException;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    25
import javax.sound.midi.MidiEvent;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    26
import javax.sound.midi.Sequence;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    27
import javax.sound.midi.ShortMessage;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    28
import javax.sound.midi.Track;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    29
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    30
/**
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    31
 * @test
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    32
 * @bug 4702328
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    33
 * @summary Wrong time in sequence for SMPTE based types
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    34
 */
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    35
public class SMPTEDuration {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    36
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    37
    public static void main(String args[]) throws Exception {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    38
         int[][] dataMes =  { {ShortMessage.NOTE_ON, 10, 0x24, 0x50} ,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    39
                 { ShortMessage.NOTE_OFF, 10, 0x24, 0x44 },
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    40
                 { ShortMessage.NOTE_ON, 10, 0x24, 0x50 },
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    41
                 { ShortMessage.NOTE_ON, 10, 0x26, 0x50 },
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    42
                 { ShortMessage.NOTE_OFF, 10, 0x26, 0x53 } };
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    43
         long[] ticks = { 0, 68, 240, 240, 286};
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    44
         int res = 240;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    45
         ShortMessage msg;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    46
         Sequence midiData = null;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    47
         Track track;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    48
         boolean failed = false;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    49
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    50
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    51
         try {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    52
             midiData = new Sequence(Sequence.SMPTE_24 , res);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    53
         } catch (InvalidMidiDataException invMidiEx) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    54
             invMidiEx.printStackTrace(System.out);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    55
             System.out.println("Unexpected InvalidMidiDataException: "
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    56
                     + invMidiEx.getMessage());
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    57
             failed = true;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    58
         }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    59
         track = midiData.createTrack();
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    60
         for (int i = 0; i < dataMes.length; i++) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    61
             msg = new ShortMessage();
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    62
             try {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    63
                 msg.setMessage(dataMes[i][0], dataMes[i][1], dataMes[i][2],
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    64
                         dataMes[i][3]);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    65
             } catch (InvalidMidiDataException invMidiEx) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    66
                 invMidiEx.printStackTrace(System.out);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    67
                 System.out.println("Unexpected InvalidMidiDataException: "
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    68
                         + invMidiEx.getMessage());
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    69
                 failed = true;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    70
             }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    71
             track.add(new MidiEvent(msg, ticks[i]));
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    72
         }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    73
         //   lengthInMs = (tickLength*1000000)/(divType*Res)
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    74
         long micros = (long) ((midiData.getTickLength() * 1000000) / (res * Sequence.SMPTE_24));
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    75
         if (midiData.getMicrosecondLength() != micros) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    76
             failed = true;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    77
             System.out.println("getMicrosecondLength() returns wrong length: "
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    78
                     + midiData.getMicrosecondLength());
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    79
             System.out.println("getMicrosecondLength() must return length: "
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    80
                     + micros);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    81
         }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    82
         if (midiData.getTickLength() != 286) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    83
             failed = true;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    84
             System.out.println("getTickLength() returns wrong length: "
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    85
                     + midiData.getTickLength());
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    86
         }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    87
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    88
         if( failed == true ) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    89
             throw new Exception("test failed");
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    90
         } else {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    91
             System.out.println("Passed.");
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    92
         }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    93
    }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    94
}