From f60a737b18d6763ac1f443fce0b61c844666e2a8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 24 Jul 2015 02:12:06 +0200 Subject: Bug 1146, Bug 1158: Add unit test for GLContext creation after showing tool-tip within JDialog Test passes on GNU/Linux X11 and Windows - both using NVidia driver. Unit test is based on Robin Provost's code as attached in Bug 1158. --- .../TestBug1146GLContextDialogToolTipAWT.java | 235 +++++++++++++++++++++ .../opengl/test/junit/util/AWTRobotUtil.java | 22 ++ .../jogamp/opengl/test/junit/util/DumpGLInfo.java | 24 ++- 3 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java (limited to 'src/test/com/jogamp') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java new file mode 100644 index 000000000..656cb47bd --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java @@ -0,0 +1,235 @@ +/** + * Copyright 2015 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.acore; + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Window; +import java.lang.reflect.InvocationTargetException; +import java.util.Locale; + +import javax.swing.AbstractButton; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.os.Platform; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLCapabilitiesImmutable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; +import com.jogamp.opengl.test.junit.util.GLClearColor; +import com.jogamp.opengl.test.junit.util.GLEventListenerCounter; +import com.jogamp.opengl.test.junit.util.UITestCase; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestBug1146GLContextDialogToolTipAWT extends UITestCase { + static final int NB_TEST = 5; + static final int ACTION_DELAY = 500; + static final int MOVE_DELAY = 2; + static final int MOVE_ITER = 100; + static final int TOOLTIP_WAIT = 3*1000; // 5s + + static AbstractButton findButton(final int depth, final Container c, final String buttonText) { + AbstractButton res = null; + final int cc = c.getComponentCount(); + for(int i=0; null==res && i tool tip + if( null != approveButtonPos ) { + AWTRobotUtil.mouseMove(robot, approveButtonPos, MOVE_ITER, MOVE_DELAY); + Thread.sleep(TOOLTIP_WAIT); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + fileChooser.setAccessory(panel2); + fileChooser.validate(); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas2, true)); + } + if( null != cancelButtonPos ) { + AWTRobotUtil.mouseClick(robot, cancelButtonPos, MOVE_ITER, MOVE_DELAY, ACTION_DELAY); + } else { + // oops .. + fileChooser.cancelSelection(); + } + } catch (final AWTException e1) { + e1.printStackTrace(); + } catch (final InterruptedException e2) { + e2.printStackTrace(); + } + } + }.start(); + + // show file chooser dialog + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + dialog.setVisible(true); + fileChooser.showOpenDialog(dialog); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + + // dispose of resources + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + canvas1.destroy(); + canvas2.destroy(); + dialog.setVisible(false); + dialog.dispose(); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + + Assert.assertEquals(1, glelc1.initCount); + Assert.assertEquals(1, glelc2.initCount); + } + + @Test + public void test01() { + final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + for (int i = 0; i < NB_TEST; i++) { + System.out.println("Iteration " + i + " / " + NB_TEST); + oneTest(caps); + } + } + + public static void main(final String[] pArgs) + { + org.junit.runner.JUnitCore.main(TestBug1146GLContextDialogToolTipAWT.class.getName()); + } +} \ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java index d9e9fc0cb..bdb03ba1d 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -36,7 +36,10 @@ import java.lang.reflect.InvocationTargetException; import java.util.concurrent.atomic.AtomicInteger; import java.awt.AWTException; import java.awt.EventQueue; +import java.awt.MouseInfo; +import java.awt.Point; import java.awt.Robot; +import java.awt.event.InputEvent; import com.jogamp.nativewindow.NativeWindow; import com.jogamp.nativewindow.NativeWindowFactory; @@ -579,6 +582,25 @@ public class AWTRobotUtil { Assert.assertEquals("Wrong key count", typeCount, counter.getCount()-c0); } + public static void mouseMove(final Robot robot, final Point destination, final int iter, final int delay) { + final Point origin = MouseInfo.getPointerInfo().getLocation(); + for (int i = 1; i <= iter; i++) { + final float alpha = i / (float) iter; + robot.mouseMove((int) (origin.x * (1 - alpha) + destination.x * alpha), + (int) (origin.y * (1 - alpha) + destination.y * alpha)); + robot.delay(delay); + } + } + public static void mouseClick(final Robot robot, final Point pos, final int moveIter, final int moveDelay, final int actionDelay) { + robot.delay(actionDelay); + mouseMove(robot, pos, moveIter, moveDelay); + + robot.delay(actionDelay); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(actionDelay); + } + static int mouseClick(final int i, final Robot robot, final int mouseButton, final Object obj, final InputEventCountAdapter counter) throws InterruptedException, AWTException, InvocationTargetException { diff --git a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java index a2887112f..76f73989a 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java +++ b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java @@ -34,10 +34,32 @@ import com.jogamp.opengl.JoglVersion; public class DumpGLInfo implements GLEventListener { + final String header; + final boolean withGLAvailability; + final boolean withCapabilities; + final boolean withExtensions; + + public DumpGLInfo(final String header, final boolean withGLAvailability, final boolean withCapabilities, final boolean withExtensions) { + this.header = header; + this.withGLAvailability = withGLAvailability; + this.withCapabilities = withCapabilities; + this.withExtensions = withExtensions; + } + public DumpGLInfo() { + this.header = null; + this.withGLAvailability = true; + this.withCapabilities = true; + this.withExtensions = true; + } public void init(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); - System.err.println(JoglVersion.getGLInfo(gl, null, true)); + if( null != header ) { + System.err.println(header); + } + System.err.println(JoglVersion.getGLInfo(gl, null, withGLAvailability, withCapabilities, withExtensions)); + System.err.println("Drawable: "+drawable.getDelegatedDrawable().getClass().getSimpleName()); + System.err.println(drawable.getChosenGLCapabilities()); } public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { -- cgit v1.2.3