1 /* 2 * Copyright (c) 2011, 2013, 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 @summary <rdar://problem/3132190> Painting: We paint twice on startup 27 @summary com.apple.junit.java.awt.Event; 28 @run main TestDoublePaint 29 */ 30 import junit.framework.*; 31 import javax.swing.*; 32 import java.awt.*; 33 import sun.awt.SunToolkit; 34 35 public class TestDoublePaint extends TestCase { 36 37 JFrame f = null; 38 int numberOfRepaints = 0; 39 40 protected void setUp() { 41 try { 42 SwingUtilities.invokeAndWait(new Runnable() { 43 @Override 44 public void run() { 45 f = new JFrame("Double Paint Tester"); 46 f.setSize(600, 300); 47 TestPanel p = new TestPanel(); 48 JPanel root = new JPanel(); 49 root.setLayout(new BorderLayout()); 50 root.add(BorderLayout.CENTER, p); 51 f.setContentPane(root); 52 f.setVisible(true); 53 } 54 }); 55 } catch (Exception ex) { 56 throw new RuntimeException(ex); 57 } 58 } 59 60 protected void tearDown() { 61 f.dispose(); 62 } 63 64 public static Test suite() { 65 return new TestSuite(TestDoublePaint.class); 66 } 67 68 public void testDoubleRepaint() throws Exception { 69 ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); 70 assertTrue("There are 2 or more repaints on start-up", numberOfRepaints == 1); 71 } 72 73 class TestPanel extends JComponent { 74 75 public void paint(Graphics g) { 76 numberOfRepaints++; 77 } 78 } 79 80 public static void main(String[] args) throws RuntimeException { 81 TestResult tr = junit.textui.TestRunner.run(suite()); 82 if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) { 83 throw new RuntimeException("### Unexpected errors or failures."); 84 } 85 } 86 }