< prev index next >

test/jdk/java/util/Calendar/bug4409072.java

Print this page

  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
 29  * @run main bug4409072
 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() {
 45         Locale locale = Locale.getDefault();
 46         if (!TestUtils.usesGregorianCalendar(locale)) {
 47             logln("Skipping this test because locale is " + locale);
 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 = {

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},

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 }

  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 = {

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},

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 }
< prev index next >