|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2024, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4188744 |
| 27 | + * @summary This test verifies that copyArea performs correctly for negative offset values. |
| 28 | + * The correct output shows that the text area is moved to the left and down, |
| 29 | + * leaving some garbage on the right and the top. |
| 30 | + * The incorrect copy would show the text area garbled and no text is legible. |
| 31 | + * @library /java/awt/regtesthelpers |
| 32 | + * @build PassFailJFrame |
| 33 | + * @run main/manual CopyNegative |
| 34 | + */ |
| 35 | + |
| 36 | +import java.awt.Color; |
| 37 | +import java.awt.Dimension; |
| 38 | +import java.awt.Frame; |
| 39 | +import java.awt.Graphics; |
| 40 | +import java.awt.Image; |
| 41 | +import java.awt.Panel; |
| 42 | + |
| 43 | +public class CopyNegative extends Panel { |
| 44 | + |
| 45 | + private static final String INSTRUCTIONS = """ |
| 46 | + This test verifies that copyArea performs correctly for negative offset values. |
| 47 | + The test draws text in an image, then copies the contents repeatedly. |
| 48 | + The correct output shows that the text is moved to the left and down, |
| 49 | + leaving some garbage on the top / right and some legible text at the bottom left. |
| 50 | + The incorrect copy would show the whole text area garbled and no text is legible. |
| 51 | + """; |
| 52 | + |
| 53 | + public static void main(String[] argv) throws Exception { |
| 54 | + PassFailJFrame.builder() |
| 55 | + .title("CopyNegativeTest") |
| 56 | + .instructions(INSTRUCTIONS) |
| 57 | + .testUI(CopyNegative::createUI) |
| 58 | + .testTimeOut(5) |
| 59 | + .rows(10) |
| 60 | + .columns(50) |
| 61 | + .build() |
| 62 | + .awaitAndCheck(); |
| 63 | + } |
| 64 | + |
| 65 | + Image img; |
| 66 | + |
| 67 | + static final int W = 200, H = 200; |
| 68 | + |
| 69 | + static Frame createUI() { |
| 70 | + Frame f = new Frame("CopyNegative"); |
| 71 | + f.add(new CopyNegative()); |
| 72 | + f.pack(); |
| 73 | + return f; |
| 74 | + } |
| 75 | + |
| 76 | + public Dimension getPreferredSize() { |
| 77 | + return new Dimension(W, H); |
| 78 | + } |
| 79 | + |
| 80 | + private void doCopy() { |
| 81 | + Graphics g = img.getGraphics(); |
| 82 | + g.setColor(Color.white); |
| 83 | + g.fillRect(0, 0, W, H); |
| 84 | + g.setColor(Color.black); |
| 85 | + String text = "Some Text To Display, it is long enough to fill the entire display line."; |
| 86 | + StringBuffer sb = new StringBuffer(text); |
| 87 | + |
| 88 | + for (int i = 1; i < 50; i++) { |
| 89 | + g.drawString(sb.toString(), 5,20 * i - 10); |
| 90 | + sb.insert(0, Integer.toString(i)); |
| 91 | + } |
| 92 | + for (int i = 0 ; i < 20 ; i++ ) { |
| 93 | + g.copyArea(0, 0, W, H, -3, 3); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public void paint(Graphics g) { |
| 98 | + img = createImage(W, H); |
| 99 | + doCopy(); |
| 100 | + g.drawImage(img, 0, 0, this); |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments