Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/util/Calendar/bug4372743.java
48795 views
1
/*
2
* Copyright (c) 2000, 2016, 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 4372743
27
* @summary test that checks transitions of ERA and YEAR which are caused by add(MONTH).
28
* @library /java/text/testlib
29
*/
30
31
import java.io.*;
32
import java.util.*;
33
import java.text.*;
34
35
import static java.util.GregorianCalendar.*;
36
37
public class bug4372743 extends IntlTest {
38
39
public static void main(String[] args) throws Exception {
40
new bug4372743().run(args);
41
}
42
43
private int[][] data = {
44
{AD, 2, MARCH},
45
{AD, 2, FEBRUARY},
46
{AD, 2, JANUARY},
47
{AD, 1, DECEMBER},
48
{AD, 1, NOVEMBER},
49
{AD, 1, OCTOBER},
50
{AD, 1, SEPTEMBER},
51
{AD, 1, AUGUST},
52
{AD, 1, JULY},
53
{AD, 1, JUNE},
54
{AD, 1, MAY},
55
{AD, 1, APRIL},
56
{AD, 1, MARCH},
57
{AD, 1, FEBRUARY},
58
{AD, 1, JANUARY},
59
{BC, 1, DECEMBER},
60
{BC, 1, NOVEMBER},
61
{BC, 1, OCTOBER},
62
{BC, 1, SEPTEMBER},
63
{BC, 1, AUGUST},
64
{BC, 1, JULY},
65
{BC, 1, JUNE},
66
{BC, 1, MAY},
67
{BC, 1, APRIL},
68
{BC, 1, MARCH},
69
{BC, 1, FEBRUARY},
70
{BC, 1, JANUARY},
71
{BC, 2, DECEMBER},
72
{BC, 2, NOVEMBER},
73
{BC, 2, OCTOBER},
74
};
75
private int tablesize = data.length;
76
77
private void check(GregorianCalendar gc, int index) {
78
if (gc.get(ERA) != data[index][ERA]) {
79
errln("Invalid era :" + gc.get(ERA) +
80
", expected :" + data[index][ERA]);
81
}
82
if (gc.get(YEAR) != data[index][YEAR]) {
83
errln("Invalid year :" + gc.get(YEAR) +
84
", expected :" + data[index][YEAR]);
85
}
86
if (gc.get(MONTH) != data[index][MONTH]) {
87
errln("Invalid month :" + gc.get(MONTH) +
88
", expected :" + data[index][MONTH]);
89
}
90
}
91
92
public void Test4372743() {
93
GregorianCalendar gc;
94
TimeZone saveZone = TimeZone.getDefault();
95
96
try {
97
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
98
99
/* Set March 3, A.D. 2 */
100
gc = new GregorianCalendar(2, MARCH, 3);
101
for (int i = 0; i < tablesize; i++) {
102
check(gc, i);
103
gc.add(gc.MONTH, -1);
104
}
105
106
/* Again, Set March 3, A.D. 2 */
107
gc = new GregorianCalendar(2, MARCH, 3);
108
for (int i = 0; i < tablesize; i+=7) {
109
check(gc, i);
110
gc.add(gc.MONTH, -7);
111
}
112
113
/* Set March 10, 2 B.C. */
114
gc = new GregorianCalendar(2, OCTOBER, 10);
115
gc.add(gc.YEAR, -3);
116
for (int i = tablesize -1; i >= 0; i--) {
117
check(gc, i);
118
gc.add(gc.MONTH, 1);
119
}
120
121
/* Again, Set March 10, 2 B.C. */
122
gc = new GregorianCalendar(2, OCTOBER, 10);
123
gc.add(gc.YEAR, -3);
124
for (int i = tablesize -1; i >= 0; i-=8) {
125
check(gc, i);
126
gc.add(gc.MONTH, 8);
127
}
128
}
129
finally {
130
TimeZone.setDefault(saveZone);
131
}
132
}
133
}
134
135