1 /* 2 * Copyright (c) 2011, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 @test 28 @bug 7040577 29 @library ../../../regtesthelpers 30 @build Sysout 31 @summary Default implementation of Toolkit.loadSystemColors(int[]) and many others doesn't throw HE in hl env 32 @author andrei dmitriev: area=awt.headless 33 @run main/othervm -Djava.awt.headless=true ExceptionContract 34 */ 35 36 import java.awt.*; 37 import java.util.Properties; 38 import test.java.awt.regtesthelpers.Sysout; 39 40 import java.awt.datatransfer.Clipboard; 41 import java.awt.dnd.*; 42 import java.awt.dnd.peer.DragSourceContextPeer; 43 import java.awt.font.TextAttribute; 44 import java.awt.im.InputMethodHighlight; 45 import java.awt.image.*; 46 import java.awt.peer.*; 47 import java.net.URL; 48 import java.util.Map; 49 import java.util.Properties; 50 51 public class ExceptionContract { 52 53 private static boolean passed = false; 54 public static void main(String[] args) { 55 //Case1 56 try{ 57 new _Toolkit().getLockingKeyState(1); 58 } catch (HeadlessException he){ 59 passed = true; 60 } 61 if (!passed){ 62 throw new RuntimeException("Tk.getLockingKeyState() didn't throw HeadlessException while in the headless mode."); 63 } 64 65 passed = false; 66 //Case2 67 try{ 68 new _Toolkit().setLockingKeyState(1, true); 69 } catch (HeadlessException he){ 70 passed = true; 71 } 72 if (!passed){ 73 throw new RuntimeException("Tk.setLockingKeyState() didn't throw HeadlessException while in the headless mode."); 74 } 75 76 passed = false; 77 //Case3 78 try{ 79 new _Toolkit().createCustomCursor(new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB), new Point(0,0), "Custom cursor"); 80 } catch (HeadlessException he){ 81 he.printStackTrace(); 82 passed = true; 83 } 84 if (!passed){ 85 throw new RuntimeException("Tk.createCustomCursor(args) didn't throw HeadlessException while in the headless mode."); 86 } 87 88 } 89 90 static class _Toolkit extends Toolkit { 91 92 @Override 93 public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) 94 throws IndexOutOfBoundsException, HeadlessException 95 { 96 return super.createCustomCursor(cursor, hotSpot, name); 97 } 98 99 100 @Override 101 public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException { 102 super.setLockingKeyState(keyCode, on); 103 } 104 105 @Override 106 public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { 107 return super.getLockingKeyState(keyCode); 108 } 109 110 111 @Override 112 public void loadSystemColors(int[] systemColors) throws HeadlessException { 113 return; 114 } 115 116 @Override 117 protected DesktopPeer createDesktopPeer(Desktop target) throws HeadlessException { 118 return null; 119 } 120 121 @Override 122 protected ButtonPeer createButton(Button target) throws HeadlessException { 123 return null; 124 } 125 126 @Override 127 protected TextFieldPeer createTextField(TextField target) throws HeadlessException { 128 return null; 129 } 130 131 @Override 132 protected LabelPeer createLabel(Label target) throws HeadlessException { 133 return null; 134 } 135 136 @Override 137 protected ListPeer createList(List target) throws HeadlessException { 138 return null; 139 } 140 141 @Override 142 protected CheckboxPeer createCheckbox(Checkbox target) throws HeadlessException { 143 return null; 144 } 145 146 @Override 147 protected ScrollbarPeer createScrollbar(Scrollbar target) throws HeadlessException { 148 return null; 149 } 150 151 @Override 152 protected ScrollPanePeer createScrollPane(ScrollPane target) throws HeadlessException { 153 return null; 154 } 155 156 @Override 157 protected TextAreaPeer createTextArea(TextArea target) throws HeadlessException { 158 return null; 159 } 160 161 @Override 162 protected ChoicePeer createChoice(Choice target) throws HeadlessException { 163 return null; 164 } 165 166 @Override 167 protected FramePeer createFrame(Frame target) throws HeadlessException { 168 return null; 169 } 170 171 @Override 172 protected CanvasPeer createCanvas(Canvas target) { 173 return null; 174 } 175 176 @Override 177 protected PanelPeer createPanel(Panel target) { 178 return null; 179 } 180 181 @Override 182 protected WindowPeer createWindow(Window target) throws HeadlessException { 183 return null; 184 } 185 186 @Override 187 protected DialogPeer createDialog(Dialog target) throws HeadlessException { 188 return null; 189 } 190 191 @Override 192 protected MenuBarPeer createMenuBar(MenuBar target) throws HeadlessException { 193 return null; 194 } 195 196 @Override 197 protected MenuPeer createMenu(Menu target) throws HeadlessException { 198 return null; 199 } 200 201 @Override 202 protected PopupMenuPeer createPopupMenu(PopupMenu target) throws HeadlessException { 203 return null; 204 } 205 206 @Override 207 protected MenuItemPeer createMenuItem(MenuItem target) throws HeadlessException { 208 return null; 209 } 210 211 @Override 212 protected FileDialogPeer createFileDialog(FileDialog target) throws HeadlessException { 213 return null; 214 } 215 216 @Override 217 protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) throws HeadlessException { 218 return null; 219 } 220 221 @Override 222 protected FontPeer getFontPeer(String name, int style) { 223 return null; 224 } 225 226 @Override 227 public Dimension getScreenSize() throws HeadlessException { 228 return null; 229 } 230 231 @Override 232 public int getScreenResolution() throws HeadlessException { 233 return 0; 234 } 235 236 @Override 237 public ColorModel getColorModel() throws HeadlessException { 238 return null; 239 } 240 241 @Override 242 public String[] getFontList() { 243 return new String[0]; 244 } 245 246 @Override 247 public FontMetrics getFontMetrics(Font font) { 248 return null; 249 } 250 251 @Override 252 public void sync() { 253 254 } 255 256 @Override 257 public Image getImage(String filename) { 258 return null; 259 } 260 261 @Override 262 public Image getImage(URL url) { 263 return null; 264 } 265 266 @Override 267 public Image createImage(String filename) { 268 return null; 269 } 270 271 @Override 272 public Image createImage(URL url) { 273 return null; 274 } 275 276 @Override 277 public boolean prepareImage(Image image, int width, int height, ImageObserver observer) { 278 return false; 279 } 280 281 @Override 282 public int checkImage(Image image, int width, int height, ImageObserver observer) { 283 return 0; 284 } 285 286 @Override 287 public Image createImage(ImageProducer producer) { 288 return null; 289 } 290 291 @Override 292 public Image createImage(byte[] imagedata, int imageoffset, int imagelength) { 293 return null; 294 } 295 296 @Override 297 public PrintJob getPrintJob(Frame frame, String jobtitle, Properties props) { 298 return null; 299 } 300 301 @Override 302 public void beep() { 303 304 } 305 306 @Override 307 public Clipboard getSystemClipboard() throws HeadlessException { 308 return null; 309 } 310 311 @Override 312 protected EventQueue getSystemEventQueueImpl() { 313 return null; 314 } 315 316 @Override 317 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { 318 return null; 319 } 320 321 @Override 322 public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { 323 return false; 324 } 325 326 @Override 327 public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType) { 328 return false; 329 } 330 331 @Override 332 public Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) throws HeadlessException { 333 return null; 334 } 335 } 336 }