test/jdk/java/util/Calendar/CalendarDataTest.java
author jbhateja
Tue, 26 Nov 2019 16:09:25 +0300
changeset 59278 8375560db76b
parent 58825 c3696c94049d
permissions -rw-r--r--
8234394: C2: Dynamic register class support in ADLC Reviewed-by: vlivanov, sviswanathan, thartmann, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     1
/*
54769
925ee7a89325 8221432: Upgrade CLDR to Version 35.1
naoto
parents: 50576
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     4
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     8
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    13
 * accompanied this code).
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    14
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    18
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    21
 * questions.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    22
 */
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    23
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    24
/**
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    25
 * @test
58825
c3696c94049d 8231273: Upgrade CLDR to v36
naoto
parents: 54769
diff changeset
    26
 * @bug 8190918 8202537 8221432 8231273
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    27
 * @summary Tests for region dependent calendar data, i.e.,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    28
 *      firstDayOfWeek and minimalDaysInFirstWeek.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    29
 * @modules jdk.localedata
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    30
 * @run main CalendarDataTest
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    31
 */
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    32
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    33
import java.util.Calendar;
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    34
import java.util.List;
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    35
import java.util.Locale;
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    36
import java.util.Optional;
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    37
import java.util.stream.IntStream;
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    38
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    39
public class CalendarDataTest {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    40
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    41
    // golden data from CLDR
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    42
    private static final List<List<String>> FIRSTDAYDATA = List.of(
58825
c3696c94049d 8231273: Upgrade CLDR to v36
naoto
parents: 54769
diff changeset
    43
        List.of("1", "AG AS AU BD BR BS BT BW BZ CA CN CO DM DO ET GT " +
54769
925ee7a89325 8221432: Upgrade CLDR to Version 35.1
naoto
parents: 50576
diff changeset
    44
            "GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ " +
925ee7a89325 8221432: Upgrade CLDR to Version 35.1
naoto
parents: 50576
diff changeset
    45
            "NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE " +
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    46
            "VI WS YE ZA ZW"),
58825
c3696c94049d 8231273: Upgrade CLDR to v36
naoto
parents: 54769
diff changeset
    47
        List.of("2",   "001 AD AI AL AM AN AR AT AX AZ BA BE BG BM BN BY " +
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    48
            "CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP " +
58825
c3696c94049d 8231273: Upgrade CLDR to v36
naoto
parents: 54769
diff changeset
    49
            "GR HR HU IE IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ " +
c3696c94049d 8231273: Upgrade CLDR to v36
naoto
parents: 54769
diff changeset
    50
            "MY NL NO NZ PL RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ " +
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    51
            "VA VN XK"),
50576
374bd919d8fe 8202537: CLDR33
rgoel
parents: 48251
diff changeset
    52
        List.of("6", "MV"),
54769
925ee7a89325 8221432: Upgrade CLDR to Version 35.1
naoto
parents: 50576
diff changeset
    53
        List.of("7", "AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY"));
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    54
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    55
    private static final List<List<String>> MINDAYSDATA = List.of(
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    56
        List.of("1", "001 GU UM US VI"),
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    57
        List.of("4", "AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR " +
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    58
            "GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO " +
50576
374bd919d8fe 8202537: CLDR33
rgoel
parents: 48251
diff changeset
    59
            "PL PT RE RU SE SJ SK SM VA"));
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    60
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    61
    public static void main(String... args) throws Exception {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    62
        // world
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    63
        Calendar cal = Calendar.getInstance(new Locale("", "001"));
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    64
        checkResult("001",
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    65
            cal.getFirstDayOfWeek(),
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    66
            cal.getMinimalDaysInFirstWeek());
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    67
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    68
        // two letter country codes
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    69
        IntStream.range(0x41, 0x5b)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    70
            .forEach(c1 -> {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    71
                IntStream.range(0x41, 0x5b)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    72
                    .mapToObj(c2 -> String.valueOf((char)c1) + String.valueOf((char)c2))
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    73
                    .forEach(region -> {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    74
                        Calendar c = Calendar.getInstance(new Locale("", region));
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    75
                        checkResult(region,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    76
                                c.getFirstDayOfWeek(),
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    77
                                c.getMinimalDaysInFirstWeek());
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    78
                    });
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    79
            });
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    80
    }
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    81
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    82
    private static void checkResult(String region, int firstDay, int minDays) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    83
        // first day of week
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    84
        int expected = Integer.parseInt(findEntry(region, FIRSTDAYDATA)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    85
            .orElse(findEntry("001", FIRSTDAYDATA).orElse(List.of("1")))
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    86
            .get(0));
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    87
        if (firstDay != expected) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    88
            throw new RuntimeException("firstDayOfWeek is incorrect for the region: " +
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    89
                    region + ". Returned: " + firstDay + ", Expected: " + expected);
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    90
        }
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    91
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    92
        // minimal days in first week
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    93
        expected = Integer.parseInt(findEntry(region, MINDAYSDATA)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    94
            .orElse(findEntry("001", MINDAYSDATA).orElse(List.of("1")))
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    95
            .get(0));
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    96
        if (minDays != expected) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    97
            throw new RuntimeException("minimalDaysInFirstWeek is incorrect for the region: " +
50576
374bd919d8fe 8202537: CLDR33
rgoel
parents: 48251
diff changeset
    98
                    region + ". Returned: " + minDays + ", Expected: " + expected);
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
    99
        }
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   100
    }
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   101
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   102
    private static Optional<List<String>> findEntry(String region, List<List<String>> data) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   103
        return data.stream()
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   104
            .filter(l -> l.get(1).contains(region))
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   105
            .findAny();
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   106
    }
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   107
}
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
diff changeset
   108