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 4740757 27 * @summary Confirm line-breaking behavior of Hangul 28 */ 29 30 package test.java.text.BreakIterator; 31 32 import java.text.*; 33 import java.util.*; 34 35 public class Bug4740757 { 36 37 private static boolean err = false; 38 main(String[] args)39 public static void main(String[] args) { 40 Locale defaultLocale = Locale.getDefault(); 41 if (defaultLocale.getLanguage().equals("th")) { 42 Locale.setDefault(Locale.KOREA); 43 test4740757(); 44 Locale.setDefault(defaultLocale); 45 } else { 46 test4740757(); 47 } 48 49 if (err) { 50 throw new RuntimeException("Incorrect Line-breaking"); 51 } 52 } 53 test4740757()54 private static void test4740757() { 55 String source = "\uc548\ub155\ud558\uc138\uc694? \uc88b\uc740 \uc544\uce68, \uc5ec\ubcf4\uc138\uc694! \uc548\ub155. End."; 56 String expected = "\uc548/\ub155/\ud558/\uc138/\uc694? /\uc88b/\uc740 /\uc544/\uce68, /\uc5ec/\ubcf4/\uc138/\uc694! /\uc548/\ub155. /End./"; 57 58 BreakIterator bi = BreakIterator.getLineInstance(Locale.KOREAN); 59 bi.setText(source); 60 int start = bi.first(); 61 int end = bi.next(); 62 StringBuilder sb = new StringBuilder(); 63 64 for (; end != BreakIterator.DONE; start = end, end = bi.next()) { 65 sb.append(source.substring(start,end)); 66 sb.append('/'); 67 } 68 69 if (!expected.equals(sb.toString())) { 70 System.err.println("Failed: Hangul line-breaking failed." + 71 "\n\tExpected: " + expected + 72 "\n\tGot: " + sb + 73 "\nin " + Locale.getDefault() + " locale."); 74 err = true; 75 } 76 } 77 78 } 79