1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.api.java.util; 19 20import dalvik.annotation.TestTargetNew; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetClass; 24 25import java.util.Calendar; 26import java.util.Date; 27import java.util.GregorianCalendar; 28import java.util.SimpleTimeZone; 29import java.util.TimeZone; 30 31@TestTargetClass(SimpleTimeZone.class) 32public class SimpleTimeZoneTest extends junit.framework.TestCase { 33 34 SimpleTimeZone st1; 35 36 SimpleTimeZone st2; 37 38 /** 39 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String) 40 */ 41 @TestTargetNew( 42 level = TestLevel.COMPLETE, 43 notes = "", 44 method = "SimpleTimeZone", 45 args = {int.class, java.lang.String.class} 46 ) 47 public void test_ConstructorILjava_lang_String() { 48 // Test for method java.util.SimpleTimeZone(int, java.lang.String) 49 50 SimpleTimeZone st = new SimpleTimeZone(1000, "TEST"); 51 assertEquals("Incorrect TZ constructed", "TEST", st.getID()); 52 assertTrue("Incorrect TZ constructed: " + "returned wrong offset", st 53 .getRawOffset() == 1000); 54 assertTrue("Incorrect TZ constructed" + "using daylight savings", !st 55 .useDaylightTime()); 56 } 57 58 /** 59 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String, 60 * int, int, int, int, int, int, int, int) 61 */ 62 @TestTargetNew( 63 level = TestLevel.COMPLETE, 64 notes = "", 65 method = "SimpleTimeZone", 66 args = {int.class, java.lang.String.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class} 67 ) 68 public void test_ConstructorILjava_lang_StringIIIIIIII() { 69 // Test for method java.util.SimpleTimeZone(int, java.lang.String, int, 70 // int, int, int, int, int, int, int) 71 SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 72 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 73 0); 74 assertTrue("Incorrect TZ constructed", st 75 .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER, 76 13).getTime())); 77 assertTrue("Incorrect TZ constructed", !(st 78 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 79 13).getTime()))); 80 assertEquals("Incorrect TZ constructed", "TEST", st.getID()); 81 assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset()); 82 assertTrue("Incorrect TZ constructed", st.useDaylightTime()); 83 84 try { 85 new SimpleTimeZone(1000, "TEST", 12, 86 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 87 0); 88 fail("IllegalArgumentException expected"); 89 } catch (IllegalArgumentException e) { 90 //expected 91 } 92 93 try { 94 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 95 10, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 96 0); 97 fail("IllegalArgumentException expected"); 98 } catch (IllegalArgumentException e) { 99 //expected 100 } 101 102 try { 103 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 104 1, 10, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 105 0); 106 fail("IllegalArgumentException expected"); 107 } catch (IllegalArgumentException e) { 108 //expected 109 } 110 111 try { 112 new SimpleTimeZone(1000, "TEST", Calendar.DECEMBER, 113 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -10, Calendar.SUNDAY, 114 0); 115 fail("IllegalArgumentException expected"); 116 } catch (IllegalArgumentException e) { 117 //expected 118 } 119 } 120 121 /** 122 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String, 123 * int, int, int, int, int, int, int, int, int) 124 */ 125 @TestTargetNew( 126 level = TestLevel.COMPLETE, 127 notes = "", 128 method = "SimpleTimeZone", 129 args = {int.class, java.lang.String.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class} 130 ) 131 public void test_ConstructorILjava_lang_StringIIIIIIIII() { 132 // Test for method java.util.SimpleTimeZone(int, java.lang.String, int, 133 // int, int, int, int, int, int, int, int) 134 SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 135 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 136 0, 1000 * 60 * 60); 137 assertTrue("Incorrect TZ constructed", st 138 .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER, 139 13).getTime())); 140 assertTrue("Incorrect TZ constructed", !(st 141 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 142 13).getTime()))); 143 assertEquals("Incorrect TZ constructed", "TEST", st.getID()); 144 assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset()); 145 assertTrue("Incorrect TZ constructed", st.useDaylightTime()); 146 assertTrue("Incorrect TZ constructed", 147 st.getDSTSavings() == 1000 * 60 * 60); 148 149 try { 150 new SimpleTimeZone(1000, "TEST", 12, 151 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 152 0, 1000 * 60 * 60); 153 fail("IllegalArgumentException expected"); 154 } catch (IllegalArgumentException e) { 155 //expected 156 } 157 158 try { 159 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 160 10, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 161 0, 1000 * 60 * 60); 162 fail("IllegalArgumentException expected"); 163 } catch (IllegalArgumentException e) { 164 //expected 165 } 166 167 try { 168 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 169 1, 10, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 170 0, 1000 * 60 * 60); 171 fail("IllegalArgumentException expected"); 172 } catch (IllegalArgumentException e) { 173 //expected 174 } 175 176 try { 177 new SimpleTimeZone(1000, "TEST", Calendar.DECEMBER, 178 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -10, Calendar.SUNDAY, 179 0, 1000 * 60 * 60); 180 fail("IllegalArgumentException expected"); 181 } catch (IllegalArgumentException e) { 182 //expected 183 } 184 } 185 186 /** 187 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String, 188 * int, int, int, int, int, int, int, int, int, int, int) 189 */ 190 @TestTargetNew( 191 level = TestLevel.COMPLETE, 192 notes = "", 193 method = "SimpleTimeZone", 194 args = {int.class, java.lang.String.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class} 195 ) 196 public void test_ConstructorILjava_lang_StringIIIIIIIIIII() { 197 // Test for method java.util.SimpleTimeZone(int, java.lang.String, int, 198 // int, int, int, int, int, int, int, int, int, int) 199 // TODO : Implement test 200 //Regression for HARMONY-1241 201 assertNotNull(new SimpleTimeZone( 202 TimeZone.LONG, 203 "Europe/Paris", 204 SimpleTimeZone.STANDARD_TIME, 205 SimpleTimeZone.STANDARD_TIME, 206 SimpleTimeZone.UTC_TIME, 207 SimpleTimeZone.WALL_TIME, 208 SimpleTimeZone.WALL_TIME, 209 TimeZone.SHORT, 210 SimpleTimeZone.STANDARD_TIME, 211 TimeZone.LONG, 212 SimpleTimeZone.UTC_TIME, 213 SimpleTimeZone.STANDARD_TIME, 214 TimeZone.LONG)); 215 //seems RI doesn't check the startTimeMode and endTimeMode at all 216 //this behavior is contradicts with spec 217 assertNotNull(new SimpleTimeZone( 218 TimeZone.LONG, 219 "Europe/Paris", 220 SimpleTimeZone.STANDARD_TIME, 221 SimpleTimeZone.STANDARD_TIME, 222 SimpleTimeZone.UTC_TIME, 223 SimpleTimeZone.WALL_TIME, 224 Integer.MAX_VALUE, 225 TimeZone.SHORT, 226 SimpleTimeZone.STANDARD_TIME, 227 TimeZone.LONG, 228 SimpleTimeZone.UTC_TIME, 229 Integer.MIN_VALUE, 230 TimeZone.LONG)); 231 232 try { 233 new SimpleTimeZone(1000, "TEST", 12, 234 1, Calendar.SUNDAY, 0, Integer.MAX_VALUE, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 235 0, Integer.MAX_VALUE, 1000 * 60 * 60); 236 fail("IllegalArgumentException expected"); 237 } catch (IllegalArgumentException e) { 238 //expected 239 } 240 241 try { 242 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 243 10, Calendar.SUNDAY, 0, Integer.MAX_VALUE, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 244 0, Integer.MAX_VALUE, 1000 * 60 * 60); 245 fail("IllegalArgumentException expected"); 246 } catch (IllegalArgumentException e) { 247 //expected 248 } 249 250 try { 251 new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 252 1, 10, 0, Calendar.NOVEMBER, Integer.MAX_VALUE, -1, Calendar.SUNDAY, 253 0, Integer.MAX_VALUE, 1000 * 60 * 60); 254 fail("IllegalArgumentException expected"); 255 } catch (IllegalArgumentException e) { 256 //expected 257 } 258 259 try { 260 new SimpleTimeZone(1000, "TEST", Calendar.DECEMBER, 261 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, Integer.MAX_VALUE, -10, Calendar.SUNDAY, 262 0, Integer.MAX_VALUE, 1000 * 60 * 60); 263 fail("IllegalArgumentException expected"); 264 } catch (IllegalArgumentException e) { 265 //expected 266 } 267 } 268 269 /** 270 * @tests java.util.SimpleTimeZone#clone() 271 */ 272 @TestTargetNew( 273 level = TestLevel.COMPLETE, 274 notes = "", 275 method = "clone", 276 args = {} 277 ) 278 public void test_clone() { 279 // Test for method java.lang.Object java.util.SimpleTimeZone.clone() 280 SimpleTimeZone st1 = new SimpleTimeZone(1000, "TEST", 281 Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, 282 -1, Calendar.SUNDAY, 0); 283 SimpleTimeZone stA = new SimpleTimeZone(1, "Gah"); 284 assertTrue("Clone resulted in same reference", st1.clone() != st1); 285 assertTrue("Clone resulted in unequal object", ((SimpleTimeZone) st1 286 .clone()).equals(st1)); 287 assertTrue("Clone resulted in same reference", stA.clone() != stA); 288 assertTrue("Clone resulted in unequal object", ((SimpleTimeZone) stA 289 .clone()).equals(stA)); 290 } 291 292 /** 293 * @tests java.util.SimpleTimeZone#equals(java.lang.Object) 294 */ 295 @TestTargetNew( 296 level = TestLevel.COMPLETE, 297 notes = "", 298 method = "equals", 299 args = {java.lang.Object.class} 300 ) 301 public void test_equalsLjava_lang_Object() { 302 // Test for method boolean 303 // java.util.SimpleTimeZone.equals(java.lang.Object) 304 TimeZone tz = TimeZone.getTimeZone("EST"); 305 st1 = new SimpleTimeZone(tz.getRawOffset(), "EST"); 306 st2 = new SimpleTimeZone(0, "EST"); 307 assertFalse(st1.equals(st2)); 308 st1.setRawOffset(st2.getRawOffset()); 309 assertTrue(st1.equals(st2)); 310 } 311 312 /** 313 * @tests java.util.SimpleTimeZone#getDSTSavings() 314 */ 315 @TestTargetNew( 316 level = TestLevel.COMPLETE, 317 notes = "", 318 method = "getDSTSavings", 319 args = {} 320 ) 321 public void test_getDSTSavings() { 322 // Test for method int java.util.SimpleTimeZone.getDSTSavings() 323 st1 = new SimpleTimeZone(0, "TEST"); 324 325 assertEquals("Non-zero default daylight savings", 326 0, st1.getDSTSavings()); 327 st1.setStartRule(0, 1, 1, 1); 328 st1.setEndRule(11, 1, 1, 1); 329 330 assertEquals("Incorrect default daylight savings", 331 3600000, st1.getDSTSavings()); 332 st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1, 333 -Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1, 334 Calendar.SUNDAY, 2 * 3600000, 7200000); 335 assertEquals("Incorrect daylight savings from constructor", 7200000, st1 336 .getDSTSavings()); 337 338 } 339 340 /** 341 * @tests java.util.SimpleTimeZone#getOffset(int, int, int, int, int, int) 342 */ 343 @TestTargetNew( 344 level = TestLevel.COMPLETE, 345 notes = "", 346 method = "getOffset", 347 args = {int.class, int.class, int.class, int.class, int.class, int.class} 348 ) 349 public void test_getOffsetIIIIII() { 350 // Test for method int java.util.SimpleTimeZone.getOffset(int, int, int, 351 // int, int, int) 352// TimeZone st1 = TimeZone.getTimeZone("EST"); 353 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 354 assertTrue("Incorrect offset returned", st1.getOffset( 355 GregorianCalendar.AD, 1998, Calendar.NOVEMBER, 11, 356 Calendar.WEDNESDAY, 0) == -(5 * 60 * 60 * 1000)); 357 358 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 359 assertEquals("Incorrect offset returned", -(5 * 60 * 60 * 1000), st1 360 .getOffset(GregorianCalendar.AD, 1998, Calendar.JUNE, 11, 361 Calendar.THURSDAY, 0)); 362 363 // Regression for HARMONY-5459 364 st1 = new SimpleTimeZone(TimeZone.getDefault().getRawOffset(), TimeZone.getDefault().getID()); 365 int fourHours = 4*60*60*1000; 366 st1.setRawOffset(fourHours); 367 assertEquals(fourHours, st1.getOffset(1, 2099, 01, 1, 5, 0)); 368 369 try { 370 st1.getOffset(-1, 2099, 01, 1, 5, 0); 371 fail("IllegalArgumentException expected"); 372 } catch (IllegalArgumentException e) { 373 //expected 374 } 375 376 try { 377 st1.getOffset(1, 2099, 15, 1, 5, 0); 378 fail("IllegalArgumentException expected"); 379 } catch (IllegalArgumentException e) { 380 //expected 381 } 382 383 try { 384 st1.getOffset(1, 2099, 01, 100, 5, 0); 385 fail("IllegalArgumentException expected"); 386 } catch (IllegalArgumentException e) { 387 //expected 388 } 389 390 try { 391 st1.getOffset(1, 2099, 01, 1, 50, 0); 392 fail("IllegalArgumentException expected"); 393 } catch (IllegalArgumentException e) { 394 //expected 395 } 396 397 try { 398 st1.getOffset(1, 2099, 01, 1, 5, -10); 399 fail("IllegalArgumentException expected"); 400 } catch (IllegalArgumentException e) { 401 //expected 402 } 403 } 404 405 /** 406 * @tests java.util.SimpleTimeZone#getRawOffset() 407 */ 408 @TestTargetNew( 409 level = TestLevel.COMPLETE, 410 notes = "", 411 method = "getRawOffset", 412 args = {} 413 ) 414 public void test_getRawOffset() { 415 // Test for method int java.util.SimpleTimeZone.getRawOffset() 416 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 417 assertTrue("Incorrect offset returned", 418 st1.getRawOffset() == -(5 * 60 * 60 * 1000)); 419 420 } 421 422 /** 423 * @tests java.util.SimpleTimeZone#hashCode() 424 */ 425 @TestTargetNew( 426 level = TestLevel.COMPLETE, 427 notes = "", 428 method = "hashCode", 429 args = {} 430 ) 431 public void test_hashCode() { 432 // Test for method int java.util.SimpleTimeZone.hashCode() 433 // For lack of a better test. 434 st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1, 435 -Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1, 436 Calendar.SUNDAY, 2 * 3600000); 437 assertTrue(TimeZone.getTimeZone("EST").hashCode() != 0); 438 assertTrue(st1.hashCode() != 0); 439 } 440 441 /** 442 * @tests java.util.SimpleTimeZone#hasSameRules(java.util.TimeZone) 443 */ 444 @TestTargetNew( 445 level = TestLevel.COMPLETE, 446 notes = "", 447 method = "hasSameRules", 448 args = {java.util.TimeZone.class} 449 ) 450 public void test_hasSameRulesLjava_util_TimeZone() { 451 // Test for method boolean 452 // java.util.SimpleTimeZone.hasSameRules(java.util.TimeZone) 453 SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 454 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 455 0); 456 SimpleTimeZone sameAsSt = new SimpleTimeZone(1000, "REST", 457 Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, 458 -1, Calendar.SUNDAY, 0); 459 SimpleTimeZone notSameAsSt = new SimpleTimeZone(1000, "PEST", 460 Calendar.NOVEMBER, 2, Calendar.SUNDAY, 0, Calendar.NOVEMBER, 461 -1, Calendar.SUNDAY, 0); 462 assertTrue("Time zones have same rules but return false", st 463 .hasSameRules(sameAsSt)); 464 assertTrue("Time zones have different rules but return true", !st 465 .hasSameRules(notSameAsSt)); 466 } 467 468 /** 469 * @tests java.util.SimpleTimeZone#inDaylightTime(java.util.Date) 470 */ 471 @TestTargetNew( 472 level = TestLevel.COMPLETE, 473 notes = "", 474 method = "inDaylightTime", 475 args = {java.util.Date.class} 476 ) 477 public void test_inDaylightTimeLjava_util_Date() { 478 // Test for method boolean 479 // java.util.SimpleTimeZone.inDaylightTime(java.util.Date) 480 TimeZone tz = TimeZone.getTimeZone("EST"); 481 SimpleTimeZone zone = new SimpleTimeZone(tz.getRawOffset(), "EST", 482 Calendar.APRIL, 1, -Calendar.SUNDAY, 7200000, Calendar.OCTOBER, -1, Calendar.SUNDAY, 7200000, 3600000); 483 GregorianCalendar gc = new GregorianCalendar(1998, Calendar.JUNE, 11); 484 485 assertTrue("Returned incorrect daylight value1", zone.inDaylightTime(gc 486 .getTime())); 487 gc = new GregorianCalendar(1998, Calendar.NOVEMBER, 11); 488 assertTrue("Returned incorrect daylight value2", !(zone 489 .inDaylightTime(gc.getTime()))); 490 gc = new GregorianCalendar(zone); 491 gc.set(1999, Calendar.APRIL, 4, 1, 59, 59); 492 assertTrue("Returned incorrect daylight value3", !(zone 493 .inDaylightTime(gc.getTime()))); 494 Date date = new Date(gc.getTime().getTime() + 1000); 495 assertTrue("Returned incorrect daylight value4", zone 496 .inDaylightTime(date)); 497 gc.set(1999, Calendar.OCTOBER, 31, 1, 0, 0); 498 assertTrue("Returned incorrect daylight value5", !(zone 499 .inDaylightTime(gc.getTime()))); 500 date = new Date(gc.getTime().getTime() - 1000); 501 assertTrue("Returned incorrect daylight value6", zone 502 .inDaylightTime(date)); 503 504 assertTrue("Returned incorrect daylight value7", !zone 505 .inDaylightTime(new Date(891752400000L + 7200000 - 1))); 506 assertTrue("Returned incorrect daylight value8", zone 507 .inDaylightTime(new Date(891752400000L + 7200000))); 508 assertTrue("Returned incorrect daylight value9", zone 509 .inDaylightTime(new Date(909288000000L + 7200000 - 1))); 510 assertTrue("Returned incorrect daylight value10", !zone 511 .inDaylightTime(new Date(909288000000L + 7200000))); 512 } 513 514 /** 515 * @tests java.util.SimpleTimeZone#setDSTSavings(int) 516 */ 517 @TestTargetNew( 518 level = TestLevel.COMPLETE, 519 notes = "", 520 method = "setDSTSavings", 521 args = {int.class} 522 ) 523 public void test_setDSTSavingsI() { 524 // Test for method void java.util.SimpleTimeZone.setDSTSavings(int) 525 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 526 st.setStartRule(0, 1, 1, 1); 527 st.setEndRule(11, 1, 1, 1); 528 st.setDSTSavings(1); 529 assertEquals("Daylight savings amount not set", 1, st.getDSTSavings()); 530 } 531 532 /** 533 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int) 534 */ 535 @TestTargetNew( 536 level = TestLevel.COMPLETE, 537 notes = "", 538 method = "setEndRule", 539 args = {int.class, int.class, int.class} 540 ) 541 public void test_setEndRuleIII() { 542 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 543 st.setStartRule(Calendar.NOVEMBER, 1, 0); 544 st.setEndRule(Calendar.NOVEMBER, 20, 0); 545 assertTrue("StartRule improperly set1", st.useDaylightTime()); 546 assertTrue("StartRule improperly set2", st.inDaylightTime( 547 new GregorianCalendar(1998, Calendar.NOVEMBER, 548 13).getTime())); 549 assertTrue("StartRule improperly set3", !(st 550 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 551 13).getTime()))); 552 553 try { 554 st.setEndRule(13, 20, 0); 555 fail("IllegalArgumentException is not thrown."); 556 } catch(IllegalArgumentException iae) { 557 //expected 558 } 559 560 try { 561 st.setEndRule(1, 32, 0); 562 fail("IllegalArgumentException is not thrown."); 563 } catch(IllegalArgumentException iae) { 564 //expected 565 } 566 567 try { 568 st.setEndRule(1, 30, 10); 569 fail("IllegalArgumentException is not thrown."); 570 } catch(IllegalArgumentException iae) { 571 //expected 572 } 573 } 574 575 /** 576 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int) 577 */ 578 @TestTargetNew( 579 level = TestLevel.COMPLETE, 580 notes = "", 581 method = "setEndRule", 582 args = {int.class, int.class, int.class, int.class} 583 ) 584 public void test_setEndRuleIIII() { 585 // Test for method void java.util.SimpleTimeZone.setEndRule(int, int, 586 // int, int) 587 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 588 // Spec indicates that both end and start must be set or result is 589 // undefined 590 st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0); 591 st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0); 592 assertTrue("StartRule improperly set1", st.useDaylightTime()); 593 assertTrue("StartRule improperly set2", st 594 .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER, 595 13).getTime())); 596 assertTrue("StartRule improperly set3", !(st 597 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 598 13).getTime()))); 599 600 try { 601 st.setEndRule(12, -1, Calendar.SUNDAY, 0); 602 fail("IllegalArgumentException is not thrown."); 603 } catch(IllegalArgumentException iae) { 604 //expected 605 } 606 607 try { 608 st.setEndRule(Calendar.NOVEMBER, 10, Calendar.SUNDAY, 0); 609 fail("IllegalArgumentException is not thrown."); 610 } catch(IllegalArgumentException iae) { 611 //expected 612 } 613 614 try { 615 st.setEndRule(Calendar.NOVEMBER, -1, 8, 0); 616 fail("IllegalArgumentException is not thrown."); 617 } catch(IllegalArgumentException iae) { 618 //expected 619 } 620 621 try { 622 st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, -10); 623 fail("IllegalArgumentException is not thrown."); 624 } catch(IllegalArgumentException iae) { 625 //expected 626 } 627 } 628 629 /** 630 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int, boolean) 631 */ 632 @TestTargetNew( 633 level = TestLevel.COMPLETE, 634 notes = "", 635 method = "setEndRule", 636 args = {int.class, int.class, int.class, int.class, boolean.class} 637 ) 638 public void test_setEndRuleIIIIZ() { 639 // Test for method void java.util.SimpleTimeZone.setEndRule(int, int, 640 // int, int, boolean) 641 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 642 // Spec indicates that both end and start must be set or result is 643 // undefined 644 st.setStartRule(Calendar.NOVEMBER, 8, Calendar.SUNDAY, 1, false); 645 st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, true); 646 assertTrue("StartRule improperly set1", st.useDaylightTime()); 647 assertTrue("StartRule improperly set2", st 648 .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 649 7, 12, 0).getTime()))); 650 assertTrue("StartRule improperly set3", st 651 .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 652 20, 12, 0).getTime()))); 653 assertTrue("StartRule improperly set4", !(st 654 .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 655 6, 12, 0).getTime()))); 656 assertTrue("StartRule improperly set5", !(st 657 .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 658 21, 12, 0).getTime()))); 659 660 try { 661 st.setEndRule(20, 15, Calendar.SUNDAY, 1, true); 662 fail("IllegalArgumentException is not thrown."); 663 } catch(IllegalArgumentException iae) { 664 //expected 665 } 666 667 try { 668 st.setEndRule(Calendar.NOVEMBER, 35, Calendar.SUNDAY, 1, true); 669 fail("IllegalArgumentException is not thrown."); 670 } catch(IllegalArgumentException iae) { 671 //expected 672 } 673 674 try { 675 st.setEndRule(Calendar.NOVEMBER, 15, 12, 1, true); 676 fail("IllegalArgumentException is not thrown."); 677 } catch(IllegalArgumentException iae) { 678 //expected 679 } 680 681 try { 682 st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, -1, true); 683 fail("IllegalArgumentException is not thrown."); 684 } catch(IllegalArgumentException iae) { 685 //expected 686 } 687 } 688 689 /** 690 * @tests java.util.SimpleTimeZone#setRawOffset(int) 691 */ 692 @TestTargetNew( 693 level = TestLevel.COMPLETE, 694 notes = "", 695 method = "setRawOffset", 696 args = {int.class} 697 ) 698 public void test_setRawOffsetI() { 699 // Test for method void java.util.SimpleTimeZone.setRawOffset(int) 700 701 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 702 int off = st1.getRawOffset(); 703 st1.setRawOffset(1000); 704 boolean val = st1.getRawOffset() == 1000; 705 st1.setRawOffset(off); 706 assertTrue("Incorrect offset set", val); 707 } 708 709 /** 710 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int) 711 */ 712 @TestTargetNew( 713 level = TestLevel.COMPLETE, 714 notes = "", 715 method = "setStartRule", 716 args = {int.class, int.class, int.class} 717 ) 718 public void test_setStartRuleIII() { 719 // Test for method void java.util.SimpleTimeZone.setStartRule(int, int, 720 // int) 721 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 722 // Spec indicates that both end and start must be set or result is 723 // undefined 724 st.setStartRule(Calendar.NOVEMBER, 1, 1); 725 st.setEndRule(Calendar.DECEMBER, 1, 1); 726 assertTrue("StartRule improperly set", st.useDaylightTime()); 727 assertTrue("StartRule improperly set", st 728 .inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER, 729 13).getTime()))); 730 assertTrue("StartRule improperly set", !(st 731 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 732 13).getTime()))); 733 734 try { 735 st.setStartRule(13, 20, 0); 736 fail("IllegalArgumentException is not thrown."); 737 } catch(IllegalArgumentException iae) { 738 //expected 739 } 740 741 try { 742 st.setStartRule(1, 32, 0); 743 fail("IllegalArgumentException is not thrown."); 744 } catch(IllegalArgumentException iae) { 745 //expected 746 } 747 748 try { 749 st.setStartRule(1, 30, 10); 750 fail("IllegalArgumentException is not thrown."); 751 } catch(IllegalArgumentException iae) { 752 //expected 753 } 754 } 755 756 /** 757 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int) 758 */ 759 @TestTargetNew( 760 level = TestLevel.COMPLETE, 761 notes = "", 762 method = "setStartRule", 763 args = {int.class, int.class, int.class, int.class} 764 ) 765 public void test_setStartRuleIIII() { 766 // Test for method void java.util.SimpleTimeZone.setStartRule(int, int, 767 // int, int) 768 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 769 // Spec indicates that both end and start must be set or result is 770 // undefined 771 st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0); 772 st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0); 773 assertTrue("StartRule improperly set1", st.useDaylightTime()); 774 assertTrue("StartRule improperly set2", st 775 .inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER, 776 13).getTime()))); 777 assertTrue("StartRule improperly set3", !(st 778 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 779 13).getTime()))); 780 781 try { 782 st.setStartRule(12, -1, Calendar.SUNDAY, 0); 783 fail("IllegalArgumentException is not thrown."); 784 } catch(IllegalArgumentException iae) { 785 //expected 786 } 787 788 try { 789 st.setStartRule(Calendar.NOVEMBER, 10, Calendar.SUNDAY, 0); 790 fail("IllegalArgumentException is not thrown."); 791 } catch(IllegalArgumentException iae) { 792 //expected 793 } 794 795 try { 796 st.setStartRule(Calendar.NOVEMBER, -1, 8, 0); 797 fail("IllegalArgumentException is not thrown."); 798 } catch(IllegalArgumentException iae) { 799 //expected 800 } 801 802 try { 803 st.setStartRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, -10); 804 fail("IllegalArgumentException is not thrown."); 805 } catch(IllegalArgumentException iae) { 806 //expected 807 } 808 } 809 810 /** 811 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int, boolean) 812 */ 813 @TestTargetNew( 814 level = TestLevel.COMPLETE, 815 notes = "", 816 method = "setStartRule", 817 args = {int.class, int.class, int.class, int.class, boolean.class} 818 ) 819 public void test_setStartRuleIIIIZ() { 820 // Test for method void java.util.SimpleTimeZone.setStartRule(int, int, 821 // int, int, boolean) 822 SimpleTimeZone st = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 823 // Spec indicates that both end and start must be set or result is 824 // undefined 825 st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 1, true); 826 st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, false); 827 assertTrue("StartRule improperly set1", st.useDaylightTime()); 828 assertTrue("StartRule improperly set2", st 829 .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 830 7, 12, 0).getTime()))); 831 assertTrue("StartRule improperly set3", st 832 .inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 833 13, 12, 0).getTime()))); 834 assertTrue("StartRule improperly set4", !(st 835 .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 836 6, 12, 0).getTime()))); 837 assertTrue("StartRule improperly set5", !(st 838 .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 839 14, 12, 0).getTime()))); 840 841 try { 842 st.setStartRule(20, 15, Calendar.SUNDAY, 1, true); 843 fail("IllegalArgumentException is not thrown."); 844 } catch(IllegalArgumentException iae) { 845 //expected 846 } 847 848 try { 849 st.setStartRule(Calendar.NOVEMBER, 35, Calendar.SUNDAY, 1, true); 850 fail("IllegalArgumentException is not thrown."); 851 } catch(IllegalArgumentException iae) { 852 //expected 853 } 854 855 try { 856 st.setStartRule(Calendar.NOVEMBER, 15, 12, 1, true); 857 fail("IllegalArgumentException is not thrown."); 858 } catch(IllegalArgumentException iae) { 859 //expected 860 } 861 862 try { 863 st.setStartRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, -1, true); 864 fail("IllegalArgumentException is not thrown."); 865 } catch(IllegalArgumentException iae) { 866 //expected 867 } 868 } 869 870 /** 871 * @tests java.util.SimpleTimeZone#setStartYear(int) 872 */ 873 @TestTargetNew( 874 level = TestLevel.COMPLETE, 875 notes = "", 876 method = "setStartYear", 877 args = {int.class} 878 ) 879 public void test_setStartYearI() { 880 // Test for method void java.util.SimpleTimeZone.setStartYear(int) 881 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 882 st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0); 883 st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0); 884 st.setStartYear(1999); 885 assertTrue("set year improperly set1", !(st 886 .inDaylightTime(new GregorianCalendar(1999, Calendar.JULY, 12) 887 .getTime()))); 888 assertTrue("set year improperly set2", !(st 889 .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 890 13).getTime()))); 891 assertTrue("set year improperly set3", (st 892 .inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 893 13).getTime()))); 894 } 895 896 /** 897 * @tests java.util.SimpleTimeZone#toString() 898 */ 899 @TestTargetNew( 900 level = TestLevel.COMPLETE, 901 notes = "", 902 method = "toString", 903 args = {} 904 ) 905 public void test_toString() { 906 // Test for method java.lang.String java.util.SimpleTimeZone.toString() 907 String string = TimeZone.getTimeZone("EST").toString(); 908 assertNotNull("toString() returned null", string); 909 assertTrue("toString() is empty", string.length() != 0); 910 } 911 912 /** 913 * @tests java.util.SimpleTimeZone#useDaylightTime() 914 */ 915 @TestTargetNew( 916 level = TestLevel.COMPLETE, 917 notes = "", 918 method = "useDaylightTime", 919 args = {} 920 ) 921 public void test_useDaylightTime() { 922 // Test for method boolean java.util.SimpleTimeZone.useDaylightTime() 923 SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ"); 924 assertTrue("useDaylightTime returned incorrect value", !st 925 .useDaylightTime()); 926 // Spec indicates that both end and start must be set or result is 927 // undefined 928 st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0); 929 st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0); 930 assertTrue("useDaylightTime returned incorrect value", st 931 .useDaylightTime()); 932 } 933 934 @TestTargetNew( 935 level = TestLevel.COMPLETE, 936 notes = "", 937 method = "getOffset", 938 args = {long.class} 939 ) 940 public void test_getOffsetJ() { 941 Calendar cal = Calendar.getInstance(); 942 cal.set(1998, Calendar.NOVEMBER, 11, 0, 0); 943 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 944 945 assertTrue("Incorrect offset returned", st1.getOffset(cal.getTimeInMillis()) == 946 -(5 * 60 * 60 * 1000)); 947 948 st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST"); 949 cal.set(1998, Calendar.JUNE, 11, 0, 0); 950 assertEquals("Incorrect offset returned", -(5 * 60 * 60 * 1000), st1 951 .getOffset(cal.getTimeInMillis())); 952 953 // Regression for HARMONY-5459 954 st1 = new SimpleTimeZone(TimeZone.getDefault().getRawOffset(), TimeZone.getDefault().getID()); 955 int fourHours = 4*60*60*1000; 956 st1.setRawOffset(fourHours); 957 cal.set(2099, 01, 1, 0, 0); 958 959 assertEquals(fourHours, st1.getOffset(cal.getTimeInMillis())); 960 961 } 962 963 964 /** 965 * Sets up the fixture, for example, open a network connection. This method 966 * is called before a test is executed. 967 */ 968 protected void setUp() { 969 } 970 971 /** 972 * Tears down the fixture, for example, close a network connection. This 973 * method is called after a test is executed. 974 */ 975 protected void tearDown() { 976 } 977} 978