Path: blob/master/test/jdk/java/awt/EmbeddedFrame/DisplayChangedTest/DisplayChangedTest.java
41153 views
/*1* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @key headful26* @bug 4980592 817136327* @summary switching user in XP causes an NPE in28* sun.awt.windows.WWindowPeer.displayChanged29* @requires (os.family == "windows")30* @modules java.desktop/java.awt.peer31* @modules java.desktop/sun.awt.windows:open32* @modules java.desktop/sun.awt33* @author [email protected]: area=embedded34* @run main DisplayChangedTest35*/3637import java.awt.Frame;38import java.awt.Dialog;39import java.awt.TextArea;40import java.awt.peer.ComponentPeer;41import java.awt.peer.FramePeer;42import java.lang.reflect.Constructor;43import java.lang.reflect.Method;44import java.lang.reflect.Field;4546import sun.awt.AWTAccessor;4748public class DisplayChangedTest {4950/**51* Test fails if it throws any exception.52*53* @throws Exception54*/55private void init() throws Exception {5657if (!System.getProperty("os.name").startsWith("Windows")) {58System.out.println("This is Windows only test.");59return;60}6162Frame frame = new Frame("AWT Frame");63frame.pack();6465FramePeer frame_peer = AWTAccessor.getComponentAccessor()66.getPeer(frame);67Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer");68Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");69hwnd_field.setAccessible(true);70long hwnd = hwnd_field.getLong(frame_peer);7172Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");73Constructor constructor = clazz74.getConstructor(new Class[]{long.class});75Frame embedded_frame = (Frame) constructor76.newInstance(new Object[]{new Long(hwnd)});77frame.setVisible(true);7879ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(80embedded_frame);81Class peerClass = peer.getClass();82Method displayChangedM = peerClass.getMethod("displayChanged",83new Class[0]);84displayChangedM.invoke(peer, null);85embedded_frame.dispose();86frame.dispose();8788}8990public static void main(String args[]) throws Exception {91new DisplayChangedTest().init();92}9394}959697