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