Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Calendar/SupplementalJapaneseEraTestRun.java
41149 views
1
/*
2
* Copyright (c) 2014, 2019, 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
24
/*
25
* @test
26
* @bug 8048123 8054214 8173423
27
* @summary Test for jdk.calendar.japanese.supplemental.era support
28
* @library /test/lib
29
* @build SupplementalJapaneseEraTest
30
* @run testng/othervm SupplementalJapaneseEraTestRun
31
*/
32
33
import java.util.Calendar;
34
import java.util.List;
35
import java.util.Locale;
36
import java.util.TimeZone;
37
import static java.util.Calendar.*;
38
39
import jdk.test.lib.process.ProcessTools;
40
import jdk.test.lib.JDKToolLauncher;
41
import jdk.test.lib.Utils;
42
43
import org.testng.annotations.DataProvider;
44
import org.testng.annotations.Test;
45
46
public class SupplementalJapaneseEraTestRun {
47
@DataProvider(name = "validprop")
48
Object[][] validPropertyData() {
49
return new Object[][] {
50
//Tests with valid property values
51
{"name=SupEra,abbr=S.E.,since="},
52
{"name = SupEra, abbr = S.E., since = "},
53
};
54
}
55
56
@DataProvider(name = "invalidprop")
57
Object[][] invalidPropertyData() {
58
return new Object[][] {
59
//Tests with invalid property values
60
{"=SupEra,abbr=S.E.,since="},
61
{"=,abbr=S.E.,since="},
62
{"name,abbr=S.E.,since="},
63
{"abbr=S.E.,since="},
64
{"name=SupEra,since="},
65
{"name=,abbr=S.E.,since"},
66
{"name=SupEra,abbr=,since="},
67
{"name=SupEra,abbr=S.E."},
68
{"name=SupEra,abbr=S.E.,since=0"},
69
//since=9223372036854775808 the number means Long.MAX_VALUE+1
70
{"name=SupEra,abbr=S.E.,since=9223372036854775808"},
71
};
72
}
73
74
@Test(dataProvider = "validprop")
75
public void ValidPropertyValuesTest(String prop)
76
throws Throwable {
77
//get the start time of the fictional next era
78
String startTime = getStartTime();
79
testRun(prop + startTime, List.of("-t"));
80
}
81
82
@Test(dataProvider = "invalidprop")
83
public void InvalidPropertyValuesTest(String prop)
84
throws Throwable {
85
//get the start time of the fictional next era
86
String startTime = getStartTime();
87
//get the name of the current era to be used to confirm that
88
//invalid property values are ignored.
89
String currentEra = getCurrentEra();
90
testRun(prop + startTime, List.of("-b", currentEra));
91
}
92
93
private static void testRun(String property, List<String> javaParam)
94
throws Throwable{
95
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
96
launcher.addToolArg("-ea")
97
.addToolArg("-esa")
98
.addToolArg("-cp")
99
.addToolArg(Utils.TEST_CLASS_PATH)
100
.addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property)
101
.addToolArg("SupplementalJapaneseEraTest");
102
for (String para: javaParam) {
103
launcher.addToolArg(para);
104
}
105
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
106
.getExitValue();
107
System.out.println(property + ":pass");
108
if (exitCode != 0) {
109
System.out.println(property + ":fail");
110
throw new RuntimeException("Unexpected exit code: " + exitCode);
111
}
112
}
113
114
private static String getStartTime(){
115
Calendar cal = new Calendar.Builder().setCalendarType("japanese")
116
.setTimeZone(TimeZone.getTimeZone("GMT")).setFields(ERA, 5)
117
.setDate(200, FEBRUARY, 11).build();
118
return String.valueOf(cal.getTimeInMillis());
119
}
120
121
private static String getCurrentEra(){
122
Calendar jcal = new Calendar.Builder()
123
.setCalendarType("japanese")
124
.setFields(YEAR, 1, DAY_OF_YEAR, 1)
125
.build();
126
return jcal.getDisplayName(ERA, LONG, Locale.US);
127
}
128
}
129
130