Path: blob/master/test/jdk/javax/sound/midi/SysexMessage/Basic.java
41153 views
/*1* Copyright (c) 2019, 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.util.Arrays;2425import javax.sound.midi.SysexMessage;2627import static javax.sound.midi.SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE;28import static javax.sound.midi.SysexMessage.SYSTEM_EXCLUSIVE;2930/**31* @test32* @bug 822144533* @summary Checks basic functionality of javax.sound.midi.SysexMessage class34*/35public class Basic {3637public static void main(final String[] args) throws Exception {38byte[] dataExclusive = {(byte) (SYSTEM_EXCLUSIVE)};39byte[] dataSpecialExclusive = {(byte) (SPECIAL_SYSTEM_EXCLUSIVE)};40byte[] empty = {};4142////////////////////////////43// Constructors44////////////////////////////45SysexMessage msg = new SysexMessage(dataExclusive, 1);46test(msg, SYSTEM_EXCLUSIVE, empty, 1);47msg = new SysexMessage(dataSpecialExclusive, 1);48test(msg, SPECIAL_SYSTEM_EXCLUSIVE, empty, 1);49msg = new SysexMessage(SYSTEM_EXCLUSIVE, empty, 0);50test(msg, SYSTEM_EXCLUSIVE, empty, 1);51msg = new SysexMessage(SPECIAL_SYSTEM_EXCLUSIVE, empty, 0);52test(msg, SPECIAL_SYSTEM_EXCLUSIVE, empty, 1);53msg = new SysexMessage(SYSTEM_EXCLUSIVE, dataSpecialExclusive, 1);54test(msg, SYSTEM_EXCLUSIVE, dataSpecialExclusive, 2);55msg = new SysexMessage(SPECIAL_SYSTEM_EXCLUSIVE, dataExclusive, 1);56test(msg, SPECIAL_SYSTEM_EXCLUSIVE, dataExclusive, 2);5758////////////////////////////59// SysexMessage.setMessage()60////////////////////////////61msg = new SysexMessage();62msg.setMessage(dataExclusive, 1);63test(msg, SYSTEM_EXCLUSIVE, empty, 1);64msg = new SysexMessage();65msg.setMessage(dataSpecialExclusive, 1);66test(msg, SPECIAL_SYSTEM_EXCLUSIVE, empty, 1);67msg = new SysexMessage();68msg.setMessage(SYSTEM_EXCLUSIVE, empty, 0);69test(msg, SYSTEM_EXCLUSIVE, empty, 1);70msg = new SysexMessage();71msg.setMessage(SPECIAL_SYSTEM_EXCLUSIVE, empty, 0);72test(msg, SPECIAL_SYSTEM_EXCLUSIVE, empty, 1);73msg = new SysexMessage();74msg.setMessage(SYSTEM_EXCLUSIVE, dataSpecialExclusive, 1);75test(msg, SYSTEM_EXCLUSIVE, dataSpecialExclusive, 2);76msg = new SysexMessage();77msg.setMessage(SPECIAL_SYSTEM_EXCLUSIVE, dataExclusive, 1);78test(msg, SPECIAL_SYSTEM_EXCLUSIVE, dataExclusive, 2);79}8081static void test(SysexMessage msg, int status, byte[] data, int length) {82if (msg.getStatus() != status) {83System.err.println("Expected status: " + status);84System.err.println("Actual status: " + msg.getStatus());85throw new RuntimeException();86}87if (msg.getLength() != length) {88System.err.println("Expected length: " + length);89System.err.println("Actual length: " + msg.getLength());90throw new RuntimeException();91}92if (!Arrays.equals(msg.getData(), data)) {93System.err.println("Expected data: " + Arrays.toString(data));94System.err.println("Actual data: " + Arrays.toString(msg.getData()));95throw new RuntimeException();96}97}98}99100101