Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/MetaMessage/MetaMessageClone.java
32243 views
/*1* Copyright (c) 2002, 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 javax.sound.midi.MetaMessage;2425/**26* @test27* @bug 451179628* @summary Check that MetaMessage.clone() works correctly29*/30public class MetaMessageClone {3132private static void printMsg(MetaMessage msg, byte[] data) {33System.out.println(""+msg.getLength()+" total bytes, type="+msg.getType()+", dataLength="+data.length);34}3536private static void checkClone(MetaMessage msg) throws Exception {37System.out.print("Original: ");38byte[] msgData=msg.getData();39printMsg(msg, msgData);40MetaMessage msg2=(MetaMessage) msg.clone();41byte[] msg2Data=msg2.getData();42System.out.print("Clone: ");43printMsg(msg2, msg2Data);4445if (msg2.getLength()!=msg.getLength()46|| msg.getType()!=msg2.getType()47|| msgData.length!=msg2Data.length) {48throw new Exception("cloned MetaMessage is not equal.");49}50int max=Math.min(msgData.length, 10);51for (int i=0; i<max; i++) {52if (msgData[i]!=msg2Data[i]) {53throw new Exception("Cloned MetaMessage data is not equal.");54}55}56}5758public static void main(String[] args) throws Exception {59// let's create some MetaMessages and check them60MetaMessage msg=new MetaMessage();61String text="a textmarker";62msg.setMessage(1, text.getBytes(), text.length());63checkClone(msg);64msg.setMessage(0x2E, new byte[0], 0);65checkClone(msg);66byte[] data=new byte[17000];67for (int i=0; i<30; data[i]=(byte) (i++ & 0xFF));68msg.setMessage(0x02, data, 80); checkClone(msg);69msg.setMessage(0x02, data, 160); checkClone(msg);70msg.setMessage(0x02, data, 400); checkClone(msg);71msg.setMessage(0x02, data, 1000); checkClone(msg);72msg.setMessage(0x02, data, 10000); checkClone(msg);73msg.setMessage(0x02, data, 17000); checkClone(msg);74}75}767778