/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4831163 5053096 5056440
* @summary NIO charset basic verification of JISAutodetect decoder
* @author Martin Buchholz
*/
public class NIOJISAutoDetectTest {
failures++;
}
if (!cond) {
new Exception().printStackTrace();
}
}
(byte)0xcf, (byte)0xb2});
}
(byte)0xa4, (byte)0xe9});
}
//----------------------------------------------------------------
// Test special public methods of CharsetDecoder while we're here
//----------------------------------------------------------------
try {
fail("no IllegalStateException");
} catch (IllegalStateException e) {}
}
//----------------------------------------------------------------
// Used to throw BufferOverflowException
//----------------------------------------------------------------
//----------------------------------------------------------------
// InputStreamReader(...JISAutoDetect) used to infloop
//----------------------------------------------------------------
{
// used to return "ABCD" on second and subsequent reads
}
//----------------------------------------------------------------
// Check all Japanese chars for sanity
//----------------------------------------------------------------
int cnt2022 = 0;
int cnteucj = 0;
int cntsjis = 0;
int cntBAD = 0;
for (char c = '\u0000'; c < '\uffff'; c++) {
if (c == '\u001b' || // ESC
c == '\u2014') // Em-Dash?
continue;
//----------------------------------------------------------------
// JISAutoDetect can handle all chars that EUC-JP can,
// unless there is an ambiguity with SJIS.
//----------------------------------------------------------------
cnteucj++;
cntBAD++;
fail("Autodetection agrees with neither EUC nor SJIS");
}
}
} else
continue; // Optimization
//----------------------------------------------------------------
// JISAutoDetect can handle all chars that ISO-2022-JP can.
//----------------------------------------------------------------
cnt2022++;
"ISO2022 autodetection");
}
//----------------------------------------------------------------
// JISAutoDetect can handle almost all chars that SJIS can.
//----------------------------------------------------------------
cntsjis++;
"SJIS autodetection");
}
}
"misdetected as SJIS after being EUC-encoded.%n", cntBAD);
//----------------------------------------------------------------
// tests for specific byte sequences
//----------------------------------------------------------------
test("SJIS",
new byte[] { 'C', 'o', 'p', 'y', 'r', 'i', 'g', 'h', 't',
' ', (byte)0xa9, ' ', '1', '9', '9', '8' });
test("SJIS",
new byte[] { (byte)0xbb, (byte)0xdd, (byte)0xcf, (byte)0xb2,
(byte)0xb8, (byte)0xdb, (byte)0xbc, (byte)0xbd,
(byte)0xc3, (byte)0xd1, (byte)0xbd, (byte)0xde,
(byte)0x82, (byte)0xc5, (byte)0x82, (byte)0xb7 });
test("EUC-JP",
new byte[] { (byte)0xa4, (byte)0xd2, (byte)0xa4, (byte)0xe9,
(byte)0xa4, (byte)0xac, (byte)0xa4, (byte)0xca });
test("SJIS",
new byte[] { (byte)0xbb, (byte)0xdd, (byte)0xcf, (byte)0xb2,
(byte)0xb8, (byte)0xdb, (byte)0xbc, (byte)0xbd,
(byte)0xc3, (byte)0xd1, (byte)0xbd, (byte)0xde});
test("SJIS",
new byte[] { (byte)0xbb, (byte)0xdd, (byte)0xcf, (byte)0xb2,
(byte)0xb8, (byte)0xdb, (byte)0xbc, (byte)0xbd,
(byte)0xc3, (byte)0xd1, (byte)0xbd });
test("SJIS",
new byte[] { (byte)0x8f, (byte)0xa1, (byte)0xaa });
test("EUC-JP",
new byte[] { (byte)0x8f, (byte)0xc5, (byte)0xe0, (byte)0x20});
test("EUC-JP",
new byte[] { (byte)0xbb, (byte)0xdd, (byte)0xcf, (byte)0xb2,
(byte)0xb8, (byte)0xdb, (byte)0xbc, (byte)0xbd,
(byte)0xc3, (byte)0xd1, (byte)0xbd, (byte)0xde,
(byte)0xa4, (byte)0xc7, (byte)0xa4, (byte)0xb9 });
test("ISO-2022-JP",
new byte[] { 0x1b, '$', 'B', '#', '4', '$', '5', 0x1b, '(', 'B' });
//----------------------------------------------------------------
// Check handling of ambiguous end-of-input in middle of first char
//----------------------------------------------------------------
{
}
if (failures > 0)
}
"Unexpected coder result: " + result);
}
charOutput.flip();
charExpected.flip();
}
}