Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EmbeddedFrame/DisplayChangedTest/DisplayChangedTest.java
38828 views
/*1* Copyright (c) 2013, 2015, 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@bug 498059226@summary switching user in XP causes an NPE in27sun.awt.windows.WWindowPeer.displayChanged28@requires (os.family == "windows")29@author [email protected]: area=embedded30@run main DisplayChangedTest31*/32/**33* DisplayChangedTest.java34*35* summary: switching user in XP causes an NPE in36* sun.awt.windows.WWindowPeer.displayChanged37*/38import java.awt.Frame;39import java.awt.Dialog;40import java.awt.TextArea;41import java.awt.peer.ComponentPeer;42import java.awt.peer.FramePeer;43import java.lang.reflect.Constructor;44import java.lang.reflect.Method;45import java.lang.reflect.Field;4647import sun.awt.AWTAccessor;4849public class DisplayChangedTest {5051/**52* Test fails if it throws any exception.53*54* @throws Exception55*/56private void init() throws Exception {5758if (!System.getProperty("os.name").startsWith("Windows")) {59System.out.println("This is Windows only test.");60return;61}6263Frame frame = new Frame("AWT Frame");64frame.pack();6566FramePeer frame_peer = (FramePeer) AWTAccessor.getComponentAccessor()67.getPeer(frame);68Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer");69Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");70hwnd_field.setAccessible(true);71long hwnd = hwnd_field.getLong(frame_peer);7273Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");74Constructor constructor = clazz75.getConstructor(new Class[]{long.class});76Frame embedded_frame = (Frame) constructor77.newInstance(new Object[]{new Long(hwnd)});78frame.setVisible(true);7980ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(81embedded_frame);82Class peerClass = peer.getClass();83Method displayChangedM = peerClass.getMethod("displayChanged",84new Class[0]);85displayChangedM.invoke(peer, null);86embedded_frame.dispose();87frame.dispose();8889}9091public static void main(String args[]) throws Exception {92new DisplayChangedTest().init();93}9495}969798