blob: 04ddf6635077030df4bed20d62188a9cab08708b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 @test
26 @bug 4737732
27 @summary Tests that Toolkit.getScreenInsets() returns correct insets
28 @author artem.ananiev: area=awt.toplevel
29 @library ../../regtesthelpers
30 @build Util
31 @run main ScreenInsetsTest
32*/
33
34import java.awt.*;
35import java.awt.event.*;
36
37import test.java.awt.regtesthelpers.Util;
38
39public class ScreenInsetsTest
40{
41 public static void main(String[] args)
42 {
43 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
44 {
45 // this state is used in the test - sorry
46 return;
47 }
48
49 boolean passed = true;
50
51 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
52 GraphicsDevice[] gds = ge.getScreenDevices();
53 for (GraphicsDevice gd : gds)
54 {
55 GraphicsConfiguration gc = gd.getDefaultConfiguration();
56 Rectangle gcBounds = gc.getBounds();
57 Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
58
59 Frame f = new Frame("Test", gc);
60 f.setUndecorated(true);
61 f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
62 f.setVisible(true);
63 Util.waitForIdle(null);
64
65 f.setExtendedState(Frame.MAXIMIZED_BOTH);
66 Util.waitForIdle(null);
67
68 Rectangle fBounds = f.getBounds();
69 // workaround: on Windows maximized windows have negative coordinates
70 if (fBounds.x < gcBounds.x)
71 {
72 fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
73 fBounds.x = gcBounds.x;
74 }
75 if (fBounds.y < gcBounds.y)
76 {
77 fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased
78 fBounds.y = gcBounds.y;
79 }
80 Insets expected = new Insets(fBounds.y - gcBounds.y,
81 fBounds.x - gcBounds.x,
82 gcBounds.y + gcBounds.height - fBounds.y - fBounds.height,
83 gcBounds.x + gcBounds.width - fBounds.x - fBounds.width);
84
85 if (!expected.equals(gcInsets))
86 {
87 passed = false;
88 System.err.println("Wrong insets for GraphicsConfig: " + gc);
89 System.err.println("\tExpected: " + expected);
90 System.err.println("\tActual: " + gcInsets);
91 }
92
93 f.dispose();
94 }
95
96 if (!passed)
97 {
98 throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens");
99 }
100 }
101}