Path: blob/master/test/jdk/sun/nio/cs/EucJpLinux0212.java
41149 views
/*1* Copyright (c) 2008, 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 635002126* @summary Consistency checks when input buffer contains JISX0212 characters27* @author Martin Buchholz28*/2930import java.io.*;31import java.util.*;32import java.nio.*;33import java.nio.charset.*;3435public class EucJpLinux0212 {36private static void equal(CharBuffer b1, CharBuffer b2) {37equal(b1.position(), b2.position());38equal(b1.limit(), b2.limit());39System.out.printf("positions=%d %d%n", b1.position(), b2.position());40System.out.printf("limits=%d %d%n", b1.limit(), b2.limit());41for (int i = b1.position(); i < b1.limit(); i++)42equal((int)b1.get(i), (int)b2.get(i));43}4445private static void realMain(String[] args) throws Throwable {46List<ByteBuffer> bbs = Arrays.asList(47ByteBuffer.allocate(10),48ByteBuffer.allocateDirect(10));49List<CharBuffer> cbs = new ArrayList<CharBuffer>();5051for (ByteBuffer bb : bbs) {52bb.put(new byte[]{ (byte)0x8f, 0x01, 0x02,53(byte)0xa1, (byte)0xc0,540x02, 0x03});55bb.flip();56CharsetDecoder decoder = Charset.forName("EUC_JP_LINUX").newDecoder();57decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);58CharBuffer cb = decoder.decode(bb);59cbs.add(cb);60}61equal(cbs.get(0), cbs.get(1));62}6364//--------------------- Infrastructure ---------------------------65static volatile int passed = 0, failed = 0;66static void pass() {passed++;}67static void fail() {failed++; Thread.dumpStack();}68static void fail(String msg) {System.out.println(msg); fail();}69static void unexpected(Throwable t) {failed++; t.printStackTrace();}70static void check(boolean cond) {if (cond) pass(); else fail();}71static void equal(Object x, Object y) {72if (x == null ? y == null : x.equals(y)) pass();73else fail(x + " not equal to " + y);}74public static void main(String[] args) throws Throwable {75try {realMain(args);} catch (Throwable t) {unexpected(t);}76System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);77if (failed > 0) throw new AssertionError("Some tests failed");}78}798081