Path: blob/master/test/jdk/java/text/BreakIterator/Bug6513074.java
41152 views
/*1* Copyright (c) 2011, 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* @bug 651307426* @summary Confirm that JIS X 0213 characters are processed in line-breaking properly.27*/2829import java.text.*;30import java.util.*;3132public class Bug6513074 {3334private static final String[][] source = {35{"\ufa30\ufa31 \ufa69\ufa6a",36"JIS X 0213 compatibility additions (\\uFA30-\\uFA6A)"},37};3839private static final String[] expected_line = {40"\ufa30/\ufa31 /\ufa69/\ufa6a/",41};4243private static final String[] expected_word = {44"\ufa30\ufa31/ /\ufa69\ufa6a/",45};4647private static final String[] expected_char = {48"\ufa30/\ufa31/ /\ufa69/\ufa6a/",49};505152private static boolean err = false;5354public static void main(String[] args) {55Locale defaultLocale = Locale.getDefault();56if (defaultLocale.getLanguage().equals("th")) {57Locale.setDefault(Locale.JAPAN);58test6513074();59Locale.setDefault(defaultLocale);60} else {61test6513074();62}6364if (err) {65throw new RuntimeException("Failed: Incorrect Text-breaking.");66}67}686970private static void test6513074() {71BreakIterator bi = BreakIterator.getLineInstance(Locale.JAPAN);72for (int i = 0; i < source.length; i++) {73testBreakIterator(bi, "Line", source[i][0], expected_line[i], source[i][1]);74}7576bi = BreakIterator.getWordInstance(Locale.JAPAN);77for (int i = 0; i < source.length; i++) {78testBreakIterator(bi, "Word", source[i][0], expected_word[i], source[i][1]);79}8081bi = BreakIterator.getCharacterInstance(Locale.JAPAN);82for (int i = 0; i < source.length; i++) {83testBreakIterator(bi, "Character", source[i][0], expected_char[i], source[i][1]);84}85}8687private static void testBreakIterator(BreakIterator bi,88String type,89String source,90String expected,91String description) {92bi.setText(source);93int start = bi.first();94int end = bi.next();95StringBuilder sb = new StringBuilder();9697for (; end != BreakIterator.DONE; start = end, end = bi.next()) {98sb.append(source.substring(start,end));99sb.append('/');100}101102if (!expected.equals(sb.toString())) {103System.err.println("Failed: Incorrect " + type + "-breaking for " +104description +105"\n\tExpected: " + toString(expected) +106"\n\tGot: " + toString(sb.toString()));107err = true;108}109}110111private static String toString(String s) {112StringBuilder sb = new StringBuilder();113114for (int i = 0; i < s.length(); i++) {115sb.append(" 0x" + Integer.toHexString(s.charAt(i)));116}117118return sb.toString();119}120121}122123124