jdk/test/java/text/Bidi/Bug7042148.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 10089 297652d14d44
child 40679 5378433ac23f
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10089
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     1
/*
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     4
 *
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     7
 * published by the Free Software Foundation.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     8
 *
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    13
 * accompanied this code).
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    14
 *
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    18
 *
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    21
 * questions.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    22
 */
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    23
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    24
/*
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    25
 * @test
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    26
 * @bug 7042148
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    27
 * @summary verify that Bidi.baseIsLeftToRight() returns the correct value even if an incorrect position is set in the given AttributedCharacterIterator.
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    28
 */
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    29
import java.awt.font.*;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    30
import java.text.*;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    31
import java.util.*;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    32
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    33
public class Bug7042148 {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    34
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    35
    private static boolean err = false;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    36
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    37
    public static void main(String[] args) {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    38
        testDirection();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    39
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    40
        if (err) {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    41
            throw new RuntimeException("Failed");
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    42
        } else {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    43
            System.out.println("Passed.");
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    44
        }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    45
    }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    46
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    47
    private static void testDirection() {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    48
        Map attrLTR = new HashMap();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    49
        attrLTR.put(TextAttribute.RUN_DIRECTION,
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    50
                    TextAttribute.RUN_DIRECTION_LTR);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    51
        Map attrRTL = new HashMap();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    52
        attrRTL.put(TextAttribute.RUN_DIRECTION,
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    53
                    TextAttribute.RUN_DIRECTION_RTL);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    54
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    55
        String str1 = "A\u05e0";
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    56
        String str2 = "\u05e0B";
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    57
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    58
        test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    59
        test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    60
        test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    61
        test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    62
    }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    63
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    64
    private static void test(String text, Map attr, int dirFlag) {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    65
        boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    66
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    67
        Bidi bidi = new Bidi(text, dirFlag);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    68
        boolean got = bidi.baseIsLeftToRight();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    69
        if (got != expected) {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    70
            err = true;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    71
            System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    72
                               "\n\ttext=" + text +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    73
                               "\n\tExpected=" + expected +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    74
                               "\n\tGot=" + got);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    75
        }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    76
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    77
        AttributedString as = new AttributedString(text, attr);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    78
        AttributedCharacterIterator itr = as.getIterator();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    79
        itr.last();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    80
        itr.next();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    81
        bidi = new Bidi(itr);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    82
        got = bidi.baseIsLeftToRight();
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    83
        if (got != expected) {
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    84
            err = true;
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    85
            System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    86
                               "\n\ttext=" + text +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    87
                               "\n\tExpected=" + expected +
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    88
                               "\n\tGot=" + got);
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    89
        }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    90
    }
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    91
297652d14d44 7042148: closed/java/awt/font/TextLayout/CheckLayoutLTR.java failed
peytoia
parents:
diff changeset
    92
}