1 /*
  2  * Copyright (c) 2001, 2023, 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 4409072
 27  * @summary tests for set(), add(), and roll() with various week parameters.
 28  * @library /java/text/testlib
 29  * @run junit bug4409072
 30  */
 31 
 32 import  java.util.*;
 33 import static java.util.Calendar.*;
 34 
 35 import org.junit.jupiter.api.Test;
 36 
 37 import static org.junit.jupiter.api.Assertions.fail;
 38 
 39 public class bug4409072 {
 40 
 41     /* Confirm some public methods' behavior in Calendar.
 42      * (e.g. add(), roll(), set())
 43      */
 44     @Test
 45     public void Test4409072() {
 46         Locale locale = Locale.getDefault();
 47         if (!TestUtils.usesGregorianCalendar(locale)) {
 48             System.out.println("Skipping this test because locale is " + locale);
 49             return;
 50         }
 51 
 52         Locale savedLocale = Locale.getDefault();
 53         TimeZone savedTZ = TimeZone.getDefault();
 54         try {
 55             TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
 56             testSet();
 57             testAdd();
 58             testRoll();
 59         } finally {
 60             TimeZone.setDefault(savedTZ);
 61             Locale.setDefault(savedLocale);
 62         }
 63     }
 64 
 65     /*
 66      * Golden data for set() test
 67      */
 68     static final int[][][] resultWOMForSetTest = {
 69         { /* For year1998 */
 70           /* Min =     1        2        3        4        5        6        7  */
 71           /* Sun */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11}, {11,11},
 72           /* Mon */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11},
 73           /* Tue */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
 74           /* Wed */ {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
 75           /* Thu */ {10,27}, {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
 76           /* Fri */ {10,27}, {10,27}, {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
 77           /* Sat */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11}, {11,11}, {11,11},
 78         },
 79         { /* For year1999 */
 80           /* Min =     1        2        3        4        5        6        7  */
 81           /* Sun */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10},
 82           /* Mon */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10},
 83           /* Tue */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10},
 84           /* Wed */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
 85           /* Thu */ {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
 86           /* Fri */ {10,26}, {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
 87           /* Sat */ {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10}, {11,10},
 88         },
 89         { /* For year2000 */
 90           /* Min =     1        2        3        4        5        6        7  */
 91           /* Sun */ {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
 92           /* Mon */ {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
 93           /* Tue */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8},
 94           /* Wed */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8},
 95           /* Thu */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8},
 96           /* Fri */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1},
 97           /* Sat */ {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
 98         },
 99         { /* For year2001 */
100           /* Min =     1        2        3        4        5        6        7  */
101           /* Sun */ {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
102           /* Mon */ {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
103           /* Tue */ {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
104           /* Wed */ {10,30}, {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7},
105           /* Thu */ {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7},
106           /* Fri */ {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {11, 7},
107           /* Sat */ {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
108         },
109         { /* For year2002 */
110           /* Min =     1        2        3        4        5        6        7  */
111           /* Sun */ {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
112           /* Mon */ {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
113           /* Tue */ {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
114           /* Wed */ {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
115           /* Thu */ {10,29}, {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6},
116           /* Fri */ {10,29}, {10,29}, {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6},
117           /* Sat */ {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11,13},
118         },
119         { /* For year2003 */
120           /* Min =     1        2        3        4        5        6        7  */
121           /* Sun */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11,12},
122           /* Mon */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
123           /* Tue */ {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
124           /* Wed */ {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
125           /* Thu */ {10,28}, {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
126           /* Fri */ {10,28}, {10,28}, {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5},
127           /* Sat */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11,12}, {11,12},
128         },
129         { /* For year2004 */
130           /* Min =     1        2        3        4        5        6        7  */
131           /* Sun */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10},
132           /* Mon */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10},
133           /* Tue */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10},
134           /* Wed */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
135           /* Thu */ {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
136           /* Fri */ {10,26}, {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
137           /* Sat */ {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10}, {11,10},
138         },
139         { /* For year2005 */
140           /* Min =     1        2        3        4        5        6        7  */
141           /* Sun */ {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9}, {11, 9},
142           /* Mon */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9},
143           /* Tue */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9},
144           /* Wed */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9},
145           /* Thu */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2},
146           /* Fri */ {10,25}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2},
147           /* Sat */ {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9}, {11, 9}, {11, 9},
148         },
149         { /* For year2006 */
150           /* Min =     1        2        3        4        5        6        7  */
151           /* Sun */ {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
152           /* Mon */ {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
153           /* Tue */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8},
154           /* Wed */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8},
155           /* Thu */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8},
156           /* Fri */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1},
157           /* Sat */ {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
158         },
159     };
160 
161     static final int[][][] resultWOYForSetTest1 = {
162         { /* For year1998 */
163             /* FirstDayOfWeek = Sunday */
164               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 9},
165               {1998, 0, 9}, {1998, 0, 9}, {1998, 0, 9},
166             /* FirstDayOfWeek = Monday */
167               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
168               {1998, 0, 9}, {1998, 0, 9}, {1998, 0, 9},
169             /* FirstDayOfWeek = Tuesday */
170               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
171               {1998, 0, 2}, {1998, 0, 9}, {1998, 0, 9},
172             /* FirstDayOfWeek = Wednesday */
173               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
174               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 9},
175             /* FirstDayOfWeek = Thursday */
176               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
177               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
178             /* FirstDayOfWeek = Friday */
179               {1997,11,26}, {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
180               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 2},
181             /* FirstDayOfWeek = Saturday */
182               {1998, 0, 2}, {1998, 0, 2}, {1998, 0, 9}, {1998, 0, 9},
183               {1998, 0, 9}, {1998, 0, 9}, {1998, 0, 9},
184         },
185         { /* For year1999 */
186             /* FirstDayOfWeek = Sunday */
187               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 8}, {1999, 0, 8},
188               {1999, 0, 8}, {1999, 0, 8}, {1999, 0, 8},
189             /* FirstDayOfWeek = Monday */
190               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 8},
191               {1999, 0, 8}, {1999, 0, 8}, {1999, 0, 8},
192             /* FirstDayOfWeek = Tuesday */
193               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1},
194               {1999, 0, 8}, {1999, 0, 8}, {1999, 0, 8},
195             /* FirstDayOfWeek = Wednesday */
196               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1},
197               {1999, 0, 1}, {1999, 0, 8}, {1999, 0, 8},
198             /* FirstDayOfWeek = Thursday */
199               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1},
200               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 8},
201             /* FirstDayOfWeek = Friday */
202               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1},
203               {1999, 0, 1}, {1999, 0, 1}, {1999, 0, 1},
204             /* FirstDayOfWeek = Saturday */
205               {1999, 0, 1}, {1999, 0, 8}, {1999, 0, 8}, {1999, 0, 8},
206               {1999, 0, 8}, {1999, 0, 8}, {1999, 0, 8},
207         },
208         { /* For year2000 */
209             /* FirstDayOfWeek = Sunday */
210               {1999,11,31}, {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
211               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
212             /* FirstDayOfWeek = Monday */
213               {1999,11,31}, {1999,11,31}, {2000, 0, 7}, {2000, 0, 7},
214               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
215             /* FirstDayOfWeek = Tuesday */
216               {1999,11,31}, {1999,11,31}, {1999,11,31}, {2000, 0, 7},
217               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
218             /* FirstDayOfWeek = Wednesday */
219               {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
220               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
221             /* FirstDayOfWeek = Thursday */
222               {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
223               {1999,11,31}, {2000, 0, 7}, {2000, 0, 7},
224             /* FirstDayOfWeek = Friday */
225               {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
226               {1999,11,31}, {1999,11,31}, {2000, 0, 7},
227             /* FirstDayOfWeek = Saturday */
228               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
229               {2000, 0, 7}, {2000, 0, 7}, {2000, 0, 7},
230         },
231         { /* For year2001 */
232             /* FirstDayOfWeek = Sunday */
233               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
234               {2001, 0, 5}, {2001, 0, 5}, {2001, 0,12},
235             /* FirstDayOfWeek = Monday */
236               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
237               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
238             /* FirstDayOfWeek = Tuesday */
239               {2000,11,29}, {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
240               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
241             /* FirstDayOfWeek = Wednesday */
242               {2000,11,29}, {2000,11,29}, {2001, 0, 5}, {2001, 0, 5},
243               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
244             /* FirstDayOfWeek = Thursday */
245               {2000,11,29}, {2000,11,29}, {2000,11,29}, {2001, 0, 5},
246               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
247             /* FirstDayOfWeek = Friday */
248               {2000,11,29}, {2000,11,29}, {2000,11,29}, {2000,11,29},
249               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
250             /* FirstDayOfWeek = Saturday */
251               {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5}, {2001, 0, 5},
252               {2001, 0, 5}, {2001, 0,12}, {2001, 0,12},
253         },
254         { /* For year2002 */
255             /* FirstDayOfWeek = Sunday */
256               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
257               {2002, 0, 4}, {2002, 0,11}, {2002, 0,11},
258             /* FirstDayOfWeek = Monday */
259               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
260               {2002, 0, 4}, {2002, 0, 4}, {2002, 0,11},
261             /* FirstDayOfWeek = Tuesday */
262               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
263               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
264             /* FirstDayOfWeek = Wednesday */
265               {2001,11,28}, {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
266               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
267             /* FirstDayOfWeek = Thursday */
268               {2001,11,28}, {2001,11,28}, {2002, 0, 4}, {2002, 0, 4},
269               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
270             /* FirstDayOfWeek = Friday */
271               {2001,11,28}, {2001,11,28}, {2001,11,28}, {2002, 0, 4},
272               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
273             /* FirstDayOfWeek = Saturday */
274               {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4}, {2002, 0, 4},
275               {2002, 0,11}, {2002, 0,11}, {2002, 0,11},
276         },
277         { /* For year2003 */
278             /* FirstDayOfWeek = Sunday */
279               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
280               {2003, 0,10}, {2003, 0,10}, {2003, 0,10},
281             /* FirstDayOfWeek = Monday */
282               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
283               {2003, 0, 3}, {2003, 0,10}, {2003, 0,10},
284             /* FirstDayOfWeek = Tuesday */
285               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
286               {2003, 0, 3}, {2003, 0, 3}, {2003, 0,10},
287             /* FirstDayOfWeek = Wednesday */
288               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
289               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
290             /* FirstDayOfWeek = Thursday */
291               {2002,11,27}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
292               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
293             /* FirstDayOfWeek = Friday */
294               {2002,11,27}, {2002,11,27}, {2003, 0, 3}, {2003, 0, 3},
295               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3},
296             /* FirstDayOfWeek = Saturday */
297               {2003, 0, 3}, {2003, 0, 3}, {2003, 0, 3}, {2003, 0,10},
298               {2003, 0,10}, {2003, 0,10}, {2003, 0,10},
299         },
300         { /* For year2004 */
301             /* FirstDayOfWeek = Sunday */
302               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 9},
303               {2004, 0, 9}, {2004, 0, 9}, {2004, 0, 9},
304             /* FirstDayOfWeek = Monday */
305               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
306               {2004, 0, 9}, {2004, 0, 9}, {2004, 0, 9},
307             /* FirstDayOfWeek = Tuesday */
308               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
309               {2004, 0, 2}, {2004, 0, 9}, {2004, 0, 9},
310             /* FirstDayOfWeek = Wednesday */
311               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
312               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 9},
313             /* FirstDayOfWeek = Thursday */
314               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
315               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
316             /* FirstDayOfWeek = Friday */
317               {2003,11,26}, {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
318               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 2},
319             /* FirstDayOfWeek = Saturday */
320               {2004, 0, 2}, {2004, 0, 2}, {2004, 0, 9}, {2004, 0, 9},
321               {2004, 0, 9}, {2004, 0, 9}, {2004, 0, 9},
322         },
323         { /* For year2005 */
324             /* FirstDayOfWeek = Sunday */
325               {2004,11,31}, {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
326               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
327             /* FirstDayOfWeek = Monday */
328               {2004,11,31}, {2004,11,31}, {2005, 0, 7}, {2005, 0, 7},
329               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
330             /* FirstDayOfWeek = Tuesday */
331               {2004,11,31}, {2004,11,31}, {2004,11,31}, {2005, 0, 7},
332               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
333             /* FirstDayOfWeek = Wednesday */
334               {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
335               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
336             /* FirstDayOfWeek = Thursday */
337               {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
338               {2004,11,31}, {2005, 0, 7}, {2005, 0, 7},
339             /* FirstDayOfWeek = Friday */
340               {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
341               {2004,11,31}, {2004,11,31}, {2005, 0, 7},
342             /* FirstDayOfWeek = Saturday */
343               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
344               {2005, 0, 7}, {2005, 0, 7}, {2005, 0, 7},
345         },
346         { /* For year2006 */
347             /* FirstDayOfWeek = Sunday */
348               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
349               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
350             /* FirstDayOfWeek = Monday */
351               {2005,11,30}, {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
352               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
353             /* FirstDayOfWeek = Tuesday */
354               {2005,11,30}, {2005,11,30}, {2006, 0, 6}, {2006, 0, 6},
355               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
356             /* FirstDayOfWeek = Wednesday */
357               {2005,11,30}, {2005,11,30}, {2005,11,30}, {2006, 0, 6},
358               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
359             /* FirstDayOfWeek = Thursday */
360               {2005,11,30}, {2005,11,30}, {2005,11,30}, {2005,11,30},
361               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
362             /* FirstDayOfWeek = Friday */
363               {2005,11,30}, {2005,11,30}, {2005,11,30}, {2005,11,30},
364               {2005,11,30}, {2006, 0, 6}, {2006, 0, 6},
365             /* FirstDayOfWeek = Saturday */
366               {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6}, {2006, 0, 6},
367               {2006, 0, 6}, {2006, 0, 6}, {2006, 0,13},
368         }
369     };
370 
371     static final int[][] resultWOYForSetTest2 = {
372           /* Min =    1       2       3       4       5       6       7  */
373           /* Sun */ {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
374           /* Mon */ {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
375           /* Tue */ {4,25}, {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
376           /* Wed */ {4,25}, {4,25}, {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1},
377           /* Thu */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 8}, {5, 8},
378           /* Fri */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 8},
379           /* Sat */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
380     };
381 
382     /**
383      * Test for set()
384      */
385     void testSet() {
386         boolean noerror = true;
387         Calendar cal = Calendar.getInstance();
388         int sYear=1998;
389         int eYear=2006;
390 
391         // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
392         for (int dow = SUNDAY; dow <= SATURDAY; dow++) {
393 
394             // Loop for MinimalDaysInFirstWeek: 1..7
395             for (int minDow = 1; minDow <= 7; minDow++) {
396                 int index = (dow-1)*7 + (minDow-1);
397 
398                 cal.clear();
399                 cal.setLenient(true);
400                 cal.setMinimalDaysInFirstWeek(minDow);
401                 cal.setFirstDayOfWeek(dow);
402                 cal.set(YEAR, 2005);
403                 cal.set(DAY_OF_WEEK, WEDNESDAY);
404                 cal.set(WEEK_OF_YEAR, 22);
405 
406                 int y = 2005;
407                 int m = resultWOYForSetTest2[index][0];
408                 int d = resultWOYForSetTest2[index][1];
409                 int year = cal.get(YEAR);
410                 int month = cal.get(MONTH);
411                 int date = cal.get(DATE);
412 
413                 if (cal.get(WEEK_OF_YEAR) != 22) {
414                     noerror = false;
415                     fail("Failed : set(WEEK_OF_YEAR=22)" +
416                           " *** get(WEEK_OF_YEAR=" +
417                           cal.get(WEEK_OF_YEAR) + ")" +
418                           ", got " + (month+1)+"/"+date+"/"+year +
419                           ", expected " + (m+1)+"/"+d+"/"+2005 +
420                           ", MinFirstDOW=" + minDow +
421                           ", FirstDOW=" + dow);
422                 } else if ((year != y) || (month != m) || (date != d)) {
423                     noerror = false;
424                     fail("Failed : set(WEEK_OF_YEAR=22)" +
425                           " got " + (month+1)+"/"+date+"/"+year +
426                           ", expected " + (m+1)+"/"+d+"/"+y +
427                           ", MinFirstDOW=" + minDow +
428                           ", FirstDOW=" + dow);
429                 }
430 
431                 for (int targetYear = sYear; targetYear<= eYear; targetYear++) {
432                     cal.clear();
433                     cal.setLenient(true);
434                     cal.setMinimalDaysInFirstWeek(minDow);
435                     cal.setFirstDayOfWeek(dow);
436                     cal.set(YEAR, targetYear);
437                     cal.set(DAY_OF_WEEK, FRIDAY);
438                     cal.set(MONTH, DECEMBER);
439                     cal.set(WEEK_OF_MONTH, 1);
440 
441                     y = targetYear;
442                     m = resultWOMForSetTest[targetYear-sYear][index][0];
443                     d = resultWOMForSetTest[targetYear-sYear][index][1];
444                     year = cal.get(YEAR);
445                     month = cal.get(MONTH);
446                     date = cal.get(DATE);
447 
448                     if ((year != y) || (month != m) || (date != d)) {
449                         noerror = false;
450                         fail("Failed : set(WEEK_OF_MONTH=1)" +
451                               " got " + (month+1)+"/"+date+"/"+year +
452                               ", expected " + (m+1)+"/"+d+"/"+y +
453                               ", MinFirstDOW=" + minDow +
454                               ", FirstDOW=" + dow);
455                     }
456 
457                     cal.clear();
458                     cal.setLenient(true);
459                     cal.setMinimalDaysInFirstWeek(minDow);
460                     cal.setFirstDayOfWeek(dow);
461                     cal.set(YEAR, targetYear);
462                     cal.set(DAY_OF_WEEK, FRIDAY);
463                     cal.set(WEEK_OF_YEAR, 1);
464 
465                     y = resultWOYForSetTest1[targetYear-sYear][index][0];
466                     m = resultWOYForSetTest1[targetYear-sYear][index][1];
467                     d = resultWOYForSetTest1[targetYear-sYear][index][2];
468                     year = cal.get(YEAR);
469                     month = cal.get(MONTH);
470                     date = cal.get(DATE);
471 
472                     if (cal.get(WEEK_OF_YEAR) != 1) {
473                         noerror = false;
474                         fail("Failed : set(WEEK_OF_YEAR=1)" +
475                               " *** get(WEEK_OF_YEAR=" +
476                               cal.get(WEEK_OF_YEAR) + ")" +
477                               ", got " + (month+1)+"/"+date+"/"+year +
478                               ", expected " + (m+1)+"/"+d+"/"+y +
479                               ", MinFirstDOW=" + minDow +
480                               ", FirstDOW=" + dow);
481                     } else if ((year != y) || (month != m) || (date != d)) {
482                         noerror = false;
483                         fail("Failed : set(WEEK_OF_YEAR=1)" +
484                               " got " + (month+1)+"/"+date+"/"+year +
485                               ", expected " + (m+1)+"/"+d+"/"+y +
486                               ", MinFirstDOW=" + minDow +
487                               ", FirstDOW=" + dow);
488                     }
489                 }
490             }
491         }
492 
493         if (noerror) {
494             System.out.println("Passed : set() test");
495         }
496     }
497 
498     /**
499      * Test for add()
500      */
501     void testAdd() {
502         boolean noerror = true;
503         Calendar cal = Calendar.getInstance();
504 
505         // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
506         for (int dow = SUNDAY; dow <= SATURDAY; dow++) {
507 
508             // Loop for MinimalDaysInFirstWeek: 1..7
509             for (int minDow = 1; minDow <= 7; minDow++) {
510                 int oldWOY, newWOY;
511 
512                 cal.clear();
513                 cal.setLenient(true);
514                 cal.setMinimalDaysInFirstWeek(minDow);
515                 cal.setFirstDayOfWeek(dow);
516                 cal.set(2005, DECEMBER, 7);
517                 oldWOY = cal.get(WEEK_OF_YEAR);
518 
519                 for (int cnt = 0; cnt < 7; cnt++) {
520                     cal.add(WEEK_OF_YEAR, 1);
521                 }
522 
523                 int year = cal.get(YEAR);
524                 int month = cal.get(MONTH);
525                 int date = cal.get(DATE);
526 
527                 if ((year != 2006) || (month != 0) || (date != 25)) {
528                     noerror = false;
529                     fail("Failed : add(WEEK_OF_YEAR+1)" +
530                           " got " + (month+1)+"/"+date+"/"+year +
531                           ", expected 1/25/2006" +
532                           ", MinFirstDOW=" + minDow +
533                           ", FirstDOW=" + dow);
534                 }
535 
536                 for (int cnt = 0; cnt < 10; cnt++) {
537                     cal.add(WEEK_OF_YEAR, -1);
538                 }
539                 newWOY = cal.get(WEEK_OF_YEAR);
540 
541                 year = cal.get(YEAR);
542                 month = cal.get(MONTH);
543                 date = cal.get(DATE);
544 
545                 if ((oldWOY - newWOY) != 3) {
546                     fail("Failed : add(WEEK_OF_YEAR-1)" +
547                           " got " + (month+1)+"/"+date+"/"+year +
548                           ", expected 11/16/2005" +
549                           ", MinFirstDOW=" + minDow +
550                           ", FirstDOW=" + dow +
551                           ", WEEK_OF_YEAR=" + newWOY +
552                           " should be " + (oldWOY-3));
553                 } else if ((year != 2005) || (month != 10) || (date != 16)) {
554                     fail("Failed : add(-1)" +
555                           " got " + (month+1)+"/"+date+"/"+year +
556                           ", expected 11/16/2005" +
557                           ", MinFirstDOW=" + minDow +
558                           ", FirstDOW=" + dow);
559                 }
560             }
561         }
562 
563         if (noerror) {
564             System.out.println("Passed : add() test");
565         }
566     }
567 
568     /*
569      * Golden data for roll() test
570      */
571     static final int[] resultWOMForRollTest = {
572           /* Min =    1   2   3   4   5   6   7  */
573           /* Sun */   1,  1,  1, 26, 26, 26, 26,
574           /* Mon */   1,  1,  1,  1, 26, 26, 26,
575           /* Tue */  31, 31, 31, 31, 31, 24, 24,
576           /* Wed */  31, 31, 31, 31, 31, 31, 24,
577           /* Thu */  31, 31, 31, 31, 31, 31, 31,
578           /* Fri */   1, 31, 31, 31, 31, 31, 31,
579           /* Sat */   1,  1, 31, 31, 31, 31, 31,
580     };
581 
582     static final int[][] resultWOYForRollTest = {
583           /* Min =    1       2       3       4       5       6       7  */
584           /* Sun */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
585           /* Mon */ {1, 2}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
586           /* Tue */ {1, 2}, {1, 2}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
587           /* Wed */ {1, 2}, {1, 2}, {1, 2}, {0,26}, {0,26}, {0,26}, {0,26},
588           /* Thu */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {1, 2}, {1, 2},
589           /* Fri */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {1, 2},
590           /* Sat */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
591     };
592 
593     /**
594      * Test for roll()
595      */
596     void testRoll() {
597         boolean noerror = true;
598         Calendar cal = Calendar.getInstance();
599 
600         // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
601         for (int dow = SUNDAY; dow <= SATURDAY; dow++) {
602 
603             // Loop for MinimalDaysInFirstWeek: 1..7
604             for (int minDow = 1; minDow <= 7; minDow++) {
605                 int oldWOY, newWOY;
606                 int index = (dow-1)*7 + (minDow-1);
607 
608                 cal.clear();
609                 cal.setLenient(true);
610                 cal.setMinimalDaysInFirstWeek(minDow);
611                 cal.setFirstDayOfWeek(dow);
612                 cal.set(2005, DECEMBER, 12);
613                 oldWOY = cal.get(WEEK_OF_YEAR);
614                 for (int cnt = 0; cnt < 2; cnt++) {
615                     cal.roll(WEEK_OF_MONTH, -1);
616                 }
617                 int y = 2005;
618                 int m = DECEMBER;
619                 int d = resultWOMForRollTest[index];
620                 int year = cal.get(YEAR);
621                 int month = cal.get(MONTH);
622                 int date = cal.get(DATE);
623 
624                 if ((year != y) || (month != m) || (date != d)) {
625                     noerror = false;
626                     fail("Failed : roll(WEEK_OF_MONTH-1)" +
627                           " got " + (month+1) + "/" + date + "/" + year +
628                           ", expected " + (m+1) + "/" + d + "/" + y +
629                           ", MinFirstDOW=" + minDow +
630                           ", FirstDOW=" + dow);
631                 }
632 
633                 cal.clear();
634                 cal.setLenient(true);
635                 cal.setMinimalDaysInFirstWeek(minDow);
636                 cal.setFirstDayOfWeek(dow);
637                 cal.set(2005, DECEMBER, 7);
638                 oldWOY = cal.get(WEEK_OF_YEAR);
639 
640                 for (int cnt = 0; cnt < 7; cnt++) {
641                     cal.roll(WEEK_OF_YEAR, 1);
642                 }
643 
644                 y = 2005;
645                 m = resultWOYForRollTest[index][0];
646                 d = resultWOYForRollTest[index][1];
647                 year = cal.get(YEAR);
648                 month = cal.get(MONTH);
649                 date = cal.get(DATE);
650 
651                 if ((year != y) || (month != m) || (date != d)) {
652                     noerror = false;
653                     fail("Failed : roll(WEEK_OF_YEAR+1)" +
654                           " got " + (month+1) + "/" + date + "/" + year +
655                           ", expected " + (m+1) + "/" + d + "/" + y +
656                           ", MinFirstDOW=" + minDow +
657                           ", FirstDOW=" + dow);
658                 }
659 
660                 for (int cnt = 0; cnt < 10; cnt++) {
661                     cal.roll(WEEK_OF_YEAR, -1);
662                 }
663                 newWOY = cal.get(WEEK_OF_YEAR);
664 
665                 y = 2005;
666                 m = NOVEMBER;
667                 d = 16;
668                 year = cal.get(YEAR);
669                 month = cal.get(MONTH);
670                 date = cal.get(DATE);
671 
672                 if ((year != y) || (month != m) || (date != d)) {
673                     noerror = false;
674                     fail("Failed : roll(WEEK_OF_YEAR-1)" +
675                           " got " + (month+1)+"/"+date+"/"+year +
676                           ", expected " + (m+1)+"/"+d+"/"+y +
677                           ", MinFirstDOW=" + minDow +
678                           ", FirstDOW=" + dow);
679                 }
680             }
681         }
682 
683         if (noerror) {
684             System.out.println("Passed : roll() test");
685         }
686     }
687 }