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