test/jdk/java/text/Bidi/Bug7042148.java
changeset 47216 71c04702a3d5
parent 40679 5378433ac23f
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2011, 2016, 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 7042148
       
    27  * @summary verify that Bidi.baseIsLeftToRight() returns the correct value even if an incorrect position is set in the given AttributedCharacterIterator.
       
    28  * @modules java.desktop
       
    29  */
       
    30 import java.awt.font.*;
       
    31 import java.text.*;
       
    32 import java.util.*;
       
    33 
       
    34 public class Bug7042148 {
       
    35 
       
    36     private static boolean err = false;
       
    37 
       
    38     public static void main(String[] args) {
       
    39         testDirection();
       
    40 
       
    41         if (err) {
       
    42             throw new RuntimeException("Failed");
       
    43         } else {
       
    44             System.out.println("Passed.");
       
    45         }
       
    46     }
       
    47 
       
    48     private static void testDirection() {
       
    49         Map attrLTR = new HashMap();
       
    50         attrLTR.put(TextAttribute.RUN_DIRECTION,
       
    51                     TextAttribute.RUN_DIRECTION_LTR);
       
    52         Map attrRTL = new HashMap();
       
    53         attrRTL.put(TextAttribute.RUN_DIRECTION,
       
    54                     TextAttribute.RUN_DIRECTION_RTL);
       
    55 
       
    56         String str1 = "A\u05e0";
       
    57         String str2 = "\u05e0B";
       
    58 
       
    59         test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
       
    60         test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
       
    61         test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
       
    62         test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
       
    63     }
       
    64 
       
    65     private static void test(String text, Map attr, int dirFlag) {
       
    66         boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);
       
    67 
       
    68         Bidi bidi = new Bidi(text, dirFlag);
       
    69         boolean got = bidi.baseIsLeftToRight();
       
    70         if (got != expected) {
       
    71             err = true;
       
    72             System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +
       
    73                                "\n\ttext=" + text +
       
    74                                "\n\tExpected=" + expected +
       
    75                                "\n\tGot=" + got);
       
    76         }
       
    77 
       
    78         AttributedString as = new AttributedString(text, attr);
       
    79         AttributedCharacterIterator itr = as.getIterator();
       
    80         itr.last();
       
    81         itr.next();
       
    82         bidi = new Bidi(itr);
       
    83         got = bidi.baseIsLeftToRight();
       
    84         if (got != expected) {
       
    85             err = true;
       
    86             System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +
       
    87                                "\n\ttext=" + text +
       
    88                                "\n\tExpected=" + expected +
       
    89                                "\n\tGot=" + got);
       
    90         }
       
    91     }
       
    92 
       
    93 }