Path: blob/master/test/jdk/java/util/Locale/Bug8032842.java
41149 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 8032842 817553925* @summary Checks that the filterTags() and lookup() methods26* preserve the case of matching language tag(s).27* Before 8032842 fix these methods return the matching28* language tag(s) in lowercase.29* Also, checks the filterTags() to return only unique30* (ignoring case considerations) matching tags.31*32*/3334import java.util.List;35import java.util.Locale;36import java.util.Locale.FilteringMode;37import java.util.Locale.LanguageRange;3839public class Bug8032842 {4041public static void main(String[] args) {4243// test filterBasic() for preserving the case of matching tags for44// the language range '*', with no duplicates in the matching tags45testFilter("*", List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP",46"JA-JP", "en-GB"),47List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),48FilteringMode.AUTOSELECT_FILTERING);4950// test filterBasic() for preserving the case of matching tags for51// basic ranges other than *, with no duplicates in the matching tags52testFilter("mtm-RU, en-GB", List.of("En-Gb", "mTm-RU", "en-US",53"en-latn", "en-GB"),54List.of("mTm-RU", "En-Gb"), FilteringMode.AUTOSELECT_FILTERING);5556// test filterExtended() for preserving the case of matching tags for57// the language range '*', with no duplicates in the matching tags58testFilter("*", List.of("de-CH", "hi-in", "En-GB", "hi-IN",59"ja-Latn-JP", "JA-JP"),60List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),61FilteringMode.EXTENDED_FILTERING);6263// test filterExtended() for preserving the case of matching tags for64// extended ranges other than *, with no duplicates in the matching tags65testFilter("*-ch;q=0.5, *-Latn;q=0.4", List.of("fr-CH", "de-Ch",66"en-latn", "en-US", "en-Latn"),67List.of("fr-CH", "de-Ch", "en-latn"),68FilteringMode.EXTENDED_FILTERING);6970// test lookupTag() for preserving the case of matching tag71testLookup("*-ch;q=0.5", List.of("en", "fR-cH"), "fR-cH");7273}7475public static void testFilter(String ranges, List<String> tags,76List<String> expected, FilteringMode mode) {77List<LanguageRange> priorityList = LanguageRange.parse(ranges);78List<String> actual = Locale.filterTags(priorityList, tags, mode);79if (!actual.equals(expected)) {80throw new RuntimeException("[filterTags() failed for the language"81+ " range: " + ranges + ", Expected: " + expected82+ ", Found: " + actual + "]");83}84}8586public static void testLookup(String ranges, List<String> tags,87String expected) {88List<LanguageRange> priorityList = LanguageRange.parse(ranges);89String actual = Locale.lookupTag(priorityList, tags);90if (!actual.equals(expected)) {91throw new RuntimeException("[lookupTag() failed for the language"92+ " range: " + ranges + ", Expected: " + expected93+ ", Found: " + actual + "]");94}95}9697}9899100101