J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any 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 | String[] instructions = |
| 79 | { |
| 80 | "This is an AUTOMATIC test", |
| 81 | "simply wait until it is done" |
| 82 | }; |
| 83 | Sysout.createDialog( ); |
| 84 | Sysout.printInstructions( instructions ); |
| 85 | |
| 86 | }//End init() |
| 87 | |
| 88 | public void start () |
| 89 | { |
| 90 | //Get things going. Request focus, set size, et cetera |
| 91 | setSize (200,200); |
| 92 | show(); |
| 93 | |
| 94 | ColorConvertOp gp; |
| 95 | boolean passed = false; |
| 96 | try { |
| 97 | gp = new ColorConvertOp((ColorSpace)null, (RenderingHints)null); |
| 98 | } catch (NullPointerException e) { |
| 99 | try { |
| 100 | gp = new ColorConvertOp((ColorSpace)null, null, null); |
| 101 | } catch (NullPointerException e1) { |
| 102 | try { |
| 103 | gp = new ColorConvertOp((ICC_Profile[])null, null); |
| 104 | } catch (NullPointerException e2) { |
| 105 | passed = true; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (!passed) { |
| 111 | Sysout.println("Test FAILED: one of constructors didn't throw NullPointerException."); |
| 112 | throw new RuntimeException("Test FAILED: one of constructors didn't throw NullPointerException."); |
| 113 | } |
| 114 | Sysout.println("Test PASSED: all constructors threw NullPointerException."); |
| 115 | |
| 116 | //What would normally go into main() will probably go here. |
| 117 | //Use System.out.println for diagnostic messages that you want |
| 118 | //to read after the test is done. |
| 119 | //Use Sysout.println for messages you want the tester to read. |
| 120 | |
| 121 | }// start() |
| 122 | |
| 123 | }// class ConstructorsNullTest |
| 124 | |
| 125 | |
| 126 | /**************************************************** |
| 127 | Standard Test Machinery |
| 128 | DO NOT modify anything below -- it's a standard |
| 129 | chunk of code whose purpose is to make user |
| 130 | interaction uniform, and thereby make it simpler |
| 131 | to read and understand someone else's test. |
| 132 | ****************************************************/ |
| 133 | |
| 134 | /** |
| 135 | This is part of the standard test machinery. |
| 136 | It creates a dialog (with the instructions), and is the interface |
| 137 | for sending text messages to the user. |
| 138 | To print the instructions, send an array of strings to Sysout.createDialog |
| 139 | WithInstructions method. Put one line of instructions per array entry. |
| 140 | To display a message for the tester to see, simply call Sysout.println |
| 141 | with the string to be displayed. |
| 142 | This mimics System.out.println but works within the test harness as well |
| 143 | as standalone. |
| 144 | */ |
| 145 | |
| 146 | class Sysout |
| 147 | { |
| 148 | private static TestDialog dialog; |
| 149 | |
| 150 | public static void createDialogWithInstructions( String[] instructions ) |
| 151 | { |
| 152 | dialog = new TestDialog( new Frame(), "Instructions" ); |
| 153 | dialog.printInstructions( instructions ); |
| 154 | dialog.show(); |
| 155 | println( "Any messages for the tester will display here." ); |
| 156 | } |
| 157 | |
| 158 | public static void createDialog( ) |
| 159 | { |
| 160 | dialog = new TestDialog( new Frame(), "Instructions" ); |
| 161 | String[] defInstr = { "Instructions will appear here. ", "" } ; |
| 162 | dialog.printInstructions( defInstr ); |
| 163 | dialog.show(); |
| 164 | println( "Any messages for the tester will display here." ); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | public static void printInstructions( String[] instructions ) |
| 169 | { |
| 170 | dialog.printInstructions( instructions ); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | public static void println( String messageIn ) |
| 175 | { |
| 176 | dialog.displayMessage( messageIn ); |
| 177 | } |
| 178 | |
| 179 | }// Sysout class |
| 180 | |
| 181 | /** |
| 182 | This is part of the standard test machinery. It provides a place for the |
| 183 | test instructions to be displayed, and a place for interactive messages |
| 184 | to the user to be displayed. |
| 185 | To have the test instructions displayed, see Sysout. |
| 186 | To have a message to the user be displayed, see Sysout. |
| 187 | Do not call anything in this dialog directly. |
| 188 | */ |
| 189 | class TestDialog extends Dialog |
| 190 | { |
| 191 | |
| 192 | TextArea instructionsText; |
| 193 | TextArea messageText; |
| 194 | int maxStringLength = 80; |
| 195 | |
| 196 | //DO NOT call this directly, go through Sysout |
| 197 | public TestDialog( Frame frame, String name ) |
| 198 | { |
| 199 | super( frame, name ); |
| 200 | int scrollBoth = TextArea.SCROLLBARS_BOTH; |
| 201 | instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); |
| 202 | add( "North", instructionsText ); |
| 203 | |
| 204 | messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); |
| 205 | add("South", messageText); |
| 206 | |
| 207 | pack(); |
| 208 | |
| 209 | show(); |
| 210 | }// TestDialog() |
| 211 | |
| 212 | //DO NOT call this directly, go through Sysout |
| 213 | public void printInstructions( String[] instructions ) |
| 214 | { |
| 215 | //Clear out any current instructions |
| 216 | instructionsText.setText( "" ); |
| 217 | |
| 218 | //Go down array of instruction strings |
| 219 | |
| 220 | String printStr, remainingStr; |
| 221 | for( int i=0; i < instructions.length; i++ ) |
| 222 | { |
| 223 | //chop up each into pieces maxSringLength long |
| 224 | remainingStr = instructions[ i ]; |
| 225 | while( remainingStr.length() > 0 ) |
| 226 | { |
| 227 | //if longer than max then chop off first max chars to print |
| 228 | if( remainingStr.length() >= maxStringLength ) |
| 229 | { |
| 230 | //Try to chop on a word boundary |
| 231 | int posOfSpace = remainingStr. |
| 232 | lastIndexOf( ' ', maxStringLength - 1 ); |
| 233 | |
| 234 | if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; |
| 235 | |
| 236 | printStr = remainingStr.substring( 0, posOfSpace + 1 ); |
| 237 | remainingStr = remainingStr.substring( posOfSpace + 1 ); |
| 238 | } |
| 239 | //else just print |
| 240 | else |
| 241 | { |
| 242 | printStr = remainingStr; |
| 243 | remainingStr = ""; |
| 244 | } |
| 245 | |
| 246 | instructionsText.append( printStr + "\n" ); |
| 247 | |
| 248 | }// while |
| 249 | |
| 250 | }// for |
| 251 | |
| 252 | }//printInstructions() |
| 253 | |
| 254 | //DO NOT call this directly, go through Sysout |
| 255 | public void displayMessage( String messageIn ) |
| 256 | { |
| 257 | messageText.append( messageIn + "\n" ); |
| 258 | } |
| 259 | |
| 260 | }// TestDialog class |