annotate test/serviceability/ParserTest.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents 09f19d3de485
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8098
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
1 /*
10092
b0301c02f38e 8012048: JDK8 b85 source with GPL header errors
katleman
parents: 8098
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
8098
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
4 *
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
7 * published by the Free Software Foundation.
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
8 *
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
13 * accompanied this code).
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
14 *
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
15 * You should have received a copy of the GNU General Public License version
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
18 *
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
21 * questions.
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
22 */
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
23
5978
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
24 /*
17974
09f19d3de485 8043915: Tests get ClassNotFoundException: com.oracle.java.testlibrary.StreamPumper
ykantser
parents: 10092
diff changeset
25 * @test
8098
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
26 * @summary Test that the diagnostic command arguemnt parser works
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
27 * @library /testlibrary /testlibrary/whitebox
17974
09f19d3de485 8043915: Tests get ClassNotFoundException: com.oracle.java.testlibrary.StreamPumper
ykantser
parents: 10092
diff changeset
28 * @build ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.parser.*
8098
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
29 * @run main ClassFileInstaller sun.hotspot.WhiteBox
1b0dc9f87e75 8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents: 6202
diff changeset
30 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest
5978
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
31 */
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
32
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
33 import java.math.BigInteger;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
34
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
35 import sun.hotspot.parser.DiagnosticCommand;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
36 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
37 import sun.hotspot.WhiteBox;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
38
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
39 public class ParserTest {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
40 WhiteBox wb;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
41
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
42 public ParserTest() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
43 wb = WhiteBox.getWhiteBox();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
44
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
45 testNanoTime();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
46 testJLong();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
47 testBool();
6202
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
48 testQuotes();
5978
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
49 testMemorySize();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
50 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
51
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
52 public static void main(String... args) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
53 new ParserTest();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
54 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
55
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
56 public void testNanoTime() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
57 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
58 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
59 "desc", DiagnosticArgumentType.NANOTIME,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
60 false, "0");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
61 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
62
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
63 BigInteger bi = new BigInteger("7");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
64 //These should work
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
65 parse(name, bi.toString(), name + "=7ns", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
66
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
67 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
68 parse(name, bi.toString(), name + "=7us", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
69
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
70 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
71 parse(name, bi.toString(), name + "=7ms", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
72
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
73 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
74 parse(name, bi.toString(), name + "=7s", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
75
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
76 bi = bi.multiply(BigInteger.valueOf(60));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
77 parse(name, bi.toString() , name + "=7m", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
78
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
79 bi = bi.multiply(BigInteger.valueOf(60));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
80 parse(name, bi.toString() , name + "=7h", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
81
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
82 bi = bi.multiply(BigInteger.valueOf(24));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
83 parse(name, bi.toString() , name + "=7d", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
84
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
85 parse(name, "0", name + "=0", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
86
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
87 shouldFail(name + "=7xs", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
88 shouldFail(name + "=7mms", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
89 shouldFail(name + "=7f", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
90 //Currently, only value 0 is allowed without unit
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
91 shouldFail(name + "=7", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
92 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
93
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
94 public void testJLong() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
95 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
96 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
97 "desc", DiagnosticArgumentType.JLONG,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
98 false, "0");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
99 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
100
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
101 wb.parseCommandLine(name + "=10", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
102 parse(name, "10", name + "=10", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
103 parse(name, "-5", name + "=-5", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
104
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
105 //shouldFail(name + "=12m", args); <-- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
106 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
107
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
108 public void testBool() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
109 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
110 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
111 "desc", DiagnosticArgumentType.BOOLEAN,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
112 false, "false");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
113 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
114
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
115 parse(name, "true", name + "=true", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
116 parse(name, "false", name + "=false", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
117 parse(name, "true", name, args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
118
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
119 //Empty commandline to parse, tests default value
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
120 //of the parameter "name"
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
121 parse(name, "false", "", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
122 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
123
6202
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
124 public void testQuotes() throws Exception {
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
125 String name = "name";
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
126 DiagnosticCommand arg1 = new DiagnosticCommand(name,
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
127 "desc", DiagnosticArgumentType.STRING,
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
128 false, null);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
129 DiagnosticCommand arg2 = new DiagnosticCommand("arg",
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
130 "desc", DiagnosticArgumentType.STRING,
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
131 false, null);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
132 DiagnosticCommand[] args = {arg1, arg2};
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
133
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
134 // try with a quoted value
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
135 parse(name, "Recording 1", name + "=\"Recording 1\"", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
136 // try with a quoted argument
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
137 parse(name, "myrec", "\"" + name + "\"" + "=myrec", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
138 // try with both a quoted value and a quoted argument
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
139 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\"", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
140
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
141 // now the same thing but with other arguments after
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
142
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
143 // try with a quoted value
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
144 parse(name, "Recording 1", name + "=\"Recording 1\",arg=value", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
145 // try with a quoted argument
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
146 parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
147 // try with both a quoted value and a quoted argument
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
148 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args);
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
149 }
5a1f452f8f90 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 5978
diff changeset
150
5978
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
151 public void testMemorySize() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
152 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
153 String defaultValue = "1024";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
154 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
155 "desc", DiagnosticArgumentType.MEMORYSIZE,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
156 false, defaultValue);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
157 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
158
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
159 BigInteger bi = new BigInteger("7");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
160 parse(name, bi.toString(), name + "=7b", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
161
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
162 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
163 parse(name, bi.toString(), name + "=7k", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
164
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
165 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
166 parse(name, bi.toString(), name + "=7m", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
167
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
168 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
169 parse(name, bi.toString(), name + "=7g", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
170 parse(name, defaultValue, "", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
171
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
172 //shouldFail(name + "=7gg", args); <---- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
173 //shouldFail(name + "=7t", args); <----- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
174 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
175
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
176 public void parse(String searchName, String expectedValue,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
177 String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
178 //parseCommandLine will return an object array that looks like
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
179 //{<name of parsed object>, <of parsed object> ... }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
180 Object[] res = wb.parseCommandLine(cmdLine, argumentTypes);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
181 for (int i = 0; i < res.length-1; i+=2) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
182 String parsedName = (String) res[i];
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
183 if (searchName.equals(parsedName)) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
184 String parsedValue = (String) res[i+1];
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
185 if (expectedValue.equals(parsedValue)) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
186 return;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
187 } else {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
188 throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n"
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
189 + searchName + " parsed as " + parsedValue
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
190 + "! Expected: " + expectedValue);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
191 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
192 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
193 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
194 throw new Exception(searchName + " not found as a parsed Argument!");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
195 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
196
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
197 private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
198 try {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
199 wb.parseCommandLine(argument, argumentTypes);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
200 throw new Exception("Parser accepted argument: " + argument);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
201 } catch (IllegalArgumentException e) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
202 //expected
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
203 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
204 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
205 }