1 /*
   2  * Copyright (c) 2000, 2018, 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   test
  25   @bug 4185854
  26   @summary Checks that constructors do not accept nulls and throw NPE
  27   @run applet ConstructorsNullTest.html
  28 */
  29 
  30 // Note there is no @ in front of test above.  This is so that the
  31 //  harness will not mistake this file as a test file.  It should
  32 //  only see the html file as a test file. (the harness runs all
  33 //  valid test files, so it would run this test twice if this file
  34 //  were valid as well as the html file.)
  35 // Also, note the area= after Your Name in the author tag.  Here, you
  36 //  should put which functional area the test falls in.  See the
  37 //  AWT-core home page -> test areas and/or -> AWT team  for a list of
  38 //  areas.
  39 // Note also the 'ConstructorsNullTest.html' in the run tag.  This should
  40 //  be changed to the name of the test.
  41 
  42 
  43 /**
  44  * ConstructorsNullTest.java
  45  *
  46  * summary:
  47  */
  48 
  49 import java.applet.Applet;
  50 import java.awt.*;
  51 import java.awt.image.*;
  52 import java.awt.color.*;
  53 
  54 
  55 //Automated tests should run as applet tests if possible because they
  56 // get their environments cleaned up, including AWT threads, any
  57 // test created threads, and any system resources used by the test
  58 // such as file descriptors.  (This is normally not a problem as
  59 // main tests usually run in a separate VM, however on some platforms
  60 // such as the Mac, separate VMs are not possible and non-applet
  61 // tests will cause problems).  Also, you don't have to worry about
  62 // synchronisation stuff in Applet tests they way you do in main
  63 // tests...
  64 
  65 
  66 public class ConstructorsNullTest extends Applet
  67  {
  68    //Declare things used in the test, like buttons and labels here
  69 
  70    public void init()
  71     {
  72       //Create instructions for the user here, as well as set up
  73       // the environment -- set the layout manager, add buttons,
  74       // etc.
  75 
  76       this.setLayout (new BorderLayout ());
  77 
  78     }//End  init()
  79 
  80    public void start ()
  81     {
  82       //Get things going.  Request focus, set size, et cetera
  83       setSize (200,200);
  84       show();
  85 

  86       ColorConvertOp gp;
  87       boolean passed = false;
  88       try {
  89           gp = new ColorConvertOp((ColorSpace)null, (RenderingHints)null);
  90       } catch (NullPointerException e) {
  91           try {
  92               gp = new ColorConvertOp((ColorSpace)null, null, null);
  93           } catch (NullPointerException e1) {
  94               try {
  95                   gp = new ColorConvertOp((ICC_Profile[])null, null);
  96               } catch (NullPointerException e2) {
  97                   passed = true;
  98               }
  99           }
 100       }
 101 
 102       if (!passed) {
 103           System.out.println("Test FAILED: one of constructors didn't throw NullPointerException.");
 104           throw new RuntimeException("Test FAILED: one of constructors didn't throw NullPointerException.");
 105       }
 106       System.out.println("Test PASSED: all constructors threw NullPointerException.");
 107 
 108       //What would normally go into main() will probably go here.
 109       //Use System.out.println for diagnostic messages that you want
 110       //to read after the test is done.
 111       //Use System.out.println for messages you want the tester to read.
 112 
 113     }// start()
 114 
 115  }// class ConstructorsNullTest
--- EOF ---