1 /* 2 * Copyright (c) 2011, 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 * @bug 6513074 27 * @summary Confirm that JIS X 0213 characters are processed in line-breaking properly. 28 */ 29 30 import java.text.*; 31 import java.util.*; 32 33 public class Bug6513074 { 34 35 private static final String[][] source = { 36 {"\ufa30\ufa31 \ufa69\ufa6a", 37 "JIS X 0213 compatibility additions (\\uFA30-\\uFA6A)"}, 38 }; 39 40 private static final String[] expected_line = { 41 "\ufa30/\ufa31 /\ufa69/\ufa6a/", 42 }; 43 44 private static final String[] expected_word = { 45 "\ufa30\ufa31/ /\ufa69\ufa6a/", 46 }; 47 48 private static final String[] expected_char = { 49 "\ufa30/\ufa31/ /\ufa69/\ufa6a/", 50 }; 51 52 53 private static boolean err = false; 54 55 public static void main(String[] args) { 56 Locale defaultLocale = Locale.getDefault(); 57 if (defaultLocale.getLanguage().equals("th")) { 58 Locale.setDefault(Locale.JAPAN); 59 test6513074(); 60 Locale.setDefault(defaultLocale); 61 } else { 62 test6513074(); 63 } 64 65 if (err) { 66 throw new RuntimeException("Failed: Incorrect Text-breaking."); 67 } 68 } 69 70 71 private static void test6513074() { 72 BreakIterator bi = BreakIterator.getLineInstance(Locale.JAPAN); 73 for (int i = 0; i < source.length; i++) { 74 testBreakIterator(bi, "Line", source[i][0], expected_line[i], source[i][1]); 75 } 76 77 bi = BreakIterator.getWordInstance(Locale.JAPAN); 78 for (int i = 0; i < source.length; i++) { 79 testBreakIterator(bi, "Word", source[i][0], expected_word[i], source[i][1]); 80 } 81 82 bi = BreakIterator.getCharacterInstance(Locale.JAPAN); 83 for (int i = 0; i < source.length; i++) { 84 testBreakIterator(bi, "Character", source[i][0], expected_char[i], source[i][1]); 85 } 86 } 87 88 private static void testBreakIterator(BreakIterator bi, 89 String type, 90 String source, 91 String expected, 92 String description) { 93 bi.setText(source); 94 int start = bi.first(); 95 int end = bi.next(); 96 StringBuilder sb = new StringBuilder(); 97 98 for (; end != BreakIterator.DONE; start = end, end = bi.next()) { 99 sb.append(source.substring(start,end)); 100 sb.append('/'); 101 } 102 103 if (!expected.equals(sb.toString())) { 104 System.err.println("Failed: Incorrect " + type + "-breaking for " + 105 description + 106 "\n\tExpected: " + toString(expected) + 107 "\n\tGot: " + toString(sb.toString())); 108 err = true; 109 } 110 } 111 112 private static String toString(String s) { 113 StringBuilder sb = new StringBuilder(); 114 115 for (int i = 0; i < s.length(); i++) { 116 sb.append(" 0x" + Integer.toHexString(s.charAt(i))); 117 } 118 119 return sb.toString(); 120 } 121 122 }