author | sspitsyn |
Wed, 03 May 2017 02:32:02 +0000 | |
changeset 46426 | 02a1fc064144 |
parent 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, 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 |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
33730
diff
changeset
|
27 |
* @modules java.base/jdk.internal.misc |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
28 |
* @library /test/lib |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
29 |
* @build sun.hotspot.WhiteBox |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
30 |
* @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
|
31 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
32 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest |
12262
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
35 |
import java.math.BigInteger; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
36 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
37 |
import sun.hotspot.parser.DiagnosticCommand; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
38 |
import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
39 |
import sun.hotspot.WhiteBox; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
40 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
41 |
public class ParserTest { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
42 |
WhiteBox wb; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
43 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
44 |
public ParserTest() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
45 |
wb = WhiteBox.getWhiteBox(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
46 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
47 |
testNanoTime(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
48 |
testJLong(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
49 |
testBool(); |
13200
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
50 |
testQuotes(); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
51 |
testMemorySize(); |
27879
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
52 |
testSingleLetterArg(); |
12262
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
55 |
public static void main(String... args) throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
56 |
new ParserTest(); |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
59 |
public void testNanoTime() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
60 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
61 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
62 |
"desc", DiagnosticArgumentType.NANOTIME, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
63 |
false, "0"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
64 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
65 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
66 |
BigInteger bi = new BigInteger("7"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
67 |
//These should work |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
68 |
parse(name, bi.toString(), name + "=7ns", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
69 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
70 |
bi = bi.multiply(BigInteger.valueOf(1000)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
71 |
parse(name, bi.toString(), name + "=7us", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
72 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
73 |
bi = bi.multiply(BigInteger.valueOf(1000)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
74 |
parse(name, bi.toString(), name + "=7ms", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
75 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
76 |
bi = bi.multiply(BigInteger.valueOf(1000)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
77 |
parse(name, bi.toString(), name + "=7s", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
78 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
79 |
bi = bi.multiply(BigInteger.valueOf(60)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
80 |
parse(name, bi.toString() , name + "=7m", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
81 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
82 |
bi = bi.multiply(BigInteger.valueOf(60)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
83 |
parse(name, bi.toString() , name + "=7h", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
84 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
85 |
bi = bi.multiply(BigInteger.valueOf(24)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
86 |
parse(name, bi.toString() , name + "=7d", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
87 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
88 |
parse(name, "0", name + "=0", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
89 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
90 |
shouldFail(name + "=7xs", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
91 |
shouldFail(name + "=7mms", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
92 |
shouldFail(name + "=7f", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
93 |
//Currently, only value 0 is allowed without unit |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
94 |
shouldFail(name + "=7", args); |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
97 |
public void testJLong() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
98 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
99 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
100 |
"desc", DiagnosticArgumentType.JLONG, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
101 |
false, "0"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
102 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
103 |
|
27879
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
104 |
wb.parseCommandLine(name + "=10", ',', args); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
105 |
parse(name, "10", name + "=10", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
106 |
parse(name, "-5", name + "=-5", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
107 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
108 |
//shouldFail(name + "=12m", args); <-- should fail, doesn't |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
111 |
public void testBool() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
112 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
113 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
114 |
"desc", DiagnosticArgumentType.BOOLEAN, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
115 |
false, "false"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
116 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
117 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
118 |
parse(name, "true", name + "=true", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
119 |
parse(name, "false", name + "=false", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
120 |
parse(name, "true", name, args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
121 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
122 |
//Empty commandline to parse, tests default value |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
123 |
//of the parameter "name" |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
124 |
parse(name, "false", "", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
125 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
126 |
|
13200
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
127 |
public void testQuotes() throws Exception { |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
128 |
String name = "name"; |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
129 |
DiagnosticCommand arg1 = new DiagnosticCommand(name, |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
130 |
"desc", DiagnosticArgumentType.STRING, |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
131 |
false, null); |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
132 |
DiagnosticCommand arg2 = new DiagnosticCommand("arg", |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
133 |
"desc", DiagnosticArgumentType.STRING, |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
134 |
false, null); |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
135 |
DiagnosticCommand[] args = {arg1, arg2}; |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
136 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
137 |
// try with a quoted value |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
138 |
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
|
139 |
// try with a quoted argument |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
140 |
parse(name, "myrec", "\"" + name + "\"" + "=myrec", args); |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
141 |
// 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
|
142 |
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
|
143 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
144 |
// 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
|
145 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
146 |
// try with a quoted value |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
147 |
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
|
148 |
// try with a quoted argument |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
149 |
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
|
150 |
// 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
|
151 |
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
|
152 |
} |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
153 |
|
27879
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
154 |
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
|
155 |
DiagnosticCommand[] args = new DiagnosticCommand[]{ |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
}; |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
} |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
162 |
|
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
163 |
public void testMemorySize() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
164 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
165 |
String defaultValue = "1024"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
166 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
167 |
"desc", DiagnosticArgumentType.MEMORYSIZE, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
168 |
false, defaultValue); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
169 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
170 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
171 |
BigInteger bi = new BigInteger("7"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
172 |
parse(name, bi.toString(), name + "=7b", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
173 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
174 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
175 |
parse(name, bi.toString(), name + "=7k", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
176 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
177 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
178 |
parse(name, bi.toString(), name + "=7m", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
179 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
180 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
181 |
parse(name, bi.toString(), name + "=7g", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
182 |
parse(name, defaultValue, "", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
183 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
184 |
//shouldFail(name + "=7gg", args); <---- should fail, doesn't |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
185 |
//shouldFail(name + "=7t", args); <----- should fail, doesn't |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
188 |
public void parse(String searchName, String expectedValue, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
189 |
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
|
190 |
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
|
191 |
} |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
192 |
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
|
193 |
String cmdLine, char delim, DiagnosticCommand[] argumentTypes) throws Exception { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
194 |
//parseCommandLine will return an object array that looks like |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
195 |
//{<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
|
196 |
Object[] res = wb.parseCommandLine(cmdLine, delim, argumentTypes); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
197 |
for (int i = 0; i < res.length-1; i+=2) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
198 |
String parsedName = (String) res[i]; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
199 |
if (searchName.equals(parsedName)) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
200 |
String parsedValue = (String) res[i+1]; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
201 |
if (expectedValue.equals(parsedValue)) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
202 |
return; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
203 |
} else { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
204 |
throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n" |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
205 |
+ searchName + " parsed as " + parsedValue |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
206 |
+ "! Expected: " + expectedValue); |
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 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
210 |
throw new Exception(searchName + " not found as a parsed Argument!"); |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
213 |
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
|
214 |
shouldFail(argument, ',', argumentTypes); |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
215 |
} |
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
216 |
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
|
217 |
try { |
27879
419385282044
8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents:
25958
diff
changeset
|
218 |
wb.parseCommandLine(argument, delim, argumentTypes); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
219 |
throw new Exception("Parser accepted argument: " + argument); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
220 |
} catch (IllegalArgumentException e) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
221 |
//expected |
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 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
224 |
} |