test/java/awt/FontClass/CreateFont/BigFont.java

Print this page
rev 5428 : 6868690: TEST:java/awt/FontClass/CreateFont/BigFont.java test should be modified in jdk7&8 to run via jtreg

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -19,19 +19,29 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
+/*
+  @test  
+  @bug 6522586
+  @summary Enforce limits on font creation
+  @run main BigFont
+*/
 import java.applet.*;
 import java.awt.*;
 import java.io.*;
 import java.net.*;
 
 public class BigFont extends Applet {
 
-   static private class SizedInputStream extends InputStream {
+   public static void main(String args[]) {
+        System.setSecurityManager(new SecurityManager());
+        (new BigFont()).runTest1();
+   }
 
+   static private class SizedInputStream extends InputStream {
        int size;
        int cnt = 0;
 
        SizedInputStream(int size) {
            this.size = size;

@@ -55,13 +65,16 @@
     String fileName;
 
     public void init() {
         id = getParameter("number");
         fileName = getParameter("font");
-
         System.out.println("Applet " + id + " "+
                            Thread.currentThread().getThreadGroup());
+        runTest1();
+        runTest2();
+    }
+    void runTest1() {
         // Larger than size for a single font.
         int fontSize = 64 * 1000 * 1000;
         SizedInputStream sis = new SizedInputStream(fontSize);
         try {
              Font font = Font.createFont(Font.TRUETYPE_FONT, sis);

@@ -72,10 +85,12 @@
                 System.out.println(sis.getCurrentSize());
                 System.out.println(t);
                 throw new RuntimeException("Allowed file to be too large.");
             }
         }
+     }
+     void runTest2() {
         // The following part of the test was verified manually but
         // is impractical to enable  because it requires a fairly large
         // valid font to be part of the test, and we can't easily include
         // that, nor dependably reference one from the applet environment.
         /*