--- /dev/null 2015-01-05 10:07:41.260039832 -0800 +++ new/test/sun/awt/font/TestEncoders.java 2015-02-19 16:13:16.553548271 -0800 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * This does not have a test tag since it uses sun API and is + * platform-specific. + * Manually compile and test on a Unix platform with access to + * sun.* packages enabled + * @bug 8035302 + * + * @summary This verifies encoders used in X11 font code work as + * they used to when using sun.nio internals. + * + */ + +import java.nio.*; +import java.nio.charset.*; +import sun.awt.motif.*; + +public class TestEncoders { + + public static void main(String args[]) { + + X11JIS0201 xjis201 = new X11JIS0201(); + char[] jis201chars = { '\u00a5', '\u203e', '\uff61', '\uff9f' }; + byte[] jisenc = { (byte)92, (byte)126, (byte)161, (byte)223 }; + test(xjis201, jis201chars, jisenc, true); + char[] non_jis201chars = { 'a', 'b', '\u201c' }; + test(xjis201, non_jis201chars, null, true); + + X11GBK x11gbk = new X11GBK(); + char[] gbkChars = { '\u3041', '\u30a1' }; + byte[] x11gbk_bytes = { (byte)164, (byte)161, (byte)165, (byte)161 }; + test(x11gbk, gbkChars, x11gbk_bytes, true); + char[] non_gbkChars = { '\u3040', '\u30a0' }; + test(x11gbk, non_gbkChars, null, true); + + X11GB2312 x11gb2312 = new X11GB2312(); + char[] gb2312Chars = { '\u3041', '\u30a1' }; + byte[] x11gb2312_bytes = {(byte)36, (byte)33, (byte)37, (byte)33}; + test(x11gb2312, gb2312Chars, x11gb2312_bytes, true); + + X11KSC5601 x11ksc5601 = new X11KSC5601(); + char[] ksc5601Chars = { '\uAC00', '\uD79D' }; + // encodes as 0x3021, 0x487e + byte[] ksc5601_bytes = { (byte)48, (byte)33, (byte)72, (byte)126 }; + test(x11ksc5601, ksc5601Chars, ksc5601_bytes, true); + } + + static void test(Charset cs, char[] chars, byte[] expected, boolean exc) { + try { + CharBuffer cb = CharBuffer.wrap(chars); + CharsetEncoder enc = cs.newEncoder(); + enc.onMalformedInput(CodingErrorAction.REPORT); + enc.onUnmappableCharacter(CodingErrorAction.REPORT); + ByteBuffer bb = enc.encode(cb); + byte[] bytes = bb.array(); + for (int i=0;i