41905
|
1 |
/*
|
|
2 |
* Copyright (c) 2002, 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 javax.sound.midi.MetaMessage;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* @test
|
|
28 |
* @bug 4511796
|
|
29 |
* @summary Check that MetaMessage.clone() works correctly
|
|
30 |
*/
|
|
31 |
public class MetaMessageClone {
|
|
32 |
|
|
33 |
private static void printMsg(MetaMessage msg, byte[] data) {
|
|
34 |
System.out.println(""+msg.getLength()+" total bytes, type="+msg.getType()+", dataLength="+data.length);
|
|
35 |
}
|
|
36 |
|
|
37 |
private static void checkClone(MetaMessage msg) throws Exception {
|
|
38 |
System.out.print("Original: ");
|
|
39 |
byte[] msgData=msg.getData();
|
|
40 |
printMsg(msg, msgData);
|
|
41 |
MetaMessage msg2=(MetaMessage) msg.clone();
|
|
42 |
byte[] msg2Data=msg2.getData();
|
|
43 |
System.out.print("Clone: ");
|
|
44 |
printMsg(msg2, msg2Data);
|
|
45 |
|
|
46 |
if (msg2.getLength()!=msg.getLength()
|
|
47 |
|| msg.getType()!=msg2.getType()
|
|
48 |
|| msgData.length!=msg2Data.length) {
|
|
49 |
throw new Exception("cloned MetaMessage is not equal.");
|
|
50 |
}
|
|
51 |
int max=Math.min(msgData.length, 10);
|
|
52 |
for (int i=0; i<max; i++) {
|
|
53 |
if (msgData[i]!=msg2Data[i]) {
|
|
54 |
throw new Exception("Cloned MetaMessage data is not equal.");
|
|
55 |
}
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
public static void main(String[] args) throws Exception {
|
|
60 |
// let's create some MetaMessages and check them
|
|
61 |
MetaMessage msg=new MetaMessage();
|
|
62 |
String text="a textmarker";
|
|
63 |
msg.setMessage(1, text.getBytes(), text.length());
|
|
64 |
checkClone(msg);
|
|
65 |
msg.setMessage(0x2E, new byte[0], 0);
|
|
66 |
checkClone(msg);
|
|
67 |
byte[] data=new byte[17000];
|
|
68 |
for (int i=0; i<30; data[i]=(byte) (i++ & 0xFF));
|
|
69 |
msg.setMessage(0x02, data, 80); checkClone(msg);
|
|
70 |
msg.setMessage(0x02, data, 160); checkClone(msg);
|
|
71 |
msg.setMessage(0x02, data, 400); checkClone(msg);
|
|
72 |
msg.setMessage(0x02, data, 1000); checkClone(msg);
|
|
73 |
msg.setMessage(0x02, data, 10000); checkClone(msg);
|
|
74 |
msg.setMessage(0x02, data, 17000); checkClone(msg);
|
|
75 |
}
|
|
76 |
}
|