Path: blob/master/test/jdk/java/awt/FontClass/DrawStringWithInfiniteXform.java
66644 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 {3738volatile Timer timer;39volatile boolean done;4041class ScheduleTask extends TimerTask {42public void run() {43if (!done) {44throw new45RuntimeException("drawString with InfiniteXform transform takes long time");46}47}48}49public DrawStringWithInfiniteXform() {50timer = new Timer();51timer.schedule(new ScheduleTask(), 20000);52}5354public static void main(String [] args) {55DrawStringWithInfiniteXform test = new DrawStringWithInfiniteXform();56test.start();57}5859private void start() {60float[] vals = new float[6];61for (int i=0;i<6;i++) vals[i]=Float.POSITIVE_INFINITY;62AffineTransform nanTX = new AffineTransform(vals);6364BufferedImage bi = new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB);65Graphics2D g2d = bi.createGraphics();6667g2d.rotate(Float.POSITIVE_INFINITY);68Font font = g2d.getFont();69Font xfiniteFont;70for (int i=0; i<2000; i++) {71xfiniteFont = font.deriveFont(Float.POSITIVE_INFINITY);72g2d.setFont(xfiniteFont);73g2d.drawString("abc", 20, 20);74}75done = true;76timer.cancel();77System.out.println("Test passed");78}79}808182