author | igerasim |
Tue, 15 Oct 2013 21:15:17 +0400 | |
changeset 20860 | c32c6a829cf0 |
parent 16697 | 1863b690d34f |
child 24835 | be963975e2f7 |
permissions | -rw-r--r-- |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
1 |
/* |
16697 | 2 |
* Copyright (c) 2012, 2013, 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 |
/* |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
25 |
* @test ParserTest |
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 |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
27 |
* @library /testlibrary /testlibrary/whitebox |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
28 |
* @build ParserTest |
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 |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
13200
diff
changeset
|
30 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
31 |
*/ |
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 |
import java.math.BigInteger; |
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 sun.hotspot.parser.DiagnosticCommand; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
36 |
import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
37 |
import sun.hotspot.WhiteBox; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
38 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
39 |
public class ParserTest { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
40 |
WhiteBox wb; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
41 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
42 |
public ParserTest() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
43 |
wb = WhiteBox.getWhiteBox(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
44 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
45 |
testNanoTime(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
46 |
testJLong(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
47 |
testBool(); |
13200
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
48 |
testQuotes(); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
49 |
testMemorySize(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
50 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
51 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
52 |
public static void main(String... args) throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
53 |
new ParserTest(); |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
56 |
public void testNanoTime() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
57 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
58 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
59 |
"desc", DiagnosticArgumentType.NANOTIME, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
60 |
false, "0"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
61 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
62 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
63 |
BigInteger bi = new BigInteger("7"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
64 |
//These should work |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
65 |
parse(name, bi.toString(), name + "=7ns", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
66 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
67 |
bi = bi.multiply(BigInteger.valueOf(1000)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
68 |
parse(name, bi.toString(), name + "=7us", 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 + "=7ms", 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 + "=7s", 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(60)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
77 |
parse(name, bi.toString() , name + "=7m", 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 + "=7h", 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(24)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
83 |
parse(name, bi.toString() , name + "=7d", 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 |
parse(name, "0", name + "=0", 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 |
shouldFail(name + "=7xs", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
88 |
shouldFail(name + "=7mms", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
89 |
shouldFail(name + "=7f", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
90 |
//Currently, only value 0 is allowed without unit |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
91 |
shouldFail(name + "=7", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
92 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
93 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
94 |
public void testJLong() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
95 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
96 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
97 |
"desc", DiagnosticArgumentType.JLONG, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
98 |
false, "0"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
99 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
100 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
101 |
wb.parseCommandLine(name + "=10", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
102 |
parse(name, "10", name + "=10", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
103 |
parse(name, "-5", name + "=-5", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
104 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
105 |
//shouldFail(name + "=12m", args); <-- should fail, doesn't |
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 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
108 |
public void testBool() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
109 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
110 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
111 |
"desc", DiagnosticArgumentType.BOOLEAN, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
112 |
false, "false"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
113 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
114 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
115 |
parse(name, "true", name + "=true", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
116 |
parse(name, "false", name + "=false", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
117 |
parse(name, "true", name, args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
118 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
119 |
//Empty commandline to parse, tests default value |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
120 |
//of the parameter "name" |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
121 |
parse(name, "false", "", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
122 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
123 |
|
13200
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
124 |
public void testQuotes() throws Exception { |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
125 |
String name = "name"; |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
126 |
DiagnosticCommand arg1 = new DiagnosticCommand(name, |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
127 |
"desc", DiagnosticArgumentType.STRING, |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
128 |
false, null); |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
129 |
DiagnosticCommand arg2 = new DiagnosticCommand("arg", |
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[] args = {arg1, arg2}; |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
133 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
134 |
// try with a quoted value |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
135 |
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
|
136 |
// try with a quoted argument |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
137 |
parse(name, "myrec", "\"" + name + "\"" + "=myrec", args); |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
138 |
// 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
|
139 |
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
|
140 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
141 |
// 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
|
142 |
|
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
143 |
// try with a quoted value |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
144 |
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
|
145 |
// try with a quoted argument |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
146 |
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
|
147 |
// 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
|
148 |
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
|
149 |
} |
7b506e7b406e
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
12262
diff
changeset
|
150 |
|
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
151 |
public void testMemorySize() throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
152 |
String name = "name"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
153 |
String defaultValue = "1024"; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
154 |
DiagnosticCommand arg = new DiagnosticCommand(name, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
155 |
"desc", DiagnosticArgumentType.MEMORYSIZE, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
156 |
false, defaultValue); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
157 |
DiagnosticCommand[] args = {arg}; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
158 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
159 |
BigInteger bi = new BigInteger("7"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
160 |
parse(name, bi.toString(), name + "=7b", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
161 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
162 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
163 |
parse(name, bi.toString(), name + "=7k", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
164 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
165 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
166 |
parse(name, bi.toString(), name + "=7m", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
167 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
168 |
bi = bi.multiply(BigInteger.valueOf(1024)); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
169 |
parse(name, bi.toString(), name + "=7g", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
170 |
parse(name, defaultValue, "", args); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
171 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
172 |
//shouldFail(name + "=7gg", args); <---- should fail, doesn't |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
173 |
//shouldFail(name + "=7t", args); <----- should fail, doesn't |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
174 |
} |
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 |
public void parse(String searchName, String expectedValue, |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
177 |
String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
178 |
//parseCommandLine will return an object array that looks like |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
179 |
//{<name of parsed object>, <of parsed object> ... } |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
180 |
Object[] res = wb.parseCommandLine(cmdLine, argumentTypes); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
181 |
for (int i = 0; i < res.length-1; i+=2) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
182 |
String parsedName = (String) res[i]; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
183 |
if (searchName.equals(parsedName)) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
184 |
String parsedValue = (String) res[i+1]; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
185 |
if (expectedValue.equals(parsedValue)) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
186 |
return; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
187 |
} else { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
188 |
throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n" |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
189 |
+ searchName + " parsed as " + parsedValue |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
190 |
+ "! Expected: " + expectedValue); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
191 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
192 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
193 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
194 |
throw new Exception(searchName + " not found as a parsed Argument!"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
195 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
196 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
197 |
private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
198 |
try { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
199 |
wb.parseCommandLine(argument, argumentTypes); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
200 |
throw new Exception("Parser accepted argument: " + argument); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
201 |
} catch (IllegalArgumentException e) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
202 |
//expected |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
203 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
204 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff
changeset
|
205 |
} |