/* * Copyright (c) 2008, 2011, 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.
*/
/* @test * @bug 6379808 8166339 * @summary Check all Cp933 SBCS characters are not supported in Cp834 * @modules jdk.charsets
*/
publicclass TestCp834_SBCS { publicstaticvoid main(String args[]) throws Exception { // The correctness of 1:1 mapping is Coverted by CoderTest.java // and TestConv.java, we only need to verify that SBCS characters // are not supported by this charset.
CharsetEncoder enc834 = Charset.forName("Cp834")
.newEncoder()
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.onMalformedInput(CodingErrorAction.REPLACE);
CharsetDecoder dec933 = Charset.forName("Cp933")
.newDecoder()
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.onMalformedInput(CodingErrorAction.REPLACE); byte[] ba = newbyte[1]; byte[] ba2 = newbyte[2];
ByteBuffer dbb = ByteBuffer.allocateDirect(10); char[] ca = newchar[1]; char c; for (int i = 0; i <= 0xff; i++) { if (i != 0xe && i != 0xf) { // no SI/SO
ba[0] = (byte)i;
CharBuffer cb = dec933.decode(ByteBuffer.wrap(ba)); if ((c = cb.get()) != '\ufffd') { // OK, this is a SBCS character in Cp933 if (dec834.decode(ByteBuffer.wrap(ba)).get() != '\ufffd') thrownew RuntimeException("SBCS is supported in IBM834 decoder");
if (enc834.canEncode(c)) thrownew RuntimeException("SBCS can be encoded in IBM834 encoder");
ca[0] = c;
ByteBuffer bb = enc834.encode(CharBuffer.wrap(ca)); if (bb.get() != (byte)0xfe || bb.get() != (byte)0xfe) thrownew RuntimeException("SBCS is supported in IBM834 encoder");
}
}
}
// 8166339: cp834 should handle unmappable bytes as dobule-byte pair. if (! new String("\ufffd".getBytes("cp834"), "cp834").equals("\ufffd")) { thrownew RuntimeException("u+fffd roundtrip failed");
}
if (! new String("a".getBytes("cp834"), "cp834").equals("\ufffd") ||
! new String(newbyte[] { 0x41, 0x40}, "cp834").equals("\ufffd")) { thrownew RuntimeException("decoding unmappable don't return u+fffd");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.