aboutsummaryrefslogtreecommitdiff
path: root/test/java
diff options
context:
space:
mode:
authorlana <none@none>2008-07-24 21:12:50 -0700
committerlana <none@none>2008-07-24 21:12:50 -0700
commit1015cd70b8294b2505e5c265d2ab081823c64f85 (patch)
tree20caa9b99b2c3f29ab84761a8b86b34a9bf4c652 /test/java
parent13ed324e155f4c5e3b311eb5d1433185cd381281 (diff)
parent3770d88ff7d368240f39657079ed4df0b6572c9a (diff)
Merge
Diffstat (limited to 'test/java')
-rw-r--r--test/java/awt/FullScreen/BufferStrategyExceptionTest/BufferStrategyExceptionTest.java134
-rw-r--r--test/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java387
-rw-r--r--test/java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java216
-rw-r--r--test/java/awt/FullScreen/SetFSWindow/FSFrame.java204
-rw-r--r--test/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java168
-rw-r--r--test/java/awt/font/TextLayout/VisibleAdvance.java24
-rw-r--r--test/java/awt/image/MemoryLeakTest/MemoryLeakTest.java175
-rw-r--r--test/java/awt/print/PrinterJob/PrintAWTImage.java90
-rw-r--r--test/java/awt/print/PrinterJob/duke.gifbin0 -> 1929 bytes
9 files changed, 1398 insertions, 0 deletions
diff --git a/test/java/awt/FullScreen/BufferStrategyExceptionTest/BufferStrategyExceptionTest.java b/test/java/awt/FullScreen/BufferStrategyExceptionTest/BufferStrategyExceptionTest.java
new file mode 100644
index 000000000..b50cf5939
--- /dev/null
+++ b/test/java/awt/FullScreen/BufferStrategyExceptionTest/BufferStrategyExceptionTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2006-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6366813 6459844
+ * @summary Tests that no exception is thrown if a frame is resized just
+ * before we create a bufferStrategy
+ * @author Dmitri.Trembovetski area=FullScreen/BufferStrategy
+ * @run main/othervm -Dsun.java2d.opengl=true BufferStrategyExceptionTest
+ * @run main/othervm BufferStrategyExceptionTest
+ */
+
+import java.awt.AWTException;
+import java.awt.BufferCapabilities;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.ImageCapabilities;
+import java.awt.image.BufferStrategy;
+import java.awt.image.BufferedImage;
+
+/**
+ * The purpose of this test is to make sure that we do not throw an
+ * IllegalStateException during the creation of BufferStrategy if
+ * a window has been resized just before our creation attempt.
+ *
+ * We test both windowed and fullscreen mode, although the exception has
+ * been observed in full screen mode only.
+ */
+public class BufferStrategyExceptionTest {
+ private static final int TEST_REPS = 20;
+
+ public static void main(String[] args) {
+ GraphicsDevice gd =
+ GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getDefaultScreenDevice();
+
+ for (int i = 0; i < TEST_REPS; i++) {
+ TestFrame f = new TestFrame();
+ f.pack();
+ f.setSize(400, 400);
+ f.setVisible(true);
+ if (i % 2 == 0) {
+ gd.setFullScreenWindow(f);
+ }
+ // generate a resize event which will invalidate the peer's
+ // surface data and hopefully cause an exception during
+ // BufferStrategy creation in TestFrame.render()
+ Dimension d = f.getSize();
+ d.width -= 5; d.height -= 5;
+ f.setSize(d);
+
+ f.render();
+ gd.setFullScreenWindow(null);
+ sleep(100);
+ f.dispose();
+ }
+ System.out.println("Test passed.");
+ }
+
+ private static void sleep(long msecs) {
+ try {
+ Thread.sleep(msecs);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private static final BufferedImage bi =
+ new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
+
+ static class TestFrame extends Frame {
+ TestFrame() {
+ setUndecorated(true);
+ setIgnoreRepaint(true);
+ setSize(400, 400);
+ }
+
+ public void render() {
+ ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
+ ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
+ BufferCapabilities bufCap =
+ new BufferCapabilities(imgFrontBufCap,
+ imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
+ try {
+
+ createBufferStrategy(2, bufCap);
+ } catch (AWTException ex) {
+ createBufferStrategy(2);
+ }
+
+ BufferStrategy bs = getBufferStrategy();
+ do {
+ Graphics g = bs.getDrawGraphics();
+ g.setColor(Color.green);
+ g.fillRect(0, 0, getWidth(), getHeight());
+
+ g.setColor(Color.red);
+ g.drawString("Rendering test", 20, 20);
+
+ g.drawImage(bi, 50, 50, null);
+
+ g.dispose();
+ bs.show();
+ } while (bs.contentsLost()||bs.contentsRestored());
+ }
+ }
+
+}
diff --git a/test/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java b/test/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java
new file mode 100644
index 000000000..7e615068c
--- /dev/null
+++ b/test/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java
@@ -0,0 +1,387 @@
+/*
+ * Copyright 2005-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 5041219
+ * @bug 5101561
+ * @bug 5035272
+ * @bug 5096011
+ * @bug 5101712
+ * @bug 5098624
+ * @summary Here are a few assertions worth verification:
+ * - the fullscreen window is positioned at 0,0
+ * - the fs window appears on the correct screen
+ * - if the exclusive FS mode is supported, no other widndow should
+ * overlap the fs window (including the taskbar).
+ * You could, however, alt+tab out of a fullscreen window, or at least
+ * minimize it (if you've entered the fs mode with a Window, you'll need
+ * to minimize the owner frame).
+ * Note that there may be issues with FS exclusive mode with ddraw and
+ * multiple fullscreen windows (one per device).
+ * - if display mode is supported that it did change
+ * - that the original display mode is restored once
+ * the ws window is disposed
+ * All of the above should work with and w/o DirectDraw
+ * (-Dsun.java2d.noddraw=true) on windows, and w/ and w/o opengl on X11
+ * (-Dsun.java2d.opengl=True).
+ * @run main/manual/othervm -Dsun.java2d.pmoffscreen=true MultimonFullscreenTest
+ * @run main/manual/othervm -Dsun.java2d.pmoffscreen=false MultimonFullscreenTest
+ * @run main/manual/othervm -Dsun.java2d.d3d=True MultimonFullscreenTest
+ * @run main/manual/othervm -Dsun.java2d.noddraw=true MultimonFullscreenTest
+ * @run main/manual/othervm -Dsun.java2d.opengl=True MultimonFullscreenTest
+ */
+
+import java.awt.Button;
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.DisplayMode;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.GridLayout;
+import java.awt.Panel;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferStrategy;
+import java.util.HashMap;
+import java.util.Random;
+
+/**
+ */
+
+public class MultimonFullscreenTest extends Frame implements ActionListener {
+ GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getDefaultScreenDevice();
+ GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getScreenDevices();
+ HashMap<Button, GraphicsDevice> deviceMap;
+
+ private static boolean dmChange = false;
+ static boolean setNullOnDispose = false;
+ static boolean useFSFrame = true;
+ static boolean useFSWindow = false;
+ static boolean useFSDialog = false;
+ static boolean useBS = false;
+ static boolean runRenderLoop = false;
+ static boolean addHWChildren = false;
+ static volatile boolean done = true;
+
+ public MultimonFullscreenTest(String title) {
+ super(title);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ Panel p = new Panel();
+ deviceMap = new HashMap<Button, GraphicsDevice>(gd.length);
+ int num = 0;
+ for (GraphicsDevice dev : gd) {
+ Button b;
+ if (dev == defDev) {
+ b = new Button("Primary screen: " + num);
+ System.out.println("Primary Dev : " + dev + " Bounds: " +
+ dev.getDefaultConfiguration().getBounds());
+ } else {
+ b = new Button("Secondary screen " + num);
+ System.out.println("Secondary Dev : " + dev + " Bounds: " +
+ dev.getDefaultConfiguration().getBounds());
+ }
+ b.addActionListener(this);
+ p.add(b);
+ deviceMap.put(b, dev);
+ num++;
+ }
+ add("South", p);
+ Panel p1 = new Panel();
+ p1.setLayout(new GridLayout(2,0));
+ Checkbox cb = new Checkbox("Change DM on entering FS");
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ dmChange = ((Checkbox)e.getSource()).getState();
+ }
+ });
+ p1.add(cb);
+// cb = new Checkbox("Exit FS on window dispose");
+// cb.addItemListener(new ItemListener() {
+// public void itemStateChanged(ItemEvent e) {
+// setNullOnDispose = ((Checkbox)e.getSource()).getState();
+// }
+// });
+// p1.add(cb);
+ CheckboxGroup cbg = new CheckboxGroup();
+ cb = new Checkbox("Use Frame to enter FS", cbg, true);
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ useFSFrame = true;
+ useFSWindow = false;
+ useFSDialog = false;
+ }
+ });
+ p1.add(cb);
+ cb = new Checkbox("Use Window to enter FS", cbg, false);
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ useFSFrame = false;
+ useFSWindow = true;
+ useFSDialog = false;
+ }
+ });
+ p1.add(cb);
+ cb = new Checkbox("Use Dialog to enter FS", cbg, false);
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ useFSFrame = false;
+ useFSWindow = false;
+ useFSDialog = true;
+ }
+ });
+ p1.add(cb);
+ cb = new Checkbox("Run render loop");
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ runRenderLoop = ((Checkbox)e.getSource()).getState();
+ }
+ });
+ p1.add(cb);
+ cb = new Checkbox("Use BufferStrategy in render loop");
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ useBS = ((Checkbox)e.getSource()).getState();
+ }
+ });
+ p1.add(cb);
+ cb = new Checkbox("Add Children to FS window");
+ cb.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ addHWChildren = ((Checkbox)e.getSource()).getState();
+ }
+ });
+ p1.add(cb);
+ add("North", p1);
+
+ pack();
+ setVisible(true);
+ }
+
+ Font f = new Font("Dialog", Font.BOLD, 24);
+ Random rnd = new Random();
+ public void renderDimensions(Graphics g, Rectangle rectWndBounds,
+ GraphicsConfiguration gc) {
+ g.setColor(new Color(rnd.nextInt(0xffffff)));
+ g.fillRect(0, 0, rectWndBounds.width, rectWndBounds.height);
+
+ g.setColor(new Color(rnd.nextInt(0xffffff)));
+ Rectangle rectStrBounds;
+
+ g.setFont(f);
+
+ rectStrBounds = g.getFontMetrics().
+ getStringBounds(rectWndBounds.toString(), g).getBounds();
+ rectStrBounds.height += 30;
+ g.drawString(rectWndBounds.toString(), 50, rectStrBounds.height);
+ int oldHeight = rectStrBounds.height;
+ String isFSupported = "Exclusive Fullscreen mode supported: " +
+ gc.getDevice().isFullScreenSupported();
+ rectStrBounds = g.getFontMetrics().
+ getStringBounds(isFSupported, g).getBounds();
+ rectStrBounds.height += (10 + oldHeight);
+ g.drawString(isFSupported, 50, rectStrBounds.height);
+
+ oldHeight = rectStrBounds.height;
+ String isDMChangeSupported = "Display Mode Change supported: " +
+ gc.getDevice().isDisplayChangeSupported();
+ rectStrBounds = g.getFontMetrics().
+ getStringBounds(isDMChangeSupported, g).getBounds();
+ rectStrBounds.height += (10 + oldHeight);
+ g.drawString(isDMChangeSupported, 50, rectStrBounds.height);
+
+ oldHeight = rectStrBounds.height;
+ String usingBS = "Using BufferStrategy: " + useBS;
+ rectStrBounds = g.getFontMetrics().
+ getStringBounds(usingBS, g).getBounds();
+ rectStrBounds.height += (10 + oldHeight);
+ g.drawString(usingBS, 50, rectStrBounds.height);
+
+ final String m_strQuitMsg = "Double-click to dispose FullScreen Window";
+ rectStrBounds = g.getFontMetrics().
+ getStringBounds(m_strQuitMsg, g).getBounds();
+ g.drawString(m_strQuitMsg,
+ (rectWndBounds.width - rectStrBounds.width) / 2,
+ (rectWndBounds.height - rectStrBounds.height) / 2);
+
+
+ }
+
+ public void actionPerformed(ActionEvent ae) {
+ GraphicsDevice dev = deviceMap.get(ae.getSource());
+ System.err.println("Setting FS on device:"+dev);
+ final Window fsWindow;
+
+ if (useFSWindow) {
+ fsWindow = new Window(this, dev.getDefaultConfiguration()) {
+ public void paint(Graphics g) {
+ renderDimensions(g, getBounds(),
+ this.getGraphicsConfiguration());
+ }
+ };
+ } else if (useFSDialog) {
+ fsWindow = new Dialog((Frame)null, "FS Dialog on device "+dev, false,
+ dev.getDefaultConfiguration());
+ fsWindow.add(new Component() {
+ public void paint(Graphics g) {
+ renderDimensions(g, getBounds(),
+ this.getGraphicsConfiguration());
+ }
+ });
+ } else {
+ fsWindow = new Frame("FS Frame on device "+dev,
+ dev.getDefaultConfiguration())
+ {
+ public void paint(Graphics g) {
+ renderDimensions(g, getBounds(),
+ this.getGraphicsConfiguration());
+ }
+ };
+ if (addHWChildren) {
+ fsWindow.add("South", new Panel() {
+ public void paint(Graphics g) {
+ g.setColor(Color.red);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
+ });
+ fsWindow.add("North", new Button("Button, sucka!"));
+ }
+ }
+ fsWindow.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() > 1) {
+ done = true;
+ fsWindow.dispose();
+ }
+ }
+ });
+
+ fsWindow.addWindowListener(new WindowHandler());
+ dev.setFullScreenWindow(fsWindow);
+ if (dmChange && dev.isDisplayChangeSupported()) {
+ DisplayMode dms[] = dev.getDisplayModes();
+ DisplayMode myDM = null;
+ for (DisplayMode dm : dms) {
+ if (dm.getWidth() == 800 && dm.getHeight() == 600 &&
+ (dm.getBitDepth() >= 16 ||
+ dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&
+ (dm.getRefreshRate() >= 60 ||
+ dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN))
+ {
+ myDM = dm;
+ break;
+ }
+ }
+ if (myDM != null) {
+ System.err.println("Setting Display Mode: "+
+ myDM.getWidth() + "x" + myDM.getHeight() + "x" +
+ myDM.getBitDepth() + "@" + myDM.getRefreshRate() +
+ "Hz on device" + dev);
+ dev.setDisplayMode(myDM);
+ } else {
+ System.err.println("Can't find suitable display mode.");
+ }
+ }
+ done = false;
+ if (runRenderLoop) {
+ Thread updateThread = new Thread(new Runnable() {
+ public void run() {
+ BufferStrategy bs = null;
+ if (useBS) {
+ fsWindow.createBufferStrategy(2);
+ bs = fsWindow.getBufferStrategy();
+ }
+ while (!done) {
+ if (useBS) {
+ Graphics g = bs.getDrawGraphics();
+ renderDimensions(g, fsWindow.getBounds(),
+ fsWindow.getGraphicsConfiguration());
+ bs.show();
+ } else {
+ fsWindow.repaint();
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+ }
+ if (useBS) {
+ bs.dispose();
+ }
+ }
+ });
+ updateThread.start();
+ }
+ }
+
+ public static void main(String args[]) {
+ for (String s : args) {
+ if (s.equalsIgnoreCase("-dm")) {
+ System.err.println("Do Display Change after entering FS mode");
+ dmChange = true;
+ } else if (s.equalsIgnoreCase("-usewindow")) {
+ System.err.println("Using Window to enter FS mode");
+ useFSWindow = true;
+ } else if (s.equalsIgnoreCase("-setnull")) {
+ System.err.println("Setting null FS window on dispose");
+ setNullOnDispose = true;
+ } else {
+ System.err.println("Usage: MultimonFullscreenTest " +
+ "[-dm][-usewindow][-setnull]");
+ }
+
+ }
+ MultimonFullscreenTest fs =
+ new MultimonFullscreenTest("Test Full Screen");
+ }
+ class WindowHandler extends WindowAdapter {
+ public void windowClosing(WindowEvent we) {
+ done = true;
+ Window w = (Window)we.getSource();
+ if (setNullOnDispose) {
+ w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
+ }
+ w.dispose();
+ }
+ }
+}
diff --git a/test/java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java b/test/java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java
new file mode 100644
index 000000000..2e6ccdfb0
--- /dev/null
+++ b/test/java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2007-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @bug 6646411
+ * @summary Tests that full screen window and its children receive resize
+ event when display mode changes
+ * @author Dmitri.Trembovetski@sun.com: area=Graphics
+ * @run main/othervm NoResizeEventOnDMChangeTest
+ * @run main/othervm -Dsun.java2d.d3d=false NoResizeEventOnDMChangeTest
+ */
+
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.DisplayMode;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Window;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+public class NoResizeEventOnDMChangeTest {
+ public static void main(String[] args) {
+ final GraphicsDevice gd = GraphicsEnvironment.
+ getLocalGraphicsEnvironment().getDefaultScreenDevice();
+
+ if (!gd.isFullScreenSupported()) {
+ System.out.println("Full screen not supported, test passed");
+ return;
+ }
+
+ DisplayMode dm = gd.getDisplayMode();
+ final DisplayMode dms[] = new DisplayMode[2];
+ for (DisplayMode dm1 : gd.getDisplayModes()) {
+ if (dm1.getWidth() != dm.getWidth() ||
+ dm1.getHeight() != dm.getHeight())
+ {
+ dms[0] = dm1;
+ break;
+ }
+ }
+ if (dms[0] == null) {
+ System.out.println("Test Passed: all DMs have same dimensions");
+ return;
+ }
+ dms[1] = dm;
+
+ Frame f = new Frame() {
+ @Override
+ public void paint(Graphics g) {
+ g.setColor(Color.red);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setColor(Color.green);
+ g.drawRect(0, 0, getWidth()-1, getHeight()-1);
+ }
+ };
+ f.setUndecorated(true);
+ testFSWindow(gd, dms, f);
+
+ Window w = new Window(f) {
+ @Override
+ public void paint(Graphics g) {
+ g.setColor(Color.magenta);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setColor(Color.cyan);
+ g.drawRect(0, 0, getWidth()-1, getHeight()-1);
+ }
+ };
+ testFSWindow(gd, dms, w);
+ System.out.println("Test Passed.");
+ }
+
+ private static void testFSWindow(final GraphicsDevice gd,
+ final DisplayMode dms[],
+ final Window fsWin)
+ {
+ System.out.println("Testing FS window: "+fsWin);
+ Component c = new Canvas() {
+ @Override
+ public void paint(Graphics g) {
+ g.setColor(Color.blue);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setColor(Color.magenta);
+ g.drawRect(0, 0, getWidth()-1, getHeight()-1);
+ g.setColor(Color.red);
+ g.drawString("FS Window : " + fsWin, 50, 50);
+ DisplayMode dm =
+ getGraphicsConfiguration().getDevice().getDisplayMode();
+ g.drawString("Display Mode: " +
+ dm.getWidth() + "x" + dm.getHeight(), 50, 75);
+ }
+ };
+ fsWin.add("Center", c);
+ fsWin.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ fsWin.dispose();
+ if (fsWin.getOwner() != null) {
+ fsWin.getOwner().dispose();
+ }
+ }
+ });
+
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ gd.setFullScreenWindow(fsWin);
+ }
+ });
+ } catch (Exception ex) {}
+
+ sleep(1000);
+
+ final ResizeEventChecker r1 = new ResizeEventChecker();
+ final ResizeEventChecker r2 = new ResizeEventChecker();
+
+ if (gd.isDisplayChangeSupported()) {
+ fsWin.addComponentListener(r1);
+ c.addComponentListener(r2);
+ for (final DisplayMode dm1 : dms) {
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ System.err.printf("----------- Setting DM %dx%d:\n",
+ dm1.getWidth(), dm1.getHeight());
+ try {
+ gd.setDisplayMode(dm1);
+ r1.incDmChanges();
+ r2.incDmChanges();
+ } catch (IllegalArgumentException iae) {}
+ }
+ });
+ } catch (Exception ex) {}
+ for (int i = 0; i < 3; i++) {
+ fsWin.repaint();
+ sleep(1000);
+ }
+ }
+ fsWin.removeComponentListener(r1);
+ c.removeComponentListener(r2);
+ }
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ gd.setFullScreenWindow(null);
+ fsWin.dispose();
+ if (fsWin.getOwner() != null) {
+ fsWin.getOwner().dispose();
+ }
+ }
+ });
+ } catch (Exception ex) {}
+
+ System.out.printf("FS Window: resizes=%d, dm changes=%d\n",
+ r1.getResizes(), r1.getDmChanges());
+ System.out.printf("Component: resizes=%d, dm changes=%d\n",
+ r2.getResizes(), r2.getDmChanges());
+ if (r1.getResizes() < r1.getDmChanges()) {
+ throw new RuntimeException("FS Window didn't receive all resizes!");
+ }
+ if (r2.getResizes() < r2.getDmChanges()) {
+ throw new RuntimeException("Component didn't receive all resizes!");
+ }
+ }
+
+ static void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {}
+ }
+ static class ResizeEventChecker extends ComponentAdapter {
+ int dmChanges;
+ int resizes;
+
+ @Override
+ public synchronized void componentResized(ComponentEvent e) {
+ System.out.println("Received resize event for "+e.getSource());
+ resizes++;
+ }
+ public synchronized int getResizes() {
+ return resizes;
+ }
+ public synchronized void incDmChanges() {
+ dmChanges++;
+ }
+ public synchronized int getDmChanges() {
+ return dmChanges;
+ }
+ }
+}
diff --git a/test/java/awt/FullScreen/SetFSWindow/FSFrame.java b/test/java/awt/FullScreen/SetFSWindow/FSFrame.java
new file mode 100644
index 000000000..c4d423114
--- /dev/null
+++ b/test/java/awt/FullScreen/SetFSWindow/FSFrame.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2005-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6240507 6662642
+ * @summary verify that isFullScreenSupported and getFullScreenWindow work
+ * correctly with and without a SecurityManager. Note that the test may fail
+ * on older Gnome versions (see bug 6500686).
+ * @run main FSFrame
+ * @run main/othervm -Dsun.java2d.noddraw=true FSFrame
+ * @author cheth
+ */
+
+import java.awt.*;
+import java.awt.image.*;
+import java.applet.*;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import javax.imageio.ImageIO;
+
+public class FSFrame extends Frame implements Runnable {
+
+ // Don't start the test until the window is visible
+ boolean visible = false;
+ Robot robot = null;
+ static volatile boolean done = false;
+
+ public void paint(Graphics g) {
+ if (!visible && getWidth() != 0 && getHeight() != 0) {
+ visible = true;
+ try {
+ GraphicsDevice gd = getGraphicsConfiguration().getDevice();
+ robot = new Robot(gd);
+ } catch (Exception e) {
+ System.out.println("Problem creating robot: cannot verify FS " +
+ "window display");
+ }
+ }
+ g.setColor(Color.green);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
+
+ @Override
+ public void update(Graphics g) {
+ paint(g);
+ }
+
+ boolean checkColor(int x, int y, BufferedImage bImg) {
+ int pixelColor;
+ int correctColor = Color.green.getRGB();
+ pixelColor = bImg.getRGB(x, y);
+ if (pixelColor != correctColor) {
+ System.out.println("FAILURE: pixelColor " +
+ Integer.toHexString(pixelColor) +
+ " != correctColor " +
+ Integer.toHexString(correctColor) +
+ " at coordinates (" + x + ", " + y + ")");
+ return false;
+ }
+ return true;
+ }
+
+ void checkFSDisplay(boolean fsSupported) {
+ GraphicsConfiguration gc = getGraphicsConfiguration();
+ GraphicsDevice gd = gc.getDevice();
+ Rectangle r = gc.getBounds();
+ Insets in = null;
+ if (!fsSupported) {
+ in = Toolkit.getDefaultToolkit().getScreenInsets(gc);
+ r = new Rectangle(in.left, in.top,
+ r.width - (in.left + in.right),
+ r.height - (in.top + in.bottom));
+ }
+ BufferedImage bImg = robot.createScreenCapture(r);
+ // Check that all four corners and middle pixel match the window's
+ // fill color
+ if (robot == null) {
+ return;
+ }
+ boolean colorCorrect = true;
+ colorCorrect &= checkColor(0, 0, bImg);
+ colorCorrect &= checkColor(0, bImg.getHeight() - 1, bImg);
+ colorCorrect &= checkColor(bImg.getWidth() - 1, 0, bImg);
+ colorCorrect &= checkColor(bImg.getWidth() - 1, bImg.getHeight() - 1, bImg);
+ colorCorrect &= checkColor(bImg.getWidth() / 2, bImg.getHeight() / 2, bImg);
+ if (!colorCorrect) {
+ System.err.println("Test failed for mode: fsSupported="+fsSupported);
+ if (in != null) {
+ System.err.println("screen insets : " + in);
+ }
+ System.err.println("screen shot rect: " + r);
+ String name = "FSFrame_fs_"+
+ (fsSupported?"supported":"not_supported")+".png";
+ try {
+ ImageIO.write(bImg, "png", new File(name));
+ System.out.println("Dumped screen shot to "+name);
+ } catch (IOException ex) {}
+ throw new Error("Some pixel colors not correct; FS window may not" +
+ " have been displayed correctly");
+ }
+ }
+
+ void checkFSFunctionality(boolean withSecurity) {
+ GraphicsDevice gd = getGraphicsConfiguration().getDevice();
+ if (withSecurity) {
+ SecurityManager sm = new SecurityManager();
+ System.setSecurityManager(sm);
+ }
+ try {
+ // None of these should throw an exception
+ final boolean fs = gd.isFullScreenSupported();
+ System.out.println("FullscreenSupported: " + (fs ? "yes" : "no"));
+ gd.setFullScreenWindow(this);
+ try {
+ // Give the system time to set the FS window and display it
+ // properly
+ Thread.sleep(2000);
+ } catch (Exception e) {}
+ if (!withSecurity) {
+ // See if FS window got displayed correctly
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ repaint();
+ checkFSDisplay(fs);
+ }
+ });
+ } catch (InvocationTargetException ex) {
+ ex.printStackTrace();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ }
+ // reset window
+ gd.setFullScreenWindow(null);
+ try {
+ // Give the system time to set the FS window and display it
+ // properly
+ Thread.sleep(2000);
+ } catch (Exception e) {}
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ throw new Error("Failure: should not get an exception when " +
+ "calling isFSSupported or setFSWindow");
+ }
+ }
+
+ public void run() {
+ boolean firstTime = true;
+ while (!done) {
+ if (visible) {
+ checkFSFunctionality(false);
+ checkFSFunctionality(true);
+ done = true;
+ } else {
+ // sleep while we wait
+ try {
+ // Give the system time to set the FS window and display it
+ // properly
+ Thread.sleep(100);
+ } catch (Exception e) {}
+ }
+ }
+ System.out.println("PASS");
+ }
+
+ public static void main(String args[]) {
+ FSFrame frame = new FSFrame();
+ frame.setUndecorated(true);
+ Thread t = new Thread(frame);
+ frame.setSize(500, 500);
+ frame.setVisible(true);
+ t.start();
+ while (!done) {
+ try {
+ // Do not exit the main thread until the test is finished
+ Thread.sleep(1000);
+ } catch (Exception e) {}
+ }
+ frame.dispose();
+ }
+}
diff --git a/test/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java b/test/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java
new file mode 100644
index 000000000..a3062bcef
--- /dev/null
+++ b/test/java/awt/Multiscreen/DeviceIdentificationTest/DeviceIdentificationTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2007-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/**
+ * @test
+ * @bug 6614214
+ * @summary Verifies that we enter the fs mode on the correct screen.
+ * Here is how to test: start the test on on a multi-screen system.
+ * Verify that the display is correctly tracked by dragging the frame back
+ * and forth between screens. Then verify that the correct device enters
+ * the full-screen mode - when "Enter FS mode" is pressed it should enter on
+ * the device where the frame is.
+ *
+ * Then change the order of the monitors in the DisplayProperties dialog,
+ * (while the app is running) and see that it still works.
+ * Restart the app, verify again.
+ *
+ * Now change the primary monitor on the system and verify with the
+ * app running, as well as after restarting it that we still enter the
+ * fs mode on the right device.
+ *
+ * @run main/manual/othervm DeviceIdentificationTest
+ * @run main/manual/othervm -Dsun.java2d.noddraw=true DeviceIdentificationTest
+ * @run main/manual/othervm -Dsun.java2d.opengl=True DeviceIdentificationTest
+ */
+
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Panel;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+public class DeviceIdentificationTest {
+
+ public static void main(String args[]) {
+ final Frame f = new Frame("DeviceIdentificationTest");
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ f.dispose();
+ }
+ });
+ f.addComponentListener(new ComponentAdapter() {
+ public void componentMoved(ComponentEvent e) {
+ f.setTitle("Currently on: "+
+ f.getGraphicsConfiguration().getDevice());
+ }
+ });
+
+ Panel p = new Panel();
+ Button b = new Button("Print Current Devices");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ GraphicsDevice gds[] =
+ GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getScreenDevices();
+ int i = 0;
+ System.err.println("--- Devices: ---");
+ for (GraphicsDevice gd : gds) {
+ System.err.println("Device["+i+"]= "+ gd);
+ System.err.println(" bounds = "+
+ gd.getDefaultConfiguration().getBounds());
+ i++;
+ }
+ System.err.println("-------------------");
+ }
+ });
+ p.add(b);
+
+ b = new Button("Print My Device");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ GraphicsConfiguration gc = f.getGraphicsConfiguration();
+ GraphicsDevice gd = gc.getDevice();
+ System.err.println("--- My Device ---");
+ System.err.println("Device = "+ gd);
+ System.err.println(" bounds = "+
+ gd.getDefaultConfiguration().getBounds());
+ }
+ });
+ p.add(b);
+
+ b = new Button("Create FS Frame on my Device");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ GraphicsConfiguration gc = f.getGraphicsConfiguration();
+ final GraphicsDevice gd = gc.getDevice();
+ System.err.println("--- Creating FS Frame on Device ---");
+ System.err.println("Device = "+ gd);
+ System.err.println(" bounds = "+
+ gd.getDefaultConfiguration().getBounds());
+ final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {
+ public void paint(Graphics g) {
+ g.setColor(Color.green);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setColor(Color.red);
+ g.drawString("FS on device: "+gd, 200, 200);
+ g.drawString("Click to exit Full-screen.", 200, 250);
+ }
+ };
+ fsf.setUndecorated(true);
+ fsf.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ gd.setFullScreenWindow(null);
+ fsf.dispose();
+ }
+ });
+ gd.setFullScreenWindow(fsf);
+ }
+ });
+ p.add(b);
+ f.add("North", p);
+
+ p = new Panel();
+ b = new Button("Test Passed");
+ b.setBackground(Color.green);
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("Test Passed");
+ f.dispose();
+ }
+ });
+ p.add(b);
+ b = new Button("Test Failed");
+ b.setBackground(Color.red);
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("Test FAILED");
+ f.dispose();
+ throw new RuntimeException("Test FAILED");
+ }
+ });
+ p.add(b);
+ f.add("South", p);
+
+ f.pack();
+ f.setVisible(true);
+ }
+}
diff --git a/test/java/awt/font/TextLayout/VisibleAdvance.java b/test/java/awt/font/TextLayout/VisibleAdvance.java
index 446d16dba..224b23861 100644
--- a/test/java/awt/font/TextLayout/VisibleAdvance.java
+++ b/test/java/awt/font/TextLayout/VisibleAdvance.java
@@ -1,3 +1,27 @@
+/*
+ * Copyright 2005-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
diff --git a/test/java/awt/image/MemoryLeakTest/MemoryLeakTest.java b/test/java/awt/image/MemoryLeakTest/MemoryLeakTest.java
new file mode 100644
index 000000000..ace1bb497
--- /dev/null
+++ b/test/java/awt/image/MemoryLeakTest/MemoryLeakTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 1998-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4078566 6658398
+ @summary Test for a memory leak in Image.
+ @run main/manual MemoryLeakTest
+*/
+
+import java.applet.Applet;
+import java.lang.*;
+import java.awt.*;
+import java.awt.event.*;
+
+class Globals {
+ static boolean testPassed=false;
+ static Thread mainThread=null;
+}
+
+public class MemoryLeakTest extends Applet {
+
+public static void main(String args[]) throws Exception {
+ new TestDialog(new Frame(), "MemoryLeakTest").start();
+ new MemoryLeak().start();
+ Globals.mainThread = Thread.currentThread();
+ try {
+ Thread.sleep(300000);
+ } catch (InterruptedException e) {
+ if (!Globals.testPassed)
+ throw new Exception("MemoryLeakTest failed.");
+ }
+}
+
+}
+
+class TestDialog extends Dialog
+ implements ActionListener {
+
+TextArea output;
+Button passButton;
+Button failButton;
+String name;
+
+public TestDialog(Frame frame, String name)
+{
+ super(frame, name + " Pass/Fail Dialog");
+ this.name = name;
+ output = new TextArea(11, 50);
+ add("North", output);
+ output.append("Do the following steps on Solaris only.\n");
+ output.append("Maximize and minimize the Memory Leak Test window.\n");
+ output.append("Execute the following after minimize.\n");
+ output.append(" ps -al | egrep -i 'java|PPID'\n");
+ output.append("Examine the size of the process under SZ.\n");
+ output.append("Maximize and minimize the Memory Leak Test window again.\n");
+ output.append("Execute the following after minimize.\n");
+ output.append(" ps -al | egrep -i 'java|PPID'\n");
+ output.append("Examine the size of the process under SZ.\n");
+ output.append("If the two SZ values are the same, plus or minus one,\n");
+ output.append("then click Pass, else click Fail.");
+ Panel buttonPanel = new Panel();
+ passButton = new Button("Pass");
+ failButton = new Button("Fail");
+ passButton.addActionListener(this);
+ failButton.addActionListener(this);
+ buttonPanel.add(passButton);
+ buttonPanel.add(failButton);
+ add("South", buttonPanel);
+ pack();
+}
+
+public void start()
+{
+ show();
+}
+
+public void actionPerformed(ActionEvent event)
+{
+ if ( event.getSource() == passButton ) {
+ Globals.testPassed = true;
+ System.err.println(name + " Passed.");
+ }
+ else if ( event.getSource() == failButton ) {
+ Globals.testPassed = false;
+ System.err.println(name + " Failed.");
+ }
+ this.dispose();
+ if (Globals.mainThread != null)
+ Globals.mainThread.interrupt();
+}
+
+}
+
+
+class MemoryLeak extends Frame implements ComponentListener
+{
+private Image osImage;
+
+public MemoryLeak()
+{
+ super("Memory Leak Test");
+ setSize(200, 200);
+ addComponentListener(this);
+}
+
+public static void main(String args[])
+{
+ new MemoryLeak().start();
+}
+
+public void start()
+{
+ show();
+}
+
+public void paint(Graphics g) {
+ if (osImage != null) {
+ g.drawImage(osImage, 0, 0, this);
+ }
+}
+
+public void update(Graphics g)
+{
+ paint(g);
+}
+
+public void componentResized(ComponentEvent e)
+{
+ Image oldimage = osImage;
+ osImage = createImage(getSize().width, getSize().height);
+ Graphics g = osImage.getGraphics();
+ if (oldimage != null) {
+ g.drawImage(oldimage, 0, 0, getSize().width, getSize().height, this);
+ oldimage.flush();
+ } else {
+ g.setColor(Color.blue);
+ g.drawLine(0, 0, getSize().width, getSize().height);
+ }
+ g.dispose();
+}
+
+public void componentMoved(ComponentEvent e) {}
+
+public void componentShown(ComponentEvent e)
+{
+ osImage = createImage(getSize().width, getSize().height);
+ Graphics g = osImage.getGraphics();
+ g.setColor(Color.blue);
+ g.drawLine(0, 0, getSize().width, getSize().height);
+ g.dispose();
+}
+
+public void componentHidden(ComponentEvent e) {}
+
+}
diff --git a/test/java/awt/print/PrinterJob/PrintAWTImage.java b/test/java/awt/print/PrinterJob/PrintAWTImage.java
new file mode 100644
index 000000000..0cb3b4eb8
--- /dev/null
+++ b/test/java/awt/print/PrinterJob/PrintAWTImage.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1999-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/**
+ * @test
+ * @bug 4257262 6708509
+ * @summary Image should be sent to printer.
+* @run main/manual PrintAWTImage
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+
+public class PrintAWTImage extends Frame
+ implements ActionListener, Printable {
+
+ public Image imgJava;
+
+
+ public static void main(String args[]) {
+ PrintAWTImage f = new PrintAWTImage();
+ f.show();
+ }
+
+ public PrintAWTImage() {
+
+ Button printButton = new Button("Print");
+ setLayout(new FlowLayout());
+ add(printButton);
+ printButton.addActionListener(this);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+ pj.setPrintable(this);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ Image imgJava = Toolkit.getDefaultToolkit().getImage("duke.gif");
+ g2d.drawImage(imgJava, 0, 0, this);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+}
diff --git a/test/java/awt/print/PrinterJob/duke.gif b/test/java/awt/print/PrinterJob/duke.gif
new file mode 100644
index 000000000..ed32e0ff7
--- /dev/null
+++ b/test/java/awt/print/PrinterJob/duke.gif
Binary files differ