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