jdk/test/java/util/Calendar/Bug8075548.java
author naoto
Wed, 24 Jun 2015 16:42:11 -0700
changeset 31263 a81a0af34ca0
parent 29720 374070bf0fdf
permissions -rw-r--r--
8008577: Use CLDR Locale Data by Default Reviewed-by: erikj, okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29720
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     1
/*
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     4
 *
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     8
 *
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    13
 * accompanied this code).
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    14
 *
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    18
 *
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    21
 * questions.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    22
 */
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    23
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    24
/**
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    25
 * @test
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    26
 * @bug 8075548
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    27
 * @summary Make sure that the format form of month names are produced when there are
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    28
 *          no stand-alone ones available.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    29
 */
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    30
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    31
import java.text.*;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    32
import java.util.*;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    33
import static java.util.Calendar.*;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    34
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    35
public class Bug8075548 {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    36
    static int errors = 0;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    37
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    38
    public static void main(String[] args) throws Throwable {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    39
        Date date = new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2010-09-15");
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    40
        String[][] FORMAT_PAIRS = {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    41
            { "LLLL", "MMMM" },
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    42
            { "LLL",  "MMM" }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    43
        };
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    44
        Locale[] LOCALES = {
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 29720
diff changeset
    45
            Locale.ENGLISH, Locale.JAPANESE
29720
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    46
        };
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    47
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    48
        for (Locale locale : LOCALES) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    49
            for (String[] formats : FORMAT_PAIRS) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    50
                String el = new SimpleDateFormat(formats[0], locale).format(date);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    51
                String em = new SimpleDateFormat(formats[1], locale).format(date);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    52
                if (!el.equals(em)) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    53
                    errors++;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    54
                    System.err.println(locale + ": " +
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    55
                                       formats[0] + " -> " + el + ", " +
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    56
                                       formats[1] + " -> " + em);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    57
                }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    58
            }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    59
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    60
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    61
        // Test Calendar.getDisplayName() and .getDisplayNames().
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    62
        for (Locale locale : LOCALES) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    63
            testDisplayNames(locale, LONG_FORMAT, LONG_STANDALONE);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    64
            testDisplayNames(locale, SHORT_FORMAT, SHORT_STANDALONE);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    65
            testDisplayNames(locale, NARROW_FORMAT, NARROW_STANDALONE);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    66
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    67
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    68
        if (errors > 0) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    69
            throw new RuntimeException("Failed");
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    70
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    71
    }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    72
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    73
    private static void testDisplayNames(Locale locale, int formatStyle, int standaloneStyle) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    74
        Map<String, Integer> map = new HashMap<>();
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    75
        for (int month = JANUARY; month <= DECEMBER; month++) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    76
            Calendar cal = new GregorianCalendar(2015, month, 1);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    77
            String format = cal.getDisplayName(MONTH, formatStyle, locale);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    78
            String standalone = cal.getDisplayName(MONTH, standaloneStyle, locale);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    79
            if (!format.equals(standalone)) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    80
                System.err.println("Calendar.getDisplayName: " + (month+1) +
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    81
                                   ", locale=" + locale +
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    82
                                   ", format=" + format + ", standalone=" + standalone);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    83
                errors++;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    84
            }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    85
            if (standalone != null) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    86
                map.put(standalone, month);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    87
            }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    88
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    89
        if (formatStyle == NARROW_FORMAT) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    90
            // Narrow styles don't support unique names.
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    91
            // (e.g., "J" for JANUARY, JUNE, and JULY)
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    92
            return;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    93
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    94
        Calendar cal = new GregorianCalendar(2015, JANUARY, 1);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    95
        Map<String, Integer> mapStandalone = cal.getDisplayNames(MONTH, standaloneStyle, locale);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    96
        if (!map.equals(mapStandalone)) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    97
            System.err.printf("Calendar.getDisplayNames: locale=%s%n    map=%s%n    mapStandalone=%s%n",
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    98
                              locale, map, mapStandalone);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
    99
            errors++;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   100
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   101
        Map<String, Integer> mapAll = cal.getDisplayNames(MONTH, ALL_STYLES, locale);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   102
        if (!mapAll.entrySet().containsAll(map.entrySet())) {
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   103
            System.err.printf("Calendar.getDisplayNames: locale=%s%n    map=%s%n    mapAll=%s%n",
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   104
                              locale, map, mapAll);
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   105
            errors++;
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   106
        }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   107
    }
374070bf0fdf 8075548: SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"
okutsu
parents:
diff changeset
   108
}