Path: blob/master/test/jdk/java/awt/FontClass/DrawStringWithInfiniteXform.java
41149 views
/*1* Copyright (c) 2015, 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*/22/*23* @test24* @bug 802321325* @summary Font/Text APIs should not crash/takes long time26* if transform includes INIFINITY27* @run main DrawStringWithInfiniteXform28*/29import java.awt.*;30import java.awt.font.*;31import java.awt.geom.*;32import java.awt.image.*;33import java.util.Timer;34import java.util.TimerTask;3536public class DrawStringWithInfiniteXform {37Timer timer;38boolean done;39class ScheduleTask extends TimerTask {40public void run() {41timer.cancel();42if (!done) {43throw new44RuntimeException("drawString with InfiniteXform transform takes long time");45}46}47}48public DrawStringWithInfiniteXform() {49timer = new Timer();50timer.schedule(new ScheduleTask(), 10000);51}5253public static void main(String [] args) {54DrawStringWithInfiniteXform test = new DrawStringWithInfiniteXform();55test.start();56}5758private void start() {59float[] vals = new float[6];60for (int i=0;i<6;i++) vals[i]=Float.POSITIVE_INFINITY;61AffineTransform nanTX = new AffineTransform(vals);6263BufferedImage bi = new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB);64Graphics2D g2d = bi.createGraphics();6566g2d.rotate(Float.POSITIVE_INFINITY);67Font font = g2d.getFont();68Font xfiniteFont;69for (int i=0; i<2000; i++) {70xfiniteFont = font.deriveFont(Float.POSITIVE_INFINITY);71g2d.setFont(xfiniteFont);72g2d.drawString("abc", 20, 20);73}74done = true;75System.out.println("Test passed");76}77}787980