提交 f80cbd95 编写于 作者: A anthony

6848424: java/awt/Frame/FrameSize/TestFrameSize.java needs improvement

Summary: The test now thoroughly verifies the pack() method
Reviewed-by: art, dcherepanov
上级 f0f61c2d
/* /*
* Copyright 2009 Red Hat, Inc. All Rights Reserved. * Copyright 2009 Red Hat, Inc. All Rights Reserved.
* Portions Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,35 +38,62 @@ ...@@ -37,35 +38,62 @@
* Test fails if size of window is wrong * Test fails if size of window is wrong
*/ */
import java.awt.Dimension; import java.awt.*;
import java.awt.Frame;
public class TestFrameSize { public class TestFrameSize {
static Dimension desiredDimensions = new Dimension(200, 200); static Dimension desiredDimensions = new Dimension(200, 200);
static int ERROR_MARGIN = 15; static Frame mainWindow;
static Frame mainWindow;
private static Dimension getClientSize(Frame window) {
public static void drawGui() { Dimension size = window.getSize();
mainWindow = new Frame(""); Insets insets = window.getInsets();
mainWindow.setPreferredSize(desiredDimensions);
mainWindow.pack(); System.out.println("getClientSize() for " + window);
System.out.println(" size: " + size);
Dimension actualDimensions = mainWindow.getSize(); System.out.println(" insets: " + insets);
System.out.println("Desired dimensions: " + desiredDimensions.toString());
System.out.println("Actual dimensions: " + actualDimensions.toString()); return new Dimension(
if (Math.abs(actualDimensions.height - desiredDimensions.height) > ERROR_MARGIN) { size.width - insets.left - insets.right,
throw new RuntimeException("Incorrect widow size"); size.height - insets.top - insets.bottom);
} }
public static void drawGui() {
mainWindow = new Frame("");
mainWindow.setPreferredSize(desiredDimensions);
mainWindow.pack();
Dimension actualDimensions = mainWindow.getSize();
System.out.println("Desired dimensions: " + desiredDimensions.toString());
System.out.println("Actual dimensions: " + actualDimensions.toString());
if (!actualDimensions.equals(desiredDimensions)) {
throw new RuntimeException("Incorrect widow size");
}
// pack() guarantees to preserve the size of the client area after
// showing the window.
Dimension clientSize1 = getClientSize(mainWindow);
System.out.println("Client size before showing: " + clientSize1);
mainWindow.setVisible(true);
((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
Dimension clientSize2 = getClientSize(mainWindow);
System.out.println("Client size after showing: " + clientSize2);
if (!clientSize2.equals(clientSize1)) {
throw new RuntimeException("Incorrect client area size.");
} }
}
public static void main(String[] args) { public static void main(String[] args) {
try { try {
drawGui(); drawGui();
} finally { } finally {
if (mainWindow != null) { if (mainWindow != null) {
mainWindow.dispose(); mainWindow.dispose();
} }
}
} }
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册