|
1 /* |
|
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 import java.io.File; |
|
24 import java.io.IOException; |
|
25 |
|
26 /* |
|
27 * @test |
|
28 * @bug 6994753 |
|
29 * @summary tests -XshowSettings options |
|
30 * @compile -XDignore.symbol.file Settings.java TestHelper.java |
|
31 * @run main Settings |
|
32 * @author ksrini |
|
33 */ |
|
34 public class Settings { |
|
35 private static File testJar = null; |
|
36 |
|
37 static void init() throws IOException { |
|
38 if (testJar != null) { |
|
39 return; |
|
40 } |
|
41 testJar = new File("test.jar"); |
|
42 StringBuilder tsrc = new StringBuilder(); |
|
43 tsrc.append("public static void main(String... args) {\n"); |
|
44 tsrc.append(" for (String x : args) {\n"); |
|
45 tsrc.append(" System.out.println(x);\n"); |
|
46 tsrc.append(" }\n"); |
|
47 tsrc.append("}\n"); |
|
48 TestHelper.createJar(testJar, tsrc.toString()); |
|
49 } |
|
50 |
|
51 static void checkContains(TestHelper.TestResult tr, String str) { |
|
52 if (!tr.contains(str)) { |
|
53 System.out.println(tr); |
|
54 throw new RuntimeException(str + " not found"); |
|
55 } |
|
56 } |
|
57 |
|
58 static void checkNoContains(TestHelper.TestResult tr, String str) { |
|
59 if (tr.contains(str)) { |
|
60 System.out.println(tr.status); |
|
61 throw new RuntimeException(str + " found"); |
|
62 } |
|
63 } |
|
64 |
|
65 private static final String VM_SETTINGS = "VM settings:"; |
|
66 private static final String PROP_SETTINGS = "Property settings:"; |
|
67 private static final String LOCALE_SETTINGS = "Locale settings:"; |
|
68 |
|
69 static void containsAllOptions(TestHelper.TestResult tr) { |
|
70 checkContains(tr, VM_SETTINGS); |
|
71 checkContains(tr, PROP_SETTINGS); |
|
72 checkContains(tr, LOCALE_SETTINGS); |
|
73 } |
|
74 |
|
75 static void runTestOptionDefault() throws IOException { |
|
76 TestHelper.TestResult tr = null; |
|
77 tr = TestHelper.doExec(TestHelper.javaCmd, "-Xmx512m", "-Xss128k", |
|
78 "-XshowSettings", "-jar", testJar.getAbsolutePath()); |
|
79 containsAllOptions(tr); |
|
80 if (!tr.isOK()) { |
|
81 System.out.println(tr.status); |
|
82 throw new RuntimeException("test fails"); |
|
83 } |
|
84 } |
|
85 |
|
86 static void runTestOptionAll() throws IOException { |
|
87 init(); |
|
88 TestHelper.TestResult tr = null; |
|
89 tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:all"); |
|
90 containsAllOptions(tr); |
|
91 } |
|
92 |
|
93 static void runTestOptionVM() throws IOException { |
|
94 TestHelper.TestResult tr = null; |
|
95 tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:vm"); |
|
96 checkContains(tr, VM_SETTINGS); |
|
97 checkNoContains(tr, PROP_SETTINGS); |
|
98 checkNoContains(tr, LOCALE_SETTINGS); |
|
99 } |
|
100 |
|
101 static void runTestOptionProperty() throws IOException { |
|
102 TestHelper.TestResult tr = null; |
|
103 tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:properties"); |
|
104 checkNoContains(tr, VM_SETTINGS); |
|
105 checkContains(tr, PROP_SETTINGS); |
|
106 checkNoContains(tr, LOCALE_SETTINGS); |
|
107 } |
|
108 |
|
109 static void runTestOptionLocale() throws IOException { |
|
110 TestHelper.TestResult tr = null; |
|
111 tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettings:locale"); |
|
112 checkNoContains(tr, VM_SETTINGS); |
|
113 checkNoContains(tr, PROP_SETTINGS); |
|
114 checkContains(tr, LOCALE_SETTINGS); |
|
115 } |
|
116 |
|
117 static void runTestBadOptions() throws IOException { |
|
118 TestHelper.TestResult tr = null; |
|
119 tr = TestHelper.doExec(TestHelper.javaCmd, "-XshowSettingsBadOption"); |
|
120 checkNoContains(tr, VM_SETTINGS); |
|
121 checkNoContains(tr, PROP_SETTINGS); |
|
122 checkNoContains(tr, LOCALE_SETTINGS); |
|
123 checkContains(tr, "Unrecognized option: -XshowSettingsBadOption"); |
|
124 } |
|
125 public static void main(String... args) { |
|
126 try { |
|
127 runTestOptionAll(); |
|
128 runTestOptionDefault(); |
|
129 runTestOptionVM(); |
|
130 runTestOptionProperty(); |
|
131 runTestOptionLocale(); |
|
132 runTestBadOptions(); |
|
133 } catch (IOException ioe) { |
|
134 throw new RuntimeException(ioe); |
|
135 } |
|
136 } |
|
137 } |