test/jdk/java/text/Bidi/Bug7051769.java
author jjg
Thu, 14 Dec 2017 13:16:33 -0800
changeset 48340 959f2f7cbaa6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8193525: Intermittent failures of TestModulePackages.java Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10090
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     1
/*
40679
5378433ac23f 8164859: Fix module dependences in java/text tests
shurailine
parents: 25385
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
10090
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     4
 *
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     8
 *
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    13
 * accompanied this code).
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    14
 *
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    18
 *
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    21
 * questions.
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    22
 */
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    23
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    24
/*
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    25
 * @test
25385
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    26
 * @bug 7051769 8038092
10090
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    27
 * @summary verify that Bidi.toString() returns the corect result.
25385
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    28
 *     The second run is intended to test lazy SharedSectets init for 8038092
40679
5378433ac23f 8164859: Fix module dependences in java/text tests
shurailine
parents: 25385
diff changeset
    29
 * @modules java.desktop
25385
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    30
 * @run main Bug7051769
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    31
 * @run main/othervm -DpreloadBidi=true Bug7051769
10090
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    32
 */
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    33
import java.awt.font.*;
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    34
import java.text.*;
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    35
import java.util.*;
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    36
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    37
public class Bug7051769 {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    38
25385
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    39
    static {
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    40
        if (System.getProperty("preloadBidi", "").equals("true")) {
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    41
            // Make sure the SharedSecret is lazily initialized correctly
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    42
            try {
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    43
                Class.forName("sun.text.bidi.BidiBase");
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    44
                System.out.println("BidiBase class has been pre-loaded.");
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    45
            } catch (ClassNotFoundException e) {
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    46
                System.out.println("BidiBase class could not be pre-loaded.");
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    47
            }
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    48
        }
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    49
    }
2c53e38b77aa 8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents: 10090
diff changeset
    50
10090
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    51
    private static boolean err = false;
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    52
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    53
    public static void main(String[] args) {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    54
        testNumericShaping();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    55
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    56
        if (err) {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    57
            throw new RuntimeException("Failed");
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    58
        } else {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    59
            System.out.println("Passed.");
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    60
        }
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    61
    }
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    62
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    63
    private static void testNumericShaping() {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    64
        Map attrNS = new HashMap();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    65
        attrNS.put(TextAttribute.NUMERIC_SHAPING,
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    66
                   NumericShaper.getContextualShaper(NumericShaper.ARABIC));
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    67
        attrNS.put(TextAttribute.RUN_DIRECTION,
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    68
                   TextAttribute.RUN_DIRECTION_RTL);
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    69
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    70
        String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10";
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    71
        String expected = "sun.text.bidi.BidiBase[dir: 2 baselevel: 1 length: 9 runs: [1 1 1 1 1 1 1 2 2] text: [0x623 0x643 0x62a 0x648 0x628 0x631 0x20 0x661 0x660]]";
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    72
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    73
        AttributedString as = new AttributedString(text, attrNS);
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    74
        AttributedCharacterIterator itr = as.getIterator();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    75
        itr.last();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    76
        itr.next();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    77
        Bidi bidi = new Bidi(itr);
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    78
        String got = bidi.toString();
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    79
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    80
        if (!got.equals(expected)) {
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    81
            err = true;
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    82
            System.err.println("Wrong toString() output: " +
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    83
                               "\n\tExpected=" + expected +
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    84
                               "\n\tGot=" + got);
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    85
        }
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    86
    }
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    87
8571585915b6 7051769: java.text.Bidi.toString() output is wrong
peytoia
parents:
diff changeset
    88
}