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