/* * Copyright (c) 2003, 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 4691554 6221056 6380723 6404504 6419565 6529796 @summary Test the supported New I/O coders @modules jdk.charsets
*/
// Stateful b2c files have leading and trailing // shift bytes for each mapping. However when // block encoded the output will consist of a single // leadByte followed by the raw DBCS byte values and // a final trail byte. The state variable shiftHackDBCS // which is true for stateful DBCS encodings is used // to conditionally strip away per-mapping shift bytes // from the comparison of expected versus actual encoded // byte values. This hack can be eliminated in Mustang // when sun.io converters and their associated tests are // removed.
boolean boundaryBytes = false; int bytesPC = bytesPerChar;
if (shiftHackDBCS && bytesPerChar==4) {
bytesPC = 2;
boundaryBytes = true; if ((out.get()) != (byte)0x0e) {
log.println("Missing lead byte"); return(false);
}
}
byte[] rbs = newbyte[bytesPC]; byte[] obs = newbyte[bytesPC]; int e = 0; while (refChars.hasRemaining()) { int cp = getCodePoint(refChars); // Skip lead shift ref byte for stateful encoding tests if (shiftHackDBCS && bytesPC == 2)
refBytes.get();
refBytes.get(rbs);
out.get(obs); boolean eq = true; for (int i = 0; i < bytesPC; i++)
eq &= rbs[i] == obs[i]; if (!eq) {
log.println(" Error: "
+ printCodePoint(cp)
+ " --> "
+ printBytes(obs)
+ ", expected "
+ printBytes(rbs)); if (++e >= MAXERRS) {
log.println(" Too many errors, giving up"); break;
}
} if (verbose) {
log.println(" "
+ printCodePoint(cp)
+ " --> "
+ printBytes(rbs));
}
// For stateful encodings ignore/exclude per-mapping // trail bytes from byte comparison if (shiftHackDBCS && bytesPC == 2)
refBytes.get();
}
if (shiftHackDBCS && boundaryBytes) { if ((out.get()) != (byte)0x0f) {
log.println("Missing trail byte"); return(false);
}
}
if (e == 0 && (refBytes.hasRemaining() || out.hasRemaining())) { // Paranoia: Didn't consume everything thrownew IllegalStateException();
}
refBytes.rewind();
refChars.rewind(); return (e == 0);
}
// Find the test for the given bytes/char value, // expanding the test array if needed // private Test testFor(int bpc) { if (bpc > maxBytesPerChar) {
Test[] ts = new Test[bpc];
System.arraycopy(tests, 0, ts, 0, maxBytesPerChar); for (int i = maxBytesPerChar; i < bpc; i++)
ts[i] = new Test(i + 1);
tests = ts;
maxBytesPerChar = bpc;
} return tests[bpc - 1];
}
// Compute the name of the test file for the given encoding and mode. If // the file exists then return its name, otherwise return null. // private File testFile(String encoding, int mode) {
File f = new File(testRootDir, encoding + extension[mode]); if (!f.exists()) returnnull; return f;
}
// Parse the given b2c file and load up the required test objects // privatevoid loadTests(File f) throws Exception
{
clearTests();
FileInputStream in = new FileInputStream(f); try {
Parser p = new Parser(in);
Entry e = new Entry();
while ((e = (Entry)p.next(e)) != null) { if (e.cp2 != 0) continue; // skip composite (base+cc) for now byte[] bs = e.bb; char[] cc = Character.toChars(e.cp);
testFor(bs.length).put(bs, cc);
}
shiftHackDBCS = p.isStateful();
} finally {
in.close();
}
}
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.