Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/util/Calendar/bug4372743.java
48795 views
/*1* Copyright (c) 2000, 2016, 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*/2223/*24* @test25* @bug 437274326* @summary test that checks transitions of ERA and YEAR which are caused by add(MONTH).27* @library /java/text/testlib28*/2930import java.io.*;31import java.util.*;32import java.text.*;3334import static java.util.GregorianCalendar.*;3536public class bug4372743 extends IntlTest {3738public static void main(String[] args) throws Exception {39new bug4372743().run(args);40}4142private int[][] data = {43{AD, 2, MARCH},44{AD, 2, FEBRUARY},45{AD, 2, JANUARY},46{AD, 1, DECEMBER},47{AD, 1, NOVEMBER},48{AD, 1, OCTOBER},49{AD, 1, SEPTEMBER},50{AD, 1, AUGUST},51{AD, 1, JULY},52{AD, 1, JUNE},53{AD, 1, MAY},54{AD, 1, APRIL},55{AD, 1, MARCH},56{AD, 1, FEBRUARY},57{AD, 1, JANUARY},58{BC, 1, DECEMBER},59{BC, 1, NOVEMBER},60{BC, 1, OCTOBER},61{BC, 1, SEPTEMBER},62{BC, 1, AUGUST},63{BC, 1, JULY},64{BC, 1, JUNE},65{BC, 1, MAY},66{BC, 1, APRIL},67{BC, 1, MARCH},68{BC, 1, FEBRUARY},69{BC, 1, JANUARY},70{BC, 2, DECEMBER},71{BC, 2, NOVEMBER},72{BC, 2, OCTOBER},73};74private int tablesize = data.length;7576private void check(GregorianCalendar gc, int index) {77if (gc.get(ERA) != data[index][ERA]) {78errln("Invalid era :" + gc.get(ERA) +79", expected :" + data[index][ERA]);80}81if (gc.get(YEAR) != data[index][YEAR]) {82errln("Invalid year :" + gc.get(YEAR) +83", expected :" + data[index][YEAR]);84}85if (gc.get(MONTH) != data[index][MONTH]) {86errln("Invalid month :" + gc.get(MONTH) +87", expected :" + data[index][MONTH]);88}89}9091public void Test4372743() {92GregorianCalendar gc;93TimeZone saveZone = TimeZone.getDefault();9495try {96TimeZone.setDefault(TimeZone.getTimeZone("PST"));9798/* Set March 3, A.D. 2 */99gc = new GregorianCalendar(2, MARCH, 3);100for (int i = 0; i < tablesize; i++) {101check(gc, i);102gc.add(gc.MONTH, -1);103}104105/* Again, Set March 3, A.D. 2 */106gc = new GregorianCalendar(2, MARCH, 3);107for (int i = 0; i < tablesize; i+=7) {108check(gc, i);109gc.add(gc.MONTH, -7);110}111112/* Set March 10, 2 B.C. */113gc = new GregorianCalendar(2, OCTOBER, 10);114gc.add(gc.YEAR, -3);115for (int i = tablesize -1; i >= 0; i--) {116check(gc, i);117gc.add(gc.MONTH, 1);118}119120/* Again, Set March 10, 2 B.C. */121gc = new GregorianCalendar(2, OCTOBER, 10);122gc.add(gc.YEAR, -3);123for (int i = tablesize -1; i >= 0; i-=8) {124check(gc, i);125gc.add(gc.MONTH, 8);126}127}128finally {129TimeZone.setDefault(saveZone);130}131}132}133134135