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 = { 59 "ABCD", 60 "ABCD", 61 "A\ud800\udc00CD", 62 "WXYZ", 63 "WXYZ", 64 "AFEM", 65 "FGM", 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 }