1/*
2 * Copyright (c) 2010, 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/*
25 * @test
26 * @bug 7002398
27 * @summary Verify that Corrigendum #8 for Unicode 6.0.0 has been applied.
28 */
29import java.text.*;
30
31public class Bug7002398 {
32
33    private static final int[] directions = {
34        Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT,
35        Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT,
36        Bidi.DIRECTION_LEFT_TO_RIGHT,
37        Bidi.DIRECTION_RIGHT_TO_LEFT
38    };
39
40    /*
41     * Old Bidi class: AL AN AL AN AL
42     * New Bidi class:          AL
43     */
44    private static final String str = "\u0627\u0660\u0710\u070F\u070D";
45    private static final int[] expectedLevels = {1, 2, 1, 1, 1};
46
47    public static void main(String[] args) {
48        boolean err = false;
49
50        for (int dir = 0; dir < directions.length; dir ++) {
51            Bidi bidi = new Bidi(str, directions[dir]);
52            for (int index = 0; index < str.length(); index ++) {
53                int gotLevel = bidi.getLevelAt(index);
54                if (gotLevel != expectedLevels[index]) {
55                    err = true;
56                    System.err.println("Unexpected level for the character 0x" +
57                        Integer.toHexString(str.charAt(index)).toUpperCase() +
58                        ": Expected level = " + expectedLevels[index] +
59                        ", actual level = " + bidi.getLevelAt(index) +
60                        " in direction = " + directions[dir] + ".");
61                }
62            }
63        }
64
65        if (err) {
66            throw new RuntimeException("Failed.");
67        }
68    }
69
70}
71