author | mli |
Wed, 24 Oct 2018 17:52:06 +0800 | |
changeset 52234 | 5bd3a6017943 |
child 55680 | cd48f8f260c8 |
permissions | -rw-r--r-- |
52234
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
1 |
/* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
4 |
* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
8 |
* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
13 |
* accompanied this code). |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
14 |
* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
18 |
* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
21 |
* questions. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
22 |
*/ |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
23 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
24 |
/* |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
25 |
* @test |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
26 |
* @bug 8048123 8054214 8173423 |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
27 |
* @summary Test for jdk.calendar.japanese.supplemental.era support |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
28 |
* @library /test/lib |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
29 |
* @build SupplementalJapaneseEraTest |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
30 |
* @run testng/othervm SupplementalJapaneseEraTestRun |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
31 |
*/ |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
32 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
33 |
import java.util.Calendar; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
34 |
import java.util.List; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
35 |
import java.util.Locale; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
36 |
import java.util.TimeZone; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
37 |
import static java.util.Calendar.*; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
38 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
39 |
import jdk.test.lib.process.ProcessTools; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
40 |
import jdk.test.lib.JDKToolLauncher; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
41 |
import jdk.test.lib.Utils; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
42 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
43 |
import org.testng.annotations.DataProvider; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
44 |
import org.testng.annotations.Test; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
45 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
46 |
public class SupplementalJapaneseEraTestRun { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
47 |
@DataProvider(name = "validprop") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
48 |
Object[][] validPropertyData() { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
49 |
return new Object[][] { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
50 |
//Tests with valid property values |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
51 |
{"name=SupEra,abbr=S.E.,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
52 |
{"name = SupEra, abbr = S.E., since = "}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
53 |
}; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
54 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
55 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
56 |
@DataProvider(name = "invalidprop") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
57 |
Object[][] invalidPropertyData() { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
58 |
return new Object[][] { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
59 |
//Tests with invalid property values |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
60 |
{"=SupEra,abbr=S.E.,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
61 |
{"=,abbr=S.E.,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
62 |
{"name,abbr=S.E.,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
63 |
{"abbr=S.E.,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
64 |
{"name=SupEra,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
65 |
{"name=,abbr=S.E.,since"}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
66 |
{"name=SupEra,abbr=,since="}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
67 |
{"name=SupEra,abbr=S.E."}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
68 |
{"name=SupEra,abbr=S.E.,since=0"}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
69 |
//since=9223372036854775808 the number means Long.MAX_VALUE+1 |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
70 |
{"name=SupEra,abbr=S.E.,since=9223372036854775808"}, |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
71 |
}; |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
72 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
73 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
74 |
@Test(dataProvider = "validprop") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
75 |
public void ValidPropertyValuesTest(String prop) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
76 |
throws Throwable { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
77 |
//get the start time of the fictional next era |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
78 |
String startTime = getStartTime(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
79 |
testRun(prop + startTime, List.of("-t")); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
80 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
81 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
82 |
@Test(dataProvider = "invalidprop") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
83 |
public void InvalidPropertyValuesTest(String prop) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
84 |
throws Throwable { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
85 |
//get the start time of the fictional next era |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
86 |
String startTime = getStartTime(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
87 |
//get the name of the current era to be used to confirm that |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
88 |
//invalid property values are ignored. |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
89 |
String currentEra = getCurrentEra(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
90 |
testRun(prop + startTime, List.of("-b", currentEra)); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
91 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
92 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
93 |
private static void testRun(String property, List<String> javaParam) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
94 |
throws Throwable{ |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
95 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java"); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
96 |
launcher.addToolArg("-cp") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
97 |
.addToolArg(Utils.TEST_CLASS_PATH) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
98 |
.addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
99 |
.addToolArg("SupplementalJapaneseEraTest"); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
100 |
for (String para: javaParam) { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
101 |
launcher.addToolArg(para); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
102 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
103 |
int exitCode = ProcessTools.executeCommand(launcher.getCommand()) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
104 |
.getExitValue(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
105 |
System.out.println(property + ":pass"); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
106 |
if (exitCode != 0) { |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
107 |
System.out.println(property + ":fail"); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
108 |
throw new RuntimeException("Unexpected exit code: " + exitCode); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
109 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
110 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
111 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
112 |
private static String getStartTime(){ |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
113 |
Calendar cal = new Calendar.Builder().setCalendarType("japanese") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
114 |
.setTimeZone(TimeZone.getTimeZone("GMT")).setFields(ERA, 5) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
115 |
.setDate(200, FEBRUARY, 11).build(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
116 |
return String.valueOf(cal.getTimeInMillis()); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
117 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
118 |
|
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
119 |
private static String getCurrentEra(){ |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
120 |
Calendar jcal = new Calendar.Builder() |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
121 |
.setCalendarType("japanese") |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
122 |
.setFields(YEAR, 1, DAY_OF_YEAR, 1) |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
123 |
.build(); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
124 |
return jcal.getDisplayName(ERA, LONG, Locale.US); |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
125 |
} |
5bd3a6017943
8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests
mli
parents:
diff
changeset
|
126 |
} |