|
1 | 1 | /* |
2 | | - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | /* @test |
25 | | - @bug 4078566 6658398 |
26 | | - @summary Test for a memory leak in Image. |
27 | | - @run main/manual MemoryLeakTest |
28 | | -*/ |
29 | | - |
30 | | -import java.applet.Applet; |
31 | | -import java.lang.*; |
32 | | -import java.awt.*; |
33 | | -import java.awt.event.*; |
34 | | - |
35 | | -class Globals { |
36 | | - static boolean testPassed=false; |
37 | | - static Thread mainThread=null; |
38 | | -} |
39 | | - |
40 | | -public class MemoryLeakTest extends Applet { |
41 | | - |
42 | | -public static void main(String args[]) throws Exception { |
43 | | - new TestDialog(new Frame(), "MemoryLeakTest").start(); |
44 | | - new MemoryLeak().start(); |
45 | | - Globals.mainThread = Thread.currentThread(); |
46 | | - try { |
47 | | - Thread.sleep(300000); |
48 | | - } catch (InterruptedException e) { |
49 | | - if (!Globals.testPassed) |
50 | | - throw new Exception("MemoryLeakTest failed."); |
51 | | - } |
52 | | -} |
53 | | - |
54 | | -} |
55 | | - |
56 | | -class TestDialog extends Dialog |
57 | | - implements ActionListener { |
58 | | - |
59 | | -TextArea output; |
60 | | -Button passButton; |
61 | | -Button failButton; |
62 | | -String name; |
63 | | - |
64 | | -public TestDialog(Frame frame, String name) |
65 | | -{ |
66 | | - super(frame, name + " Pass/Fail Dialog"); |
67 | | - this.name = name; |
68 | | - output = new TextArea(11, 50); |
69 | | - add("North", output); |
70 | | - output.append("Do the following steps on Solaris only.\n"); |
71 | | - output.append("Maximize and minimize the Memory Leak Test window.\n"); |
72 | | - output.append("Execute the following after minimize.\n"); |
73 | | - output.append(" ps -al | egrep -i 'java|PPID'\n"); |
74 | | - output.append("Examine the size of the process under SZ.\n"); |
75 | | - output.append("Maximize and minimize the Memory Leak Test window again.\n"); |
76 | | - output.append("Execute the following after minimize.\n"); |
77 | | - output.append(" ps -al | egrep -i 'java|PPID'\n"); |
78 | | - output.append("Examine the size of the process under SZ.\n"); |
79 | | - output.append("If the two SZ values are the same, plus or minus one,\n"); |
80 | | - output.append("then click Pass, else click Fail."); |
81 | | - Panel buttonPanel = new Panel(); |
82 | | - passButton = new Button("Pass"); |
83 | | - failButton = new Button("Fail"); |
84 | | - passButton.addActionListener(this); |
85 | | - failButton.addActionListener(this); |
86 | | - buttonPanel.add(passButton); |
87 | | - buttonPanel.add(failButton); |
88 | | - add("South", buttonPanel); |
89 | | - pack(); |
90 | | -} |
91 | | - |
92 | | -public void start() |
93 | | -{ |
94 | | - show(); |
95 | | -} |
| 25 | + * @bug 4078566 6658398 |
| 26 | + * @requires (os.family == "linux") |
| 27 | + * @library /java/awt/regtesthelpers |
| 28 | + * @build PassFailJFrame |
| 29 | + * @summary Test for a memory leak in Image. |
| 30 | + * @run main/manual MemoryLeakTest |
| 31 | + */ |
96 | 32 |
|
97 | | -public void actionPerformed(ActionEvent event) |
98 | | -{ |
99 | | - if ( event.getSource() == passButton ) { |
100 | | - Globals.testPassed = true; |
101 | | - System.err.println(name + " Passed."); |
102 | | - } |
103 | | - else if ( event.getSource() == failButton ) { |
104 | | - Globals.testPassed = false; |
105 | | - System.err.println(name + " Failed."); |
| 33 | +import java.awt.Color; |
| 34 | +import java.awt.Frame; |
| 35 | +import java.awt.Graphics; |
| 36 | +import java.awt.Image; |
| 37 | +import java.awt.event.ComponentEvent; |
| 38 | +import java.awt.event.ComponentListener; |
| 39 | + |
| 40 | +public class MemoryLeakTest { |
| 41 | + private static final String INSTRUCTIONS = |
| 42 | + """ |
| 43 | + Do the following steps on Unix platforms. |
| 44 | + Maximize and minimize the Memory Leak Test window. |
| 45 | + Execute the following after minimize. |
| 46 | + ps -al | egrep -i 'java|PPID' |
| 47 | + Examine the size of the process under SZ. |
| 48 | + Maximize and minimize the Memory Leak Test window again. |
| 49 | + Execute the following after minimize. |
| 50 | + ps -al | egrep -i 'java|PPID' |
| 51 | + Examine the size of the process under SZ. |
| 52 | + If the two SZ values are the same, plus or minus one, |
| 53 | + then click Pass, else click Fail. |
| 54 | + """; |
| 55 | + |
| 56 | + public static void main(String[] args) throws Exception { |
| 57 | + PassFailJFrame |
| 58 | + .builder() |
| 59 | + .title("MemoryLeakTest Instructions") |
| 60 | + .instructions(INSTRUCTIONS) |
| 61 | + .rows(15) |
| 62 | + .columns(40) |
| 63 | + .testUI(MemoryLeak::new) |
| 64 | + .build() |
| 65 | + .awaitAndCheck(); |
106 | 66 | } |
107 | | - this.dispose(); |
108 | | - if (Globals.mainThread != null) |
109 | | - Globals.mainThread.interrupt(); |
110 | 67 | } |
111 | 68 |
|
112 | | -} |
| 69 | +class MemoryLeak extends Frame implements ComponentListener { |
| 70 | + private Image osImage; |
113 | 71 |
|
| 72 | + public MemoryLeak() { |
| 73 | + super("Memory Leak Test"); |
| 74 | + setSize(200, 200); |
| 75 | + addComponentListener(this); |
| 76 | + } |
114 | 77 |
|
115 | | -class MemoryLeak extends Frame implements ComponentListener |
116 | | -{ |
117 | | -private Image osImage; |
| 78 | + public static void main(String[] args) { |
| 79 | + new MemoryLeak().start(); |
| 80 | + } |
118 | 81 |
|
119 | | -public MemoryLeak() |
120 | | -{ |
121 | | - super("Memory Leak Test"); |
122 | | - setSize(200, 200); |
123 | | - addComponentListener(this); |
124 | | -} |
| 82 | + public void start() { |
| 83 | + setVisible(true); |
| 84 | + } |
125 | 85 |
|
126 | | -public static void main(String args[]) |
127 | | -{ |
128 | | - new MemoryLeak().start(); |
129 | | -} |
| 86 | + public void paint(Graphics g) { |
| 87 | + if (osImage != null) { |
| 88 | + g.drawImage(osImage, 0, 0, this); |
| 89 | + } |
| 90 | + } |
130 | 91 |
|
131 | | -public void start() |
132 | | -{ |
133 | | - show(); |
134 | | -} |
| 92 | + public void update(Graphics g) { |
| 93 | + paint(g); |
| 94 | + } |
135 | 95 |
|
136 | | -public void paint(Graphics g) { |
137 | | - if (osImage != null) { |
138 | | - g.drawImage(osImage, 0, 0, this); |
| 96 | + public void componentResized(ComponentEvent e) { |
| 97 | + Image oldimage = osImage; |
| 98 | + osImage = createImage(getSize().width, getSize().height); |
| 99 | + Graphics g = osImage.getGraphics(); |
| 100 | + if (oldimage != null) { |
| 101 | + g.drawImage(oldimage, 0, 0, getSize().width, getSize().height, this); |
| 102 | + oldimage.flush(); |
| 103 | + } else { |
| 104 | + g.setColor(Color.blue); |
| 105 | + g.drawLine(0, 0, getSize().width, getSize().height); |
| 106 | + } |
| 107 | + g.dispose(); |
139 | 108 | } |
140 | | -} |
141 | 109 |
|
142 | | -public void update(Graphics g) |
143 | | -{ |
144 | | - paint(g); |
145 | | -} |
| 110 | + public void componentMoved(ComponentEvent e) {} |
146 | 111 |
|
147 | | -public void componentResized(ComponentEvent e) |
148 | | -{ |
149 | | - Image oldimage = osImage; |
150 | | - osImage = createImage(getSize().width, getSize().height); |
151 | | - Graphics g = osImage.getGraphics(); |
152 | | - if (oldimage != null) { |
153 | | - g.drawImage(oldimage, 0, 0, getSize().width, getSize().height, this); |
154 | | - oldimage.flush(); |
155 | | - } else { |
| 112 | + public void componentShown(ComponentEvent e) { |
| 113 | + osImage = createImage(getSize().width, getSize().height); |
| 114 | + Graphics g = osImage.getGraphics(); |
156 | 115 | g.setColor(Color.blue); |
157 | 116 | g.drawLine(0, 0, getSize().width, getSize().height); |
| 117 | + g.dispose(); |
158 | 118 | } |
159 | | - g.dispose(); |
160 | | -} |
161 | | - |
162 | | -public void componentMoved(ComponentEvent e) {} |
163 | | - |
164 | | -public void componentShown(ComponentEvent e) |
165 | | -{ |
166 | | - osImage = createImage(getSize().width, getSize().height); |
167 | | - Graphics g = osImage.getGraphics(); |
168 | | - g.setColor(Color.blue); |
169 | | - g.drawLine(0, 0, getSize().width, getSize().height); |
170 | | - g.dispose(); |
171 | | -} |
172 | 119 |
|
173 | | -public void componentHidden(ComponentEvent e) {} |
| 120 | + public void componentHidden(ComponentEvent e) {} |
174 | 121 |
|
175 | 122 | } |
0 commit comments