Path: blob/master/test/jdk/java/util/Calendar/bug4372743.java
41149 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.util.GregorianCalendar;31import java.util.TimeZone;3233import static java.util.GregorianCalendar.*;3435public class bug4372743 extends IntlTest {3637public static void main(String[] args) throws Exception {38new bug4372743().run(args);39}4041private int[][] data = {42{AD, 2, MARCH},43{AD, 2, FEBRUARY},44{AD, 2, JANUARY},45{AD, 1, DECEMBER},46{AD, 1, NOVEMBER},47{AD, 1, OCTOBER},48{AD, 1, SEPTEMBER},49{AD, 1, AUGUST},50{AD, 1, JULY},51{AD, 1, JUNE},52{AD, 1, MAY},53{AD, 1, APRIL},54{AD, 1, MARCH},55{AD, 1, FEBRUARY},56{AD, 1, JANUARY},57{BC, 1, DECEMBER},58{BC, 1, NOVEMBER},59{BC, 1, OCTOBER},60{BC, 1, SEPTEMBER},61{BC, 1, AUGUST},62{BC, 1, JULY},63{BC, 1, JUNE},64{BC, 1, MAY},65{BC, 1, APRIL},66{BC, 1, MARCH},67{BC, 1, FEBRUARY},68{BC, 1, JANUARY},69{BC, 2, DECEMBER},70{BC, 2, NOVEMBER},71{BC, 2, OCTOBER}};72private int tablesize = data.length;7374private void check(GregorianCalendar gc, int index) {75if (gc.get(ERA) != data[index][ERA]) {76errln("Invalid era :" + gc.get(ERA)77+ ", expected :" + data[index][ERA]);78}79if (gc.get(YEAR) != data[index][YEAR]) {80errln("Invalid year :" + gc.get(YEAR)81+ ", expected :" + data[index][YEAR]);82}83if (gc.get(MONTH) != data[index][MONTH]) {84errln("Invalid month :" + gc.get(MONTH)85+ ", expected :" + data[index][MONTH]);86}87}8889public void Test4372743() {90GregorianCalendar gc;91TimeZone saveZone = TimeZone.getDefault();9293try {94TimeZone.setDefault(TimeZone.getTimeZone("PST"));9596/* Set March 3, A.D. 2 */97gc = new GregorianCalendar(2, MARCH, 3);98for (int i = 0; i < tablesize; i++) {99check(gc, i);100gc.add(MONTH, -1);101}102103/* Again, Set March 3, A.D. 2 */104gc = new GregorianCalendar(2, MARCH, 3);105for (int i = 0; i < tablesize; i += 7) {106check(gc, i);107gc.add(MONTH, -7);108}109110/* Set March 10, 2 B.C. */111gc = new GregorianCalendar(2, OCTOBER, 10);112gc.add(YEAR, -3);113for (int i = tablesize - 1; i >= 0; i--) {114check(gc, i);115gc.add(MONTH, 1);116}117118/* Again, Set March 10, 2 B.C. */119gc = new GregorianCalendar(2, OCTOBER, 10);120gc.add(YEAR, -3);121for (int i = tablesize - 1; i >= 0; i -= 8) {122check(gc, i);123gc.add(MONTH, 8);124}125} finally {126TimeZone.setDefault(saveZone);127}128}129}130131132