Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Collator/G7Test.java
47182 views
/*1* Copyright (c) 1997, 2016, 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*/2223/*24* @test25* @library /java/text/testlib26* @summary test G7 Collation27*/28/*29*30*31* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved32* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved33*34* Portions copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.35*36* The original version of this source code and documentation is copyrighted37* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These38* materials are provided under terms of a License Agreement between Taligent39* and Sun. This technology is protected by multiple US and International40* patents. This notice and attribution to Taligent may not be removed.41* Taligent is a registered trademark of Taligent, Inc.42*43*/4445/**46* G7 Test cases47*48* @author Helena Shih49*/5051import java.text.Collator;52import java.text.RuleBasedCollator;53import java.util.Locale;5455// G7 test program for printing out test results5657public class G7Test extends CollatorTest {5859public static void main(String[] args) throws Exception {60new G7Test().run(args);61}6263private static final String testCases[] = {64"black-birds", // 065"Pat", // 166"p\u00E9ch\u00E9", // 267"p\u00EAche", // 368"p\u00E9cher", // 469"p\u00EAcher", // 570"Tod", // 671"T\u00F6ne", // 772"Tofu", // 873"blackbirds", // 974"Ton", // 1075"PAT", // 1176"blackbird", // 1277"black-bird", // 1378"pat", // 1479// Additional tests80"czar", // 1581"churo", // 1682"cat", // 1783"darn", // 1884"?", // 1985"quick", // 2086"#", // 2187"&", // 2288"aardvark", // 2389"a-rdvark", // 2490"abbot", // 2591"coop", // 2692"co-p", // 2793"cop", // 2894"zebra" // 2995};9697// loop to TOTALTESTSET98private static final int[][] G7Results = {99{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1005, 6, 8, 10, 7, 31, 31, 31, 31, 31,10131, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_US102{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1035, 6, 8, 10, 7, 31, 31, 31, 31, 31,10431, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_GB105{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1065, 6, 8, 10, 7, 31, 31, 31, 31, 31,10731, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_CA108{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,1095, 6, 8, 10, 7, 31, 31, 31, 31, 31,11031, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_FR111{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,1125, 6, 8, 10, 7, 31, 31, 31, 31, 31,11331, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_CA114{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1155, 6, 8, 10, 7, 31, 31, 31, 31, 31,11631, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // de_DE117{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1185, 6, 8, 10, 7, 31, 31, 31, 31, 31,11931, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // it_IT120{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1215, 6, 8, 10, 7, 31, 31, 31, 31, 31,12231, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // ja_JP123};124125// new table collation with rules "& Z < p, P"126// loop to FIXEDTESTSET127private static final int[] Test1Results = {12812, 13, 9, 0, 6, 8, 10, 7, 14, 1,12911, 2, 3, 4, 5, 31, 31, 31, 31, 31,13031, 31, 31, 31, 31, 31, 31, 31, 31, 31131};132133// new table collation with rules "& C < ch , cH, Ch, CH "134// loop to TOTALTESTSET135private static final int[] Test2Results = {13619, 22, 21, 23, 25, 24, 12, 13, 9, 0,13717, 26, 28, 27, 15, 16, 18, 14, 1, 11,1382, 3, 4, 5, 20, 6, 8, 10, 7, 29139};140141// new table collation with rules142// "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&' "143// loop to TOTALTESTSET144private static final int[] Test3Results = {14523, 25, 22, 24, 12, 13, 9, 0, 17, 16,14626, 28, 27, 15, 18, 21, 14, 1, 11, 2,1473, 4, 5, 19, 20, 6, 8, 10, 7, 29148};149150// analogous to Japanese rules151// " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- "152// loop to TOTALTESTSET153private static final int[] Test4Results = {15419, 22, 21, 23, 24, 25, 12, 13, 9, 0,15517, 16, 26, 27, 28, 15, 18, 14, 1, 11,1562, 3, 4, 5, 20, 6, 8, 10, 7, 29157};158159public void TestG7Data() {160for (int i = 0; i < locales.length; i++) {161Collator myCollation= null;162RuleBasedCollator tblColl1 = null;163164try {165myCollation = Collator.getInstance(locales[i]);166tblColl1 = new RuleBasedCollator(((RuleBasedCollator)myCollation).getRules());167} catch (Exception foo) {168errln("Exception: " + foo.getMessage() +169" Locale : " + locales[i].getDisplayName() +170" getRules failed\n");171continue;172}173for (int j = 0; j < FIXEDTESTSET; j++) {174for (int n = j+1; n < FIXEDTESTSET; n++) {175doTest(tblColl1, testCases[G7Results[i][j]],176testCases[G7Results[i][n]], -1);177}178}179myCollation = null;180}181}182183/*184* Demo Test 1 : Create a new table collation with rules "& Z < p, P"185*/186public void TestDemoTest1() {187int j = 0;188final Collator myCollation = Collator.getInstance(Locale.US);189final String defRules = ((RuleBasedCollator)myCollation).getRules();190RuleBasedCollator tblColl = null;191String newRules = defRules + " & Z < p, P";192193try {194tblColl = new RuleBasedCollator(newRules);195for (j = 0; j < FIXEDTESTSET; j++) {196for (int n = j+1; n < FIXEDTESTSET; n++) {197doTest(tblColl, testCases[Test1Results[j]],198testCases[Test1Results[n]], -1);199}200}201tblColl = null;202} catch (Exception foo) {203errln("Exception: " + foo.getMessage() +204"\nDemo Test 1 Table Collation object creation failed.");205}206}207208/*209* Demo Test 2 : Create a new table collation with rules210* "& C < ch , cH, Ch, CH"211*/212public void TestDemoTest2() {213final Collator myCollation = Collator.getInstance(Locale.US);214final String defRules = ((RuleBasedCollator)myCollation).getRules();215String newRules = defRules + "& C < ch , cH, Ch, CH";216217try {218RuleBasedCollator tblColl = new RuleBasedCollator(newRules);219for (int j = 0; j < TOTALTESTSET; j++) {220for (int n = j+1; n < TOTALTESTSET; n++) {221doTest(tblColl, testCases[Test2Results[j]],222testCases[Test2Results[n]], -1);223}224}225} catch (Exception foo) {226errln("Exception: " + foo.getMessage() +227"\nDemo Test 2 Table Collation object creation failed.\n");228}229}230231/*232* Demo Test 3 : Create a new table collation with rules233* "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"234*/235public void TestDemoTest3() {236final Collator myCollation = Collator.getInstance(Locale.US);237final String defRules = ((RuleBasedCollator)myCollation).getRules();238RuleBasedCollator tblColl = null;239String newRules = defRules + "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&";240241try {242tblColl = new RuleBasedCollator(newRules);243for (int j = 0; j < TOTALTESTSET; j++) {244for (int n = j+1; n < TOTALTESTSET; n++) {245doTest(tblColl, testCases[Test3Results[j]],246testCases[Test3Results[n]], -1);247}248}249} catch (Exception foo) {250errln("Exception: " + foo.getMessage() +251"\nDemo Test 3 Table Collation object creation failed.");252}253}254255/*256* Demo Test 4 : Create a new table collation with rules257* " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "258*/259public void TestDemoTest4() {260final Collator myCollation = Collator.getInstance(Locale.US);261final String defRules = ((RuleBasedCollator)myCollation).getRules();262RuleBasedCollator tblColl = null;263String newRules = defRules + " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";264265try {266tblColl = new RuleBasedCollator(newRules);267for (int j = 0; j < TOTALTESTSET; j++) {268for (int n = j+1; n < TOTALTESTSET; n++) {269doTest(tblColl, testCases[Test4Results[j]],270testCases[Test4Results[n]], -1);271}272}273} catch (Exception foo) {274errln("Exception: " + foo.getMessage() +275"\nDemo Test 4 Table Collation object creation failed.");276}277tblColl = null;278}279280private static final int FIXEDTESTSET = 15;281private static final int TOTALTESTSET = 30;282283private static final Locale locales[] = {284Locale.US,285Locale.UK,286Locale.CANADA,287Locale.FRANCE,288Locale.CANADA_FRENCH,289Locale.GERMANY,290Locale.JAPAN,291Locale.ITALY292};293}294295296