Path: blob/master/test/jdk/java/text/Collator/SurrogatesTest.java
41149 views
/*1* Copyright (c) 2003, 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 Supplementary Character Collation27*/2829import java.text.Collator;30import java.text.RuleBasedCollator;3132// Quick dummy program for printing out test results33public class SurrogatesTest extends CollatorTest {3435public static void main(String[] args) throws Exception {36new SurrogatesTest().run(args);37}3839/*40* Data for TestPrimary()41*/42private static final String[] primarySourceData = {43"A\ud800\udc04BCD"44};4546private static final String[] primaryTargetData = {47"A\ud800\udc05BCD"48};4950private static final int[] primaryResults = {51052};5354/*55* Data for TestTertiary()56*/57private static final String[] tertiarySourceData = {58"ABCD",59"ABCD",60"A\ud800\udc00CD",61"WXYZ",62"WXYZ",63"AFEM",64"FGM",65"BB",66"BB"67};6869private static final String[] tertiaryTargetData = {70"A\ud800\udc00CD",71"AB\ud800\udc00D",72"A\ud800\udc01CD",73"W\ud800\udc0aYZ",74"W\ud800\udc0bYZ",75"A\ud800\udc08M",76"\ud800\udc08M",77"\ud800\udc04\ud800\udc02",78"\ud800\udc04\ud800\udc05"79};8081private static final int[] tertiaryResults = {82-1, 1, 1, 1, -1, -1, -1, -1, 183};8485public void TestPrimary() {86doTest(myCollation, Collator.PRIMARY,87primarySourceData, primaryTargetData, primaryResults);88}8990public void TestTertiary() {91doTest(myCollation, Collator.TERTIARY,92tertiarySourceData, tertiaryTargetData, tertiaryResults);93}9495private Collator getCollator() {96RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();97String rule = base.getRules();98try {99return new RuleBasedCollator(rule100+ "&B < \ud800\udc01 < \ud800\udc00"101+ ", \ud800\udc02, \ud800\udc03"102+ "; \ud800\udc04, \ud800\udc05"103+ "< \ud800\udc06 < \ud800\udc07"104+ "&FE < \ud800\udc08"105+ "&PE, \ud800\udc09"106+ "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"107+ "&\ud800\udc0a < x, X"108+ "&A < \ud800\udc04\ud800\udc05");109} catch (Exception e) {110errln("Failed to create new RulebasedCollator object");111return null;112}113}114115private Collator myCollation = getCollator();116}117118119