From 124e866c23c5eff007c24206450cf9cda5b361d5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 4 Oct 2015 01:31:55 +0200 Subject: Bug 1245: Adding Unit Test, similar to TestBug816JTabbedPanelVisibilityB849B878AWT TestBug1245JTabbedPanelCrashAWT passed as expected on GNU/Linux, Debian8, amd64 w/: - proprietary NV - GL_RENDERER = Gallium 0.4 on AMD ARUBA GL_VERSION = 3.0 Mesa 10.3.2 GL_VENDOR = X.Org --- .../jogl/awt/TestBug1245JTabbedPanelCrashAWT.java | 228 +++++++++++++++++++++ .../test/junit/jogl/demos/es2/RedSquareES2.java | 32 ++- 2 files changed, 251 insertions(+), 9 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug1245JTabbedPanelCrashAWT.java (limited to 'src') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug1245JTabbedPanelCrashAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug1245JTabbedPanelCrashAWT.java new file mode 100644 index 000000000..bc52238bb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug1245JTabbedPanelCrashAWT.java @@ -0,0 +1,228 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.GLEventListenerCounter; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +/** + * Bug 1245 + *

+ * https://jogamp.org/bugzilla/show_bug.cgi?id=1245 + *

+ */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestBug1245JTabbedPanelCrashAWT extends UITestCase { + + static long durationPerTest = 500*4; // ms + static boolean manual = false; + + @SuppressWarnings("serial") + static class View3D extends JPanel { + final GLCanvas canvas; + final Animator animator; + final int num; + + public View3D(final int num) { + this.num = num; + this.setLayout(new BorderLayout()); + canvas = new GLCanvas(); + canvas.setSize(new Dimension(100, 100)); + canvas.setMinimumSize(new Dimension(100, 100)); + add(canvas, BorderLayout.CENTER); + animator = new Animator(); + animator.add(canvas); + // could do animator.start() here as well, + // just to be nice - we start/stop at add/remove Notify + } + @Override + public void addNotify() { + System.err.println("View3D["+num+"].addNotify()"); + super.addNotify(); + if( null != animator ) { + animator.start(); + } + } + @Override + public void removeNotify() { + System.err.println("View3D["+num+"].removeNotify()"); + if( null != animator ) { + animator.stop(); + } + super.removeNotify(); + } + + public String getGLCanvasStats() { + return "GLCanvas: comp "+canvas.getBounds()+", visible "+canvas.isVisible()+", showing "+canvas.isShowing()+ + ", displayable "+canvas.isDisplayable()+", "+canvas.getSurfaceWidth()+"x"+canvas.getSurfaceHeight()+ + ", "+canvas.getChosenGLCapabilities()+", drawable 0x"+Long.toHexString(canvas.getHandle()); + } + } + + final GLEventListenerCounter glelCounter = new GLEventListenerCounter(); + + private JTabbedPane createAndShowGUI(final JFrame frame, final View3D[] views) { + final JPanel panel = new JPanel(new GridLayout(1, 1)); + final JTabbedPane tabbedPanel = new JTabbedPane(); + for(int i=0; i= views.length); + } + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + System.err.println("XXX SetVisible OFF XXX"); + frame.dispose(); + } }); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, false)); + System.err.println("XXX POST.DISPOSE: "+glelCounter); + } + + void switchTab(final JTabbedPane tabbedPanel, final View3D[] views, final int thisId, final int nextId) throws InvocationTargetException, InterruptedException { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + System.err.println("XXXX Panel("+id(views[thisId])+" -> Panel("+id(views[nextId])+") START"); + tabbedPanel.setSelectedIndex(nextId); + }}); + } + + public static void main(final String args[]) { + for(int i=0; i