Path: blob/master/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseRollDayOfWeekTestGenerator.java
41152 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.PrintWriter;24import java.nio.file.Path;25import java.nio.file.Paths;26import java.util.GregorianCalendar;27import java.util.Locale;28import static java.util.Calendar.*;293031public class JapaneseRollDayOfWeekTestGenerator {32private static final String[] ERAS = {33"BeforeMeiji", "Meiji", "Taisho", "Showa", "Heisei"34};3536private static final String[] DAYOFWEEK = {37null, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"38};3940private static final int[] DAYOFMONTH = {4125, 26, 27, 28, 29, 30, 31,421, 2, 3, 4, 5, 6, 743};4445private static final int DOM_BASE = 7;4647//Usage: JapaneseRollDayOfWeekTestGenerator will generate test script into48// file rolldow.cts.49public static void generateTestScript(String[] args) throws Exception{50Locale.setDefault(Locale.ROOT);5152//This test generator assumes that Heisei has (nYears - 1) or more years.53int nYears = (args.length == 1) ?54Math.max(3, Math.min(Integer.parseInt(args[0]), 40)) : 28;5556// Start from Showa 6357int era = 3;58int year = 63;59Path testPath = Paths.get(System.getProperty("test.classes"));60String scFileName = testPath + "/rolldow.cts";6162try (PrintWriter out = new PrintWriter(scFileName)){63out.println("locale ja JP JP\n" + "new instance jcal\n" + "use jcal");64for (int y = 0; y < nYears; y++) {65out.printf("\nTest %s %d\n", ERAS[era], year);66for (int fdw = SUNDAY; fdw <= SATURDAY; fdw++) {67int endFdw = fdw + 6;68if (endFdw > SATURDAY) {69endFdw -= 7;70}71for (int mdifw = 1; mdifw <= 7; mdifw++) {72int domIndex = DOM_BASE;73out.println(" clear all");74out.printf(" set FirstDayOfWeek %s\n", DAYOFWEEK[fdw]);75out.printf(" set MinimalDaysInFirstWeek %d\n", mdifw);76out.printf(" set date %s %d Jan 1\n", ERAS[era], year);77out.println(" get week_of_year\n" + " assign $result $woy");78out.println(" get day_of_week\n" + " assign $result $doy");7980int gyear = year + (year >= 60 ? 1925 : 1988);81int next = new GregorianCalendar(gyear, JANUARY, 1).get(DAY_OF_WEEK);82for (int i = 0; i < 10; i++) {8384out.println(" roll day_of_week 1");85next = nextFdw(next, fdw, endFdw);86if (next == fdw) {87domIndex -= 6;88} else {89domIndex++;90}91int dom = DAYOFMONTH[domIndex];92out.printf("\tcheck date %d %s %d%n", (dom >= 25) ? year - 1 : year,93(dom >= 25) ? "Dec" : "Jan", dom);94out.println("\teval $doy + 1");95out.println("\tassign $result $doy");96out.println("\tassign Sun $doy if $doy > Sat");97out.println("\tcheck day_of_week $doy");98out.println("\tcheck week_of_year $woy");99}100101for (int i = 0; i < 10; i++) {102out.println("\troll day_of_week -1");103out.println("\teval $doy - 1");104out.println("\tassign $result $doy");105out.println("\tassign Sat $doy if $doy < Sun");106out.println("\tcheck day_of_week $doy");107out.println("\tcheck week_of_year $woy");108}109}110}111112if (year == 64 && era == 3) {113era++;114year = 2;115} else {116year++;117}118}119}120}121122private static int nextFdw(int x, int start, int end) {123if (x == end)124return start;125x++;126if (x > SATURDAY)127x = SUNDAY;128return x;129}130}131132133