Path: blob/master/test/jdk/java/text/AttributedString/getRunStartLimitTest.java
41152 views
/*1* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 415116026* @summary Make sure to return correct run start and limit values27* when the iterator has been created with begin and end index values.28* @modules java.desktop29*/3031import java.awt.font.TextAttribute;32import java.text.AttributedCharacterIterator;33import java.text.AttributedString;34import java.text.Annotation;3536public class getRunStartLimitTest {3738public static void main(String[] args) throws Exception {3940String text = "Hello world";41AttributedString as = new AttributedString(text);4243// add non-Annotation attributes44as.addAttribute(TextAttribute.WEIGHT,45TextAttribute.WEIGHT_LIGHT,460,473);48as.addAttribute(TextAttribute.WEIGHT,49TextAttribute.WEIGHT_BOLD,503,515);52as.addAttribute(TextAttribute.WEIGHT,53TextAttribute.WEIGHT_EXTRABOLD,545,55text.length());5657// add Annotation attributes58as.addAttribute(TextAttribute.WIDTH,59new Annotation(TextAttribute.WIDTH_EXTENDED),600,613);62as.addAttribute(TextAttribute.WIDTH,63new Annotation(TextAttribute.WIDTH_CONDENSED),643,654);6667AttributedCharacterIterator aci = as.getIterator(null, 2, 4);6869aci.first();70int runStart = aci.getRunStart();71if (runStart != 2) {72throw new Exception("1st run start is wrong. ("+runStart+" should be 2.)");73}7475int runLimit = aci.getRunLimit();76if (runLimit != 3) {77throw new Exception("1st run limit is wrong. ("+runLimit+" should be 3.)");78}7980Object value = aci.getAttribute(TextAttribute.WEIGHT);81if (value != TextAttribute.WEIGHT_LIGHT) {82throw new Exception("1st run attribute is wrong. ("83+value+" should be "+TextAttribute.WEIGHT_LIGHT+".)");84}8586value = aci.getAttribute(TextAttribute.WIDTH);87if (value != null) {88throw new Exception("1st run annotation is wrong. ("89+value+" should be null.)");90}9192aci.setIndex(runLimit);93runStart = aci.getRunStart();94if (runStart != 3) {95throw new Exception("2nd run start is wrong. ("+runStart+" should be 3.)");96}9798runLimit = aci.getRunLimit();99if (runLimit != 4) {100throw new Exception("2nd run limit is wrong. ("+runLimit+" should be 4.)");101}102value = aci.getAttribute(TextAttribute.WEIGHT);103if (value != TextAttribute.WEIGHT_BOLD) {104throw new Exception("2nd run attribute is wrong. ("105+value+" should be "+TextAttribute.WEIGHT_BOLD+".)");106}107108value = aci.getAttribute(TextAttribute.WIDTH);109if (!(value instanceof Annotation)110|| (((Annotation)value).getValue() != TextAttribute.WIDTH_CONDENSED)) {111throw new Exception("2nd run annotation is wrong. (" + value + " should be "112+ new Annotation(TextAttribute.WIDTH_CONDENSED)+".)");113}114}115}116117118