|
1 /* |
|
2 * Copyright (c) 2014, 2018, 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("-cp") |
|
97 .addToolArg(Utils.TEST_CLASS_PATH) |
|
98 .addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property) |
|
99 .addToolArg("SupplementalJapaneseEraTest"); |
|
100 for (String para: javaParam) { |
|
101 launcher.addToolArg(para); |
|
102 } |
|
103 int exitCode = ProcessTools.executeCommand(launcher.getCommand()) |
|
104 .getExitValue(); |
|
105 System.out.println(property + ":pass"); |
|
106 if (exitCode != 0) { |
|
107 System.out.println(property + ":fail"); |
|
108 throw new RuntimeException("Unexpected exit code: " + exitCode); |
|
109 } |
|
110 } |
|
111 |
|
112 private static String getStartTime(){ |
|
113 Calendar cal = new Calendar.Builder().setCalendarType("japanese") |
|
114 .setTimeZone(TimeZone.getTimeZone("GMT")).setFields(ERA, 5) |
|
115 .setDate(200, FEBRUARY, 11).build(); |
|
116 return String.valueOf(cal.getTimeInMillis()); |
|
117 } |
|
118 |
|
119 private static String getCurrentEra(){ |
|
120 Calendar jcal = new Calendar.Builder() |
|
121 .setCalendarType("japanese") |
|
122 .setFields(YEAR, 1, DAY_OF_YEAR, 1) |
|
123 .build(); |
|
124 return jcal.getDisplayName(ERA, LONG, Locale.US); |
|
125 } |
|
126 } |