--- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/Frame/SetBounds/SetBounds.java 2014-04-10 14:45:43.653184227 +0400 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; +import java.applet.Applet; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +import static jdk.testlibrary.Asserts.*; + +/* + * @test 1.1 2001/05/14 + * @summary Checking Whether + * 1.When Frame.setExtendedStateBounds() is called for a + * Frame with state as Frame.NORMAL, the bounds of the + * Frame must be the same as what is specified when frame + * is in normal state. + * + * 2.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_VERT,the bounds + * of the Frame must be the same as what is specified + * when frame is in vertically maximized state. + * + * 3.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_HORZ,the bounds + * of the Frame must be the same as what is specified + * when frame is in horizontally maximized state. + * + * 4.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_BOTH,the bounds + * of the Frame must be the same as what is specified + * when frame is in maximized state. + * + * @library ../../../../lib/testlibrary + * @build ExtendedRobot jdk.testlibrary.Asserts + * @run main SetBounds + */ + +public class SetBounds extends Applet implements ActionListener { + + Frame testFrame; + Button[] buttons = new Button[4]; + Map borders = new HashMap(); + { + borders.put("NORMAL", new Rectangle(50,50,350,350)); + borders.put("MAXIMIZED_HORIZ", new Rectangle(50,50,500,350)); + borders.put("MAXIMIZED_VERT", new Rectangle(50,50,350,500)); + borders.put("MAXIMIZED_BOTH", new Rectangle(50,50,600,600)); + } + Rectangle bound = null; + ExtendedRobot robot; + boolean flag = false; + boolean actionPerformed; + + public Point targetCenter(Component target) { + int w = target.getWidth(); + int h = target.getHeight(); + Point loc = target.getLocationOnScreen(); + loc.x += (w/2); + loc.y += (h/2); + return loc; + } + + public SetBounds() throws Exception { + // CONFIG: Do any other initialization here. + try { + robot = new ExtendedRobot(); + } catch (AWTException e) { + e.printStackTrace(); + } + + SwingUtilities.invokeAndWait(() -> { + testFrame = new Frame( "TestFrame "); + testFrame.setLayout(new FlowLayout()); + + buttons[0] = new Button("NORMAL"); + buttons[1] = new Button("BOTH"); + buttons[2] = new Button("HORIZ"); + buttons[3] = new Button("VERT"); + + for (Button button : buttons) { + button.addActionListener(this); + testFrame.add(button); + } + + testFrame.setSize(200, 200); + testFrame.setVisible(true); + }); + + robot.waitForIdle(); + + } + + String getKey(Button button){ + if (button.getLabel().equals("NORMAL")) { + return button.getLabel(); + } else { + return "MAXIMIZED_"+button.getLabel(); + } + } + + void verify(String state) throws Exception { + if(Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.class.getField(state).getInt(null)) ) { + testFrame.setBounds(borders.get(state)); + bound = testFrame.getBounds(); + } else { + flag = true; + System.out.println("Frame."+state+" not supported"); + } + actionPerformed = true; + } + public void actionPerformed(ActionEvent ae) { + try { + verify(getKey((Button) ae.getSource())); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void doTest() { + // CONFIG: Put here the code to exercise and verify the GUI. + + for (Button button : buttons) { + actionPerformed = false; + bound = null; + flag = false; + robot.mouseMove(targetCenter(button)); + robot.waitForIdle(); + robot.click(); + robot.waitForIdle(); + + assertTrue(actionPerformed, "'"+getKey(button)+"' button did not trigger action when clicked"); + + if (!flag) { + assertEquals(bound, borders.get(getKey(button)), + "The Bounds of the Frame is not same as what" + + " is specified when the frame is in Frame. "+getKey(button)+" state"); + } + } + } + + public static void main(String[] args) throws Exception { + new SetBounds().doTest(); + } +}