2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 395N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 395N/A * This code is free software; you can redistribute it and/or modify it 395N/A * under the terms of the GNU General Public License version 2 only, as 395N/A * published by the Free Software Foundation. 395N/A * This code is distributed in the hope that it will be useful, but WITHOUT 395N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 395N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 395N/A * version 2 for more details (a copy is included in the LICENSE file that 395N/A * accompanied this code). 395N/A * You should have received a copy of the GNU General Public License version 395N/A * 2 along with this work; if not, write to the Free Software Foundation, 395N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 395N/A @bug 4403848 6348426 6407730 395N/A @summary Check correctness of the UTF-16 converter in all its flavors 395N/A "obtained char[" + i +
"] : " +
395N/A private static void checkResult(char[] expected, 395N/A if (testStr.length() != expected.length) 395N/A failureReport(testStr, expected); 395N/A for (int i = 0; i < testStr.length(); i++) { 395N/A if (testStr.charAt(i) != expected[i]) { 395N/A failureReport(testStr, expected); 395N/A throw new Exception ("REGTEST TestUTF16 failed: " 395N/A System.err.println ("Test " + testName + " PASSED"); 395N/A // Tests: Check decoding of UTF-16. 395N/A // Ensures correct endian polarity 395N/A // of the decoders and appropriate 395N/A // interpretation of BOM bytes where 395N/A // Test 1: BigEndian UTF-16 Decoding 395N/A new byte[] { (
byte)
0x00, (
byte)
0x92,
395N/A (
byte)
0x00, (
byte)
0x93 });
395N/A // Test 1a: BigEndian UTF-16 Decoding. BOM bytes provided. 395N/A new byte[] { (
byte)
0xfe, (
byte)
0xff,
395N/A (
byte)
0x00, (
byte)
0x92,
395N/A (
byte)
0x00, (
byte)
0x93 });
395N/A new byte[] { (
byte)
0x00, (
byte)
0x92,
395N/A (
byte)
0x00, (
byte)
0x93 });
395N/A // Test 2a: LittleEndian UTF-16 Decoding, BOM bytes provided. 395N/A new byte[] { (
byte)
0xff, (
byte)
0xfe,
395N/A (
byte)
0x00, (
byte)
0x92,
395N/A (
byte)
0x00, (
byte)
0x93 });
395N/A // Test 3: UTF-16 (with mandatory byte order mark) Decoding 395N/A new byte[] { (
byte)
0xfe, (
byte)
0xff,
395N/A (
byte)
0x92, (
byte)
0x00,
395N/A (
byte)
0x93, (
byte)
0x00 });
395N/A // Test 3a: UTF-16 BOM omitted. This should decode OK. 395N/A new byte[] { (
byte)
0x92, (
byte)
0x00,
395N/A (
byte)
0x93, (
byte)
0x00 });
395N/A // Test 4: encoding using UTF-16 395N/A // BOM must be emitted when encoding and must be BigEndian. 395N/A new byte[] { (
byte)
0xfe, (
byte)
0xff,
395N/A (
byte)
0x01, (
byte)
0x23 });
395N/A {(
byte)
0xd8,(
byte)
0x00,
395N/A (
byte)
0xdc,(
byte)
0x01})
395N/A // UnicodeLittle should accept non-BOM byte sequence 395N/A new byte[] {
'A',
0,
'r',
0,
'i',
0,
'a',
0,
'l',
0});
395N/A // Reversed BOM in middle of stream Negative test. 395N/A boolean caughtException = false; 395N/A String out = new String(new byte[] {(byte)0x00, 395N/A } catch (IOException e) { caughtException = true; } 395N/A if (caughtException == false) 395N/A throw new Exception ("Incorrectly parsed BOM in middle of input"); 395N/A // Fixed included with bug 4403848 fixes buffer sizing 395N/A // issue due to non provision of additional 2 bytes 395N/A // headroom for initial BOM bytes for UTF-16 encoding.