< prev index next >

test/jdk/java/text/Collator/SurrogatesTest.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 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 Supplementary Character Collation

 28  */
 29 
 30 import java.text.Collator;
 31 import java.text.RuleBasedCollator;
 32 
 33 // Quick dummy program for printing out test results
 34 public class SurrogatesTest extends CollatorTest {
 35 
 36     public static void main(String[] args) throws Exception {
 37         new SurrogatesTest().run(args);
 38     }

 39 
 40     /*
 41      * Data for TestPrimary()
 42      */
 43     private static final String[] primarySourceData = {
 44         "A\ud800\udc04BCD"
 45     };
 46 
 47     private static final String[] primaryTargetData = {
 48         "A\ud800\udc05BCD"
 49     };
 50 
 51     private static final int[] primaryResults = {
 52          0
 53     };
 54 
 55     /*
 56      * Data for TestTertiary()
 57      */
 58     private static final String[] tertiarySourceData = {

 66         "BB",
 67         "BB"
 68     };
 69 
 70     private static final String[] tertiaryTargetData = {
 71         "A\ud800\udc00CD",
 72         "AB\ud800\udc00D",
 73         "A\ud800\udc01CD",
 74         "W\ud800\udc0aYZ",
 75         "W\ud800\udc0bYZ",
 76         "A\ud800\udc08M",
 77         "\ud800\udc08M",
 78         "\ud800\udc04\ud800\udc02",
 79         "\ud800\udc04\ud800\udc05"
 80     };
 81 
 82     private static final int[] tertiaryResults = {
 83         -1,  1,  1,  1, -1, -1, -1, -1,  1
 84     };
 85 

 86     public void TestPrimary() {
 87         doTest(myCollation, Collator.PRIMARY,
 88                primarySourceData, primaryTargetData, primaryResults);
 89     }
 90 

 91     public void TestTertiary() {
 92         doTest(myCollation, Collator.TERTIARY,
 93                tertiarySourceData, tertiaryTargetData, tertiaryResults);
 94     }
 95 
 96     private Collator getCollator() {
 97         RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
 98         String rule = base.getRules();
 99         try {
100             return new RuleBasedCollator(rule
101                                      + "&B < \ud800\udc01 < \ud800\udc00"
102                                      + ", \ud800\udc02, \ud800\udc03"
103                                      + "; \ud800\udc04, \ud800\udc05"
104                                      + "< \ud800\udc06 < \ud800\udc07"
105                                      + "&FE < \ud800\udc08"
106                                      + "&PE, \ud800\udc09"
107                                      + "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
108                                      + "&\ud800\udc0a < x, X"
109                                      + "&A < \ud800\udc04\ud800\udc05");
110         } catch (Exception e) {
111             errln("Failed to create new RulebasedCollator object");
112             return null;
113         }
114     }
115 
116     private Collator myCollation = getCollator();
117 }

  1 /*
  2  * Copyright (c) 2003, 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 Supplementary Character Collation
 28  * @run junit SurrogatesTest
 29  */
 30 
 31 import java.text.Collator;
 32 import java.text.RuleBasedCollator;
 33 
 34 import org.junit.jupiter.api.Test;

 35 
 36 import static org.junit.jupiter.api.Assertions.fail;
 37 
 38 // Quick dummy program for printing out test results
 39 public class SurrogatesTest {
 40 
 41     /*
 42      * Data for TestPrimary()
 43      */
 44     private static final String[] primarySourceData = {
 45         "A\ud800\udc04BCD"
 46     };
 47 
 48     private static final String[] primaryTargetData = {
 49         "A\ud800\udc05BCD"
 50     };
 51 
 52     private static final int[] primaryResults = {
 53          0
 54     };
 55 
 56     /*
 57      * Data for TestTertiary()
 58      */
 59     private static final String[] tertiarySourceData = {

 67         "BB",
 68         "BB"
 69     };
 70 
 71     private static final String[] tertiaryTargetData = {
 72         "A\ud800\udc00CD",
 73         "AB\ud800\udc00D",
 74         "A\ud800\udc01CD",
 75         "W\ud800\udc0aYZ",
 76         "W\ud800\udc0bYZ",
 77         "A\ud800\udc08M",
 78         "\ud800\udc08M",
 79         "\ud800\udc04\ud800\udc02",
 80         "\ud800\udc04\ud800\udc05"
 81     };
 82 
 83     private static final int[] tertiaryResults = {
 84         -1,  1,  1,  1, -1, -1, -1, -1,  1
 85     };
 86 
 87     @Test
 88     public void TestPrimary() {
 89         TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
 90                primarySourceData, primaryTargetData, primaryResults);
 91     }
 92 
 93     @Test
 94     public void TestTertiary() {
 95         TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
 96                tertiarySourceData, tertiaryTargetData, tertiaryResults);
 97     }
 98 
 99     private Collator getCollator() {
100         RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
101         String rule = base.getRules();
102         try {
103             return new RuleBasedCollator(rule
104                                      + "&B < \ud800\udc01 < \ud800\udc00"
105                                      + ", \ud800\udc02, \ud800\udc03"
106                                      + "; \ud800\udc04, \ud800\udc05"
107                                      + "< \ud800\udc06 < \ud800\udc07"
108                                      + "&FE < \ud800\udc08"
109                                      + "&PE, \ud800\udc09"
110                                      + "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
111                                      + "&\ud800\udc0a < x, X"
112                                      + "&A < \ud800\udc04\ud800\udc05");
113         } catch (Exception e) {
114             fail("Failed to create new RulebasedCollator object");
115             return null;
116         }
117     }
118 
119     private Collator myCollation = getCollator();
120 }
< prev index next >