1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /* @test
25  * @bug 8186803
26  * @summary Check if the linefeed is de/encoded correctly in ebcdic
27  * @modules jdk.charsets
28  */
29 
30 public class TestEBCDICLineFeed {
31 
main(String[] args)32     public static void main(String[] args) throws Exception {
33 
34         String[] csnames = new String[] {
35             "IBM037",  "IBM1025", "IBM1026", "IBM1112", "IBM1122", "IBM1123",
36             "IBM1166", "IBM273",  "IBM277",  "IBM278",  "IBM280",  "IBM284",
37             "IBM285",  "IBM297",  "IBM420",  "IBM424",  "IBM500",  "IBM838",
38             "IBM870",  "IBM871",   "IBM875", "IBM918",  "IBM930",  "IBM935",
39             "IBM937",  "IBM939",
40 
41             "IBM01140", "IBM01141", "IBM01142", "IBM01143", "IBM01144",
42             "IBM01145", "IBM01146", "IBM01147", "IBM01148", "IBM01149",
43         };
44 
45         int errs = 0;
46         for (String cs : csnames) {
47             byte[] bb = "\n".getBytes(cs);
48             if (bb.length != 1 || bb[0] != 0x15) {
49                 System.out.printf(" error: %s c2b  u+000A -> %x%n",
50                                   cs,  bb[0] & 0xff);
51                 errs++;
52             }
53             bb = "\u0085".getBytes(cs);
54             if (bb.length != 1 || bb[0] != 0x15) {
55                 System.out.printf(" error: %s c2b  u+0085 -> %x%n",
56                                   cs,  bb[0] & 0xff);
57                 errs++;
58             }
59             String str = new String(new byte[] { 0x15 }, cs);
60             if (!str.equals("\n")) {
61                 System.out.printf(" error: %s b2c  0015 -> 0x%x%n",
62                                   cs, str.toCharArray()[0] & 0xffff);
63             }
64             str = new String(new byte[] { 0x25 }, cs);
65             if (!str.equals("\n")) {
66                 System.out.printf(" error: %s b2c  0025 -> 0x%x%n",
67                                   cs, str.toCharArray()[0] & 0xffff);
68             }
69         }
70         if (errs > 0)
71             throw new Exception(errs + " error(s) detected");
72     }
73 }
74