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