Path: blob/master/test/jdk/java/text/Collator/G7Test.java
41149 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* @modules jdk.localedata28*/29/*30*31*32* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved33* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved34*35* Portions copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.36*37* The original version of this source code and documentation is copyrighted38* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These39* materials are provided under terms of a License Agreement between Taligent40* and Sun. This technology is protected by multiple US and International41* patents. This notice and attribution to Taligent may not be removed.42* Taligent is a registered trademark of Taligent, Inc.43*44*/4546/**47* G7 Test cases48*49* @author Helena Shih50*/5152import java.text.Collator;53import java.text.RuleBasedCollator;54import java.util.Locale;5556// G7 test program for printing out test results5758public class G7Test extends CollatorTest {5960public static void main(String[] args) throws Exception {61new G7Test().run(args);62}6364private static final String testCases[] = {65"black-birds", // 066"Pat", // 167"p\u00E9ch\u00E9", // 268"p\u00EAche", // 369"p\u00E9cher", // 470"p\u00EAcher", // 571"Tod", // 672"T\u00F6ne", // 773"Tofu", // 874"blackbirds", // 975"Ton", // 1076"PAT", // 1177"blackbird", // 1278"black-bird", // 1379"pat", // 1480// Additional tests81"czar", // 1582"churo", // 1683"cat", // 1784"darn", // 1885"?", // 1986"quick", // 2087"#", // 2188"&", // 2289"aardvark", // 2390"a-rdvark", // 2491"abbot", // 2592"coop", // 2693"co-p", // 2794"cop", // 2895"zebra" // 2996};9798// loop to TOTALTESTSET99private static final int[][] G7Results = {100{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1015, 6, 8, 10, 7, 31, 31, 31, 31, 31,10231, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_US103{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1045, 6, 8, 10, 7, 31, 31, 31, 31, 31,10531, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_GB106{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1075, 6, 8, 10, 7, 31, 31, 31, 31, 31,10831, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_CA109{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,1105, 6, 8, 10, 7, 31, 31, 31, 31, 31,11131, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_FR112{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,1135, 6, 8, 10, 7, 31, 31, 31, 31, 31,11431, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_CA115{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1165, 6, 8, 10, 7, 31, 31, 31, 31, 31,11731, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // de_DE118{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1195, 6, 8, 10, 7, 31, 31, 31, 31, 31,12031, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // it_IT121{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,1225, 6, 8, 10, 7, 31, 31, 31, 31, 31,12331, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // ja_JP124};125126// new table collation with rules "& Z < p, P"127// loop to FIXEDTESTSET128private static final int[] Test1Results = {12912, 13, 9, 0, 6, 8, 10, 7, 14, 1,13011, 2, 3, 4, 5, 31, 31, 31, 31, 31,13131, 31, 31, 31, 31, 31, 31, 31, 31, 31132};133134// new table collation with rules "& C < ch , cH, Ch, CH "135// loop to TOTALTESTSET136private static final int[] Test2Results = {13719, 22, 21, 23, 25, 24, 12, 13, 9, 0,13817, 26, 28, 27, 15, 16, 18, 14, 1, 11,1392, 3, 4, 5, 20, 6, 8, 10, 7, 29140};141142// new table collation with rules143// "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&' "144// loop to TOTALTESTSET145private static final int[] Test3Results = {14623, 25, 22, 24, 12, 13, 9, 0, 17, 16,14726, 28, 27, 15, 18, 21, 14, 1, 11, 2,1483, 4, 5, 19, 20, 6, 8, 10, 7, 29149};150151// analogous to Japanese rules152// " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- "153// loop to TOTALTESTSET154private static final int[] Test4Results = {15519, 22, 21, 23, 24, 25, 12, 13, 9, 0,15617, 16, 26, 27, 28, 15, 18, 14, 1, 11,1572, 3, 4, 5, 20, 6, 8, 10, 7, 29158};159160public void TestG7Data() {161for (int i = 0; i < locales.length; i++) {162Collator myCollation= null;163RuleBasedCollator tblColl1 = null;164165try {166myCollation = Collator.getInstance(locales[i]);167tblColl1 = new RuleBasedCollator(((RuleBasedCollator)myCollation).getRules());168} catch (Exception foo) {169errln("Exception: " + foo.getMessage() +170" Locale : " + locales[i].getDisplayName() +171" getRules failed\n");172continue;173}174for (int j = 0; j < FIXEDTESTSET; j++) {175for (int n = j+1; n < FIXEDTESTSET; n++) {176doTest(tblColl1, testCases[G7Results[i][j]],177testCases[G7Results[i][n]], -1);178}179}180myCollation = null;181}182}183184/*185* Demo Test 1 : Create a new table collation with rules "& Z < p, P"186*/187public void TestDemoTest1() {188int j = 0;189final Collator myCollation = Collator.getInstance(Locale.US);190final String defRules = ((RuleBasedCollator)myCollation).getRules();191RuleBasedCollator tblColl = null;192String newRules = defRules + " & Z < p, P";193194try {195tblColl = new RuleBasedCollator(newRules);196for (j = 0; j < FIXEDTESTSET; j++) {197for (int n = j+1; n < FIXEDTESTSET; n++) {198doTest(tblColl, testCases[Test1Results[j]],199testCases[Test1Results[n]], -1);200}201}202tblColl = null;203} catch (Exception foo) {204errln("Exception: " + foo.getMessage() +205"\nDemo Test 1 Table Collation object creation failed.");206}207}208209/*210* Demo Test 2 : Create a new table collation with rules211* "& C < ch , cH, Ch, CH"212*/213public void TestDemoTest2() {214final Collator myCollation = Collator.getInstance(Locale.US);215final String defRules = ((RuleBasedCollator)myCollation).getRules();216String newRules = defRules + "& C < ch , cH, Ch, CH";217218try {219RuleBasedCollator tblColl = new RuleBasedCollator(newRules);220for (int j = 0; j < TOTALTESTSET; j++) {221for (int n = j+1; n < TOTALTESTSET; n++) {222doTest(tblColl, testCases[Test2Results[j]],223testCases[Test2Results[n]], -1);224}225}226} catch (Exception foo) {227errln("Exception: " + foo.getMessage() +228"\nDemo Test 2 Table Collation object creation failed.\n");229}230}231232/*233* Demo Test 3 : Create a new table collation with rules234* "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"235*/236public void TestDemoTest3() {237final Collator myCollation = Collator.getInstance(Locale.US);238final String defRules = ((RuleBasedCollator)myCollation).getRules();239RuleBasedCollator tblColl = null;240String newRules = defRules + "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&";241242try {243tblColl = new RuleBasedCollator(newRules);244for (int j = 0; j < TOTALTESTSET; j++) {245for (int n = j+1; n < TOTALTESTSET; n++) {246doTest(tblColl, testCases[Test3Results[j]],247testCases[Test3Results[n]], -1);248}249}250} catch (Exception foo) {251errln("Exception: " + foo.getMessage() +252"\nDemo Test 3 Table Collation object creation failed.");253}254}255256/*257* Demo Test 4 : Create a new table collation with rules258* " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "259*/260public void TestDemoTest4() {261final Collator myCollation = Collator.getInstance(Locale.US);262final String defRules = ((RuleBasedCollator)myCollation).getRules();263RuleBasedCollator tblColl = null;264String newRules = defRules + " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";265266try {267tblColl = new RuleBasedCollator(newRules);268for (int j = 0; j < TOTALTESTSET; j++) {269for (int n = j+1; n < TOTALTESTSET; n++) {270doTest(tblColl, testCases[Test4Results[j]],271testCases[Test4Results[n]], -1);272}273}274} catch (Exception foo) {275errln("Exception: " + foo.getMessage() +276"\nDemo Test 4 Table Collation object creation failed.");277}278tblColl = null;279}280281private static final int FIXEDTESTSET = 15;282private static final int TOTALTESTSET = 30;283284private static final Locale locales[] = {285Locale.US,286Locale.UK,287Locale.CANADA,288Locale.FRANCE,289Locale.CANADA_FRENCH,290Locale.GERMANY,291Locale.JAPAN,292Locale.ITALY293};294}295296297