< prev index next >

test/jdk/java/text/Collator/G7Test.java

Print this page

  1 /*
  2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @library /java/text/testlib
 27  * @summary test G7 Collation
 28  * @modules jdk.localedata

 29  */
 30 /*
 31  *
 32  *
 33  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
 34  * (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
 35  *
 36  * Portions copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
 37  *
 38  *   The original version of this source code and documentation is copyrighted
 39  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
 40  * materials are provided under terms of a License Agreement between Taligent
 41  * and Sun. This technology is protected by multiple US and International
 42  * patents. This notice and attribution to Taligent may not be removed.
 43  *   Taligent is a registered trademark of Taligent, Inc.
 44  *
 45 */
 46 
 47 /**
 48  * G7 Test cases
 49  *
 50  * @author     Helena Shih
 51  */
 52 
 53 import java.text.Collator;
 54 import java.text.RuleBasedCollator;
 55 import java.util.Locale;
 56 
 57 // G7 test program for printing out test results
 58 
 59 public class G7Test extends CollatorTest {
 60 
 61     public static void main(String[] args) throws Exception {
 62         new G7Test().run(args);
 63     }
 64 
 65     private static final String testCases[] = {
 66         "black-birds",              // 0
 67         "Pat",                      // 1
 68         "p\u00E9ch\u00E9",          // 2
 69         "p\u00EAche",               // 3
 70         "p\u00E9cher",              // 4
 71         "p\u00EAcher",              // 5
 72         "Tod",                      // 6
 73         "T\u00F6ne",                // 7
 74         "Tofu",                     // 8
 75         "blackbirds",               // 9
 76         "Ton",                      // 10
 77         "PAT",                      // 11
 78         "blackbird",                // 12
 79         "black-bird",               // 13
 80         "pat",                      // 14
 81         // Additional tests
 82         "czar",                     // 15
 83         "churo",                    // 16

141     };
142 
143     // new table collation with rules
144     //     "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&'  "
145     // loop to TOTALTESTSET
146     private static final int[] Test3Results = {
147         23, 25, 22, 24, 12, 13,  9,  0, 17, 16,
148         26, 28, 27, 15, 18, 21, 14,  1, 11,  2,
149          3,  4,  5, 19, 20,  6,  8, 10,  7, 29
150     };
151 
152     // analogous to Japanese rules
153     //     " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- "
154     // loop to TOTALTESTSET
155     private static final int[] Test4Results = {
156         19, 22, 21, 23, 24, 25, 12, 13,  9,  0,
157         17, 16, 26, 27, 28, 15, 18, 14,  1, 11,
158          2,  3,  4,  5, 20,  6,  8, 10,  7, 29
159     };
160 

161     public void TestG7Data() {
162         for (int i = 0; i < locales.length; i++) {
163             Collator myCollation= null;
164             RuleBasedCollator tblColl1 = null;
165 
166             try {
167                 myCollation = Collator.getInstance(locales[i]);
168                 tblColl1 = new RuleBasedCollator(((RuleBasedCollator)myCollation).getRules());
169             } catch (Exception foo) {
170                 errln("Exception: " + foo.getMessage() +
171                       " Locale : " + locales[i].getDisplayName() +
172                       " getRules failed\n");
173                 continue;
174             }
175             for (int j = 0; j < FIXEDTESTSET; j++) {
176                 for (int n = j+1; n < FIXEDTESTSET; n++) {
177                     doTest(tblColl1, testCases[G7Results[i][j]],
178                            testCases[G7Results[i][n]], -1);
179                 }
180             }
181             myCollation = null;
182         }
183     }
184 
185     /*
186      * Demo Test 1 : Create a new table collation with rules "& Z < p, P"
187      */

188     public void TestDemoTest1() {
189         int j = 0;
190         final Collator myCollation = Collator.getInstance(Locale.US);
191         final String defRules = ((RuleBasedCollator)myCollation).getRules();
192         RuleBasedCollator tblColl = null;
193         String newRules = defRules + " & Z < p, P";
194 
195         try {
196             tblColl = new RuleBasedCollator(newRules);
197             for (j = 0; j < FIXEDTESTSET; j++) {
198                 for (int n = j+1; n < FIXEDTESTSET; n++) {
199                     doTest(tblColl, testCases[Test1Results[j]],
200                            testCases[Test1Results[n]], -1);
201                 }
202             }
203             tblColl = null;
204         } catch (Exception foo) {
205             errln("Exception: " + foo.getMessage() +
206                   "\nDemo Test 1 Table Collation object creation failed.");
207         }
208     }
209 
210     /*
211      * Demo Test 2 : Create a new table collation with rules
212      *     "& C < ch , cH, Ch, CH"
213      */

214     public void TestDemoTest2() {
215         final Collator myCollation = Collator.getInstance(Locale.US);
216         final String defRules = ((RuleBasedCollator)myCollation).getRules();
217         String newRules = defRules + "& C < ch , cH, Ch, CH";
218 
219         try {
220             RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
221             for (int j = 0; j < TOTALTESTSET; j++) {
222                 for (int n = j+1; n < TOTALTESTSET; n++) {
223                     doTest(tblColl, testCases[Test2Results[j]],
224                            testCases[Test2Results[n]], -1);
225                 }
226             }
227         } catch (Exception foo) {
228             errln("Exception: " + foo.getMessage() +
229                   "\nDemo Test 2 Table Collation object creation failed.\n");
230         }
231     }
232 
233     /*
234      * Demo Test 3 : Create a new table collation with rules
235      *     "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"
236      */

237     public void TestDemoTest3() {
238         final Collator myCollation = Collator.getInstance(Locale.US);
239         final String defRules = ((RuleBasedCollator)myCollation).getRules();
240         RuleBasedCollator tblColl = null;
241         String newRules = defRules + "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&";
242 
243         try {
244             tblColl = new RuleBasedCollator(newRules);
245             for (int j = 0; j < TOTALTESTSET; j++) {
246                 for (int n = j+1; n < TOTALTESTSET; n++) {
247                     doTest(tblColl, testCases[Test3Results[j]],
248                            testCases[Test3Results[n]], -1);
249                 }
250             }
251         } catch (Exception foo) {
252             errln("Exception: " + foo.getMessage() +
253                   "\nDemo Test 3 Table Collation object creation failed.");
254         }
255     }
256 
257     /*
258      * Demo Test 4 : Create a new table collation with rules
259      *     " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "
260      */

261     public void TestDemoTest4() {
262         final Collator myCollation = Collator.getInstance(Locale.US);
263         final String defRules = ((RuleBasedCollator)myCollation).getRules();
264         RuleBasedCollator tblColl = null;
265         String newRules = defRules + " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
266 
267         try {
268             tblColl = new RuleBasedCollator(newRules);
269             for (int j = 0; j < TOTALTESTSET; j++) {
270                 for (int n = j+1; n < TOTALTESTSET; n++) {
271                     doTest(tblColl, testCases[Test4Results[j]],
272                            testCases[Test4Results[n]], -1);
273                 }
274             }
275         } catch (Exception foo) {
276             errln("Exception: " + foo.getMessage() +
277                   "\nDemo Test 4 Table Collation object creation failed.");
278         }
279         tblColl = null;
280     }
281 
282     private static final int FIXEDTESTSET = 15;
283     private static final int TOTALTESTSET = 30;
284 
285     private static final Locale locales[] = {
286         Locale.US,
287         Locale.UK,
288         Locale.CANADA,
289         Locale.FRANCE,
290         Locale.CANADA_FRENCH,
291         Locale.GERMANY,
292         Locale.JAPAN,
293         Locale.ITALY
294     };
295 }

  1 /*
  2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @library /java/text/testlib
 27  * @summary test G7 Collation
 28  * @modules jdk.localedata
 29  * @run junit G7Test
 30  */
 31 /*
 32  *
 33  *
 34  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
 35  * (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
 36  *
 37  * Portions copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
 38  *
 39  *   The original version of this source code and documentation is copyrighted
 40  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
 41  * materials are provided under terms of a License Agreement between Taligent
 42  * and Sun. This technology is protected by multiple US and International
 43  * patents. This notice and attribution to Taligent may not be removed.
 44  *   Taligent is a registered trademark of Taligent, Inc.
 45  *
 46 */
 47 
 48 /**
 49  * G7 Test cases
 50  *
 51  * @author     Helena Shih
 52  */
 53 
 54 import java.text.Collator;
 55 import java.text.RuleBasedCollator;
 56 import java.util.Locale;
 57 
 58 import org.junit.jupiter.api.Test;
 59 
 60 import static org.junit.jupiter.api.Assertions.fail;
 61 
 62 // G7 test program for printing out test results
 63 
 64 public class G7Test {
 65 
 66     private static final String testCases[] = {
 67         "black-birds",              // 0
 68         "Pat",                      // 1
 69         "p\u00E9ch\u00E9",          // 2
 70         "p\u00EAche",               // 3
 71         "p\u00E9cher",              // 4
 72         "p\u00EAcher",              // 5
 73         "Tod",                      // 6
 74         "T\u00F6ne",                // 7
 75         "Tofu",                     // 8
 76         "blackbirds",               // 9
 77         "Ton",                      // 10
 78         "PAT",                      // 11
 79         "blackbird",                // 12
 80         "black-bird",               // 13
 81         "pat",                      // 14
 82         // Additional tests
 83         "czar",                     // 15
 84         "churo",                    // 16

142     };
143 
144     // new table collation with rules
145     //     "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&'  "
146     // loop to TOTALTESTSET
147     private static final int[] Test3Results = {
148         23, 25, 22, 24, 12, 13,  9,  0, 17, 16,
149         26, 28, 27, 15, 18, 21, 14,  1, 11,  2,
150          3,  4,  5, 19, 20,  6,  8, 10,  7, 29
151     };
152 
153     // analogous to Japanese rules
154     //     " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- "
155     // loop to TOTALTESTSET
156     private static final int[] Test4Results = {
157         19, 22, 21, 23, 24, 25, 12, 13,  9,  0,
158         17, 16, 26, 27, 28, 15, 18, 14,  1, 11,
159          2,  3,  4,  5, 20,  6,  8, 10,  7, 29
160     };
161 
162     @Test
163     public void TestG7Data() {
164         for (int i = 0; i < locales.length; i++) {
165             Collator myCollation= null;
166             RuleBasedCollator tblColl1 = null;
167 
168             try {
169                 myCollation = Collator.getInstance(locales[i]);
170                 tblColl1 = new RuleBasedCollator(((RuleBasedCollator)myCollation).getRules());
171             } catch (Exception foo) {
172                 fail("Exception: " + foo.getMessage() +
173                       " Locale : " + locales[i].getDisplayName() +
174                       " getRules failed\n");
175                 continue;
176             }
177             for (int j = 0; j < FIXEDTESTSET; j++) {
178                 for (int n = j+1; n < FIXEDTESTSET; n++) {
179                     TestUtils.doCollatorTest(tblColl1, testCases[G7Results[i][j]],
180                            testCases[G7Results[i][n]], -1);
181                 }
182             }
183             myCollation = null;
184         }
185     }
186 
187     /*
188      * Demo Test 1 : Create a new table collation with rules "& Z < p, P"
189      */
190     @Test
191     public void TestDemoTest1() {
192         int j = 0;
193         final Collator myCollation = Collator.getInstance(Locale.US);
194         final String defRules = ((RuleBasedCollator)myCollation).getRules();
195         RuleBasedCollator tblColl = null;
196         String newRules = defRules + " & Z < p, P";
197 
198         try {
199             tblColl = new RuleBasedCollator(newRules);
200             for (j = 0; j < FIXEDTESTSET; j++) {
201                 for (int n = j+1; n < FIXEDTESTSET; n++) {
202                     TestUtils.doCollatorTest(tblColl, testCases[Test1Results[j]],
203                            testCases[Test1Results[n]], -1);
204                 }
205             }
206             tblColl = null;
207         } catch (Exception foo) {
208             fail("Exception: " + foo.getMessage() +
209                   "\nDemo Test 1 Table Collation object creation failed.");
210         }
211     }
212 
213     /*
214      * Demo Test 2 : Create a new table collation with rules
215      *     "& C < ch , cH, Ch, CH"
216      */
217     @Test
218     public void TestDemoTest2() {
219         final Collator myCollation = Collator.getInstance(Locale.US);
220         final String defRules = ((RuleBasedCollator)myCollation).getRules();
221         String newRules = defRules + "& C < ch , cH, Ch, CH";
222 
223         try {
224             RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
225             for (int j = 0; j < TOTALTESTSET; j++) {
226                 for (int n = j+1; n < TOTALTESTSET; n++) {
227                     TestUtils.doCollatorTest(tblColl, testCases[Test2Results[j]],
228                            testCases[Test2Results[n]], -1);
229                 }
230             }
231         } catch (Exception foo) {
232             fail("Exception: " + foo.getMessage() +
233                   "\nDemo Test 2 Table Collation object creation failed.\n");
234         }
235     }
236 
237     /*
238      * Demo Test 3 : Create a new table collation with rules
239      *     "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"
240      */
241     @Test
242     public void TestDemoTest3() {
243         final Collator myCollation = Collator.getInstance(Locale.US);
244         final String defRules = ((RuleBasedCollator)myCollation).getRules();
245         RuleBasedCollator tblColl = null;
246         String newRules = defRules + "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&";
247 
248         try {
249             tblColl = new RuleBasedCollator(newRules);
250             for (int j = 0; j < TOTALTESTSET; j++) {
251                 for (int n = j+1; n < TOTALTESTSET; n++) {
252                     TestUtils.doCollatorTest(tblColl, testCases[Test3Results[j]],
253                            testCases[Test3Results[n]], -1);
254                 }
255             }
256         } catch (Exception foo) {
257             fail("Exception: " + foo.getMessage() +
258                   "\nDemo Test 3 Table Collation object creation failed.");
259         }
260     }
261 
262     /*
263      * Demo Test 4 : Create a new table collation with rules
264      *     " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "
265      */
266     @Test
267     public void TestDemoTest4() {
268         final Collator myCollation = Collator.getInstance(Locale.US);
269         final String defRules = ((RuleBasedCollator)myCollation).getRules();
270         RuleBasedCollator tblColl = null;
271         String newRules = defRules + " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
272 
273         try {
274             tblColl = new RuleBasedCollator(newRules);
275             for (int j = 0; j < TOTALTESTSET; j++) {
276                 for (int n = j+1; n < TOTALTESTSET; n++) {
277                     TestUtils.doCollatorTest(tblColl, testCases[Test4Results[j]],
278                            testCases[Test4Results[n]], -1);
279                 }
280             }
281         } catch (Exception foo) {
282             fail("Exception: " + foo.getMessage() +
283                   "\nDemo Test 4 Table Collation object creation failed.");
284         }
285         tblColl = null;
286     }
287 
288     private static final int FIXEDTESTSET = 15;
289     private static final int TOTALTESTSET = 30;
290 
291     private static final Locale locales[] = {
292         Locale.US,
293         Locale.UK,
294         Locale.CANADA,
295         Locale.FRANCE,
296         Locale.CANADA_FRENCH,
297         Locale.GERMANY,
298         Locale.JAPAN,
299         Locale.ITALY
300     };
301 }
< prev index next >