jdk/test/java/awt/Toolkit/Headless/WrappedToolkitTest/TestWrapped.java
changeset 12401 b41262091b0f
equal deleted inserted replaced
12400:80e69bcb0b8e 12401:b41262091b0f
       
     1 /*
       
     2  * Copyright (c) 2012, 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 6282388
       
    27  * @summary Tests that AWT use correct toolkit to be wrapped into HeadlessToolkit
       
    28  * @author artem.ananiev@sun.com: area=awt.headless
       
    29  * @run shell WrappedToolkitTest.sh
       
    30  */
       
    31 
       
    32 import java.awt.*;
       
    33 
       
    34 import java.lang.reflect.*;
       
    35 
       
    36 import sun.awt.*;
       
    37 
       
    38 public class TestWrapped
       
    39 {
       
    40     public static void main(String[] args)
       
    41     {
       
    42         try
       
    43         {
       
    44         if (args.length != 1) {
       
    45             System.err.println("No correct toolkit class name is specified, test is not run");
       
    46             System.exit(0);
       
    47         }
       
    48 
       
    49         String correctToolkitClassName = args[0];
       
    50         Toolkit tk = Toolkit.getDefaultToolkit();
       
    51         Class tkClass = tk.getClass();
       
    52         if (!tkClass.getName().equals("sun.awt.HeadlessToolkit"))
       
    53         {
       
    54             System.err.println(tkClass.getName());
       
    55             System.err.println("Error: default toolkit is not an instance of HeadlessToolkit");
       
    56             System.exit(-1);
       
    57         }
       
    58 
       
    59         Field f = tkClass.getDeclaredField("tk");
       
    60         f.setAccessible(true);
       
    61         Class wrappedClass = f.get(tk).getClass();
       
    62         if (!wrappedClass.getName().equals(correctToolkitClassName)) {
       
    63             System.err.println(wrappedClass.getName());
       
    64             System.err.println("Error: wrapped toolkit is not an instance of " + correctToolkitClassName);
       
    65             System.exit(-1);
       
    66         }
       
    67         }
       
    68         catch (Exception z)
       
    69         {
       
    70             z.printStackTrace(System.err);
       
    71             System.exit(-1);
       
    72         }
       
    73 
       
    74         System.exit(0);
       
    75     }
       
    76 }