/* * Copyright (c) 2008, 2020, 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 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466 * 8212794 8220281 8235834 * @summary Check if the problems reported in above bugs have been fixed * @modules jdk.charsets
*/
privatestaticvoid bug6569191 () throws Exception { byte[] bs = newbyte[] { (byte)0x81, (byte)0xad, // fffd ff6d
(byte)0x81, (byte)0xae, // fffd ff6e
(byte)0x81, (byte)0xaf, // fffd ff6f
(byte)0x81, (byte)0xb0, // fffd ff70
(byte)0x85, (byte)0x81, // fffd ->
(byte)0x85, (byte)0x87, // 2266 ->
(byte)0x85, (byte)0xe0, // 32a4 ->
(byte)0x85, (byte)0xf0 };// 7165 fffd
String s = new String(bs, "Cp943"); // see DoubleByte for how the unmappables are handled if (!"\ufffd\uff6d\ufffd\uff6e\ufffd\uff6f\ufffd\uff70\ufffd\u2266\u32a4\u7165\ufffd"
.equals(s)) thrownew Exception("Cp943 failed");
}
privatestaticvoid bug6577466 () throws Exception { for (int c = Character.MIN_VALUE; c <= Character.MAX_VALUE; c++){ if (!Character.isDefined((char)c)) continue;
String s = String.valueOf((char)c); byte[] bb = null;
bb = s.getBytes("x-IBM970");
}
}
privatestaticvoid bug8213618 () throws Exception {
String cs = "x-IBM970"; byte[] ba = newbyte[]{(byte)0xA2,(byte)0xC1};
String s = "\u25C9"; if (!(new String(ba, cs)).equals(s)) thrownew Exception("Cp970 failed"); if (!Arrays.equals(ba, s.getBytes(cs))) thrownew Exception("Cp970 failed");
ba = newbyte[]{0x3f,0x3f,0x3f}; if (!Arrays.equals(ba, "\u6950\u84f1\ucf7f".getBytes(cs))) thrownew Exception("Cp970 failed");
}
privatestaticvoid bug8202329() throws Exception {
String original = "\\\u007E\u00A5\u203E"; // [backslash][tilde][yen][overscore] byte[] expectedBytes; // bytes after conversion
String expectedStringfromBytes; // String constructed from bytes
Charset charset; // charset used for conversion
ByteBuffer bb; // Buffer that holds encoded bytes byte[] ba; // byte array that holds encoded bytes
CharBuffer cb; // Buffer that holds decoded chars
// Test IBM943, where \ and ~ are encoded to unmappable i.e., 0x3f // and [yen] and [overscore] are encoded to 0x5c and 0x7e
charset = Charset.forName("IBM943");
expectedBytes = newbyte[] {0x3f, 0x3f, 0x5c, 0x7e};
expectedStringfromBytes = "??\u00A5\u203E";
bb = charset.encode(original);
ba = newbyte[bb.remaining()];
bb.get(ba, 0, ba.length); if(!Arrays.equals(ba, expectedBytes)) { thrownew Exception("IBM943 failed to encode");
}
cb = charset.decode(ByteBuffer.wrap(expectedBytes)); if(!cb.toString().equals(expectedStringfromBytes)) { thrownew Exception("IBM943 failed to decode");
}
// Test IBM943C, where \ and ~ are encoded to 0x5c and 0x7e // and [yen] and [overscore] are encoded to 0x5c and 0x7e
charset = Charset.forName("IBM943C");
expectedBytes = newbyte[] {0x5c, 0x7e, 0x5c, 0x7e};
expectedStringfromBytes = "\\~\\~";
bb = charset.encode(original);
ba = newbyte[bb.remaining()];
bb.get(ba, 0, ba.length); if(!Arrays.equals(ba, expectedBytes)) { thrownew Exception("IBM943C failed to encode");
}
cb = charset.decode(ByteBuffer.wrap(expectedBytes)); if(!cb.toString().equals(expectedStringfromBytes)) { thrownew Exception("IBM943C failed to decode");
}
}
privatestaticvoid bug8235834 () throws Exception { // 8235834 affects IBM-943 and IBM-943C encoder. // The decoded results of the corresponding characters of IBM-943 // and IBM-943C is the same. for (String csName : new String[] {"x-IBM943", "x-IBM943C"}) {
Charset cs = Charset.forName(csName); if (!Arrays.equals(byteIBM943c2b, strIBM943c2b1.getBytes(cs))) { thrownew Exception(csName+" failed to encode");
} if (!strIBM943c2b2.equals(new String(byteIBM943c2b, cs))) { thrownew Exception(csName+" failed to round-trip conversion");
}
}
}
publicstaticvoid main (String[] args) throws Exception {
bug6577466(); // need to be tested before any other IBM949C test case
bug6639450();
bug6371437();
bug6371422();
bug6371416();
bug6371619();
bug6371431();
bug6569191();
bug8202329();
bug8212794();
bug8213618();
bug8220281();
bug8235834();
}
}
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.