aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java235
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java22
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java24
3 files changed, 280 insertions, 1 deletions
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<cc; i++) {
+ final Component e = c.getComponent(i);
+ // System.err.println("["+depth+"]["+i+"]: "+e.getClass().getSimpleName()+": "+e);
+ if( e instanceof AbstractButton ) {
+ final AbstractButton b = (AbstractButton) e;
+ final String bT = b.getText();
+ if( buttonText.equals(bT) ) {
+ res = b;
+ }
+ } else if( e instanceof Container ) {
+ res = findButton(depth+1, (Container)e, buttonText);
+ }
+ }
+ return res;
+ }
+
+ private void oneTest(final GLCapabilitiesImmutable caps) {
+ // base dialog
+ final JDialog dialog = new JDialog((Window) null);
+ dialog.setMinimumSize(new Dimension(500, 300));
+ dialog.setPreferredSize(new Dimension(500, 300));
+
+ dialog.setModal(false);
+
+ // build accessory
+ final GLEventListenerCounter glelc1 = new GLEventListenerCounter();
+ final GLCanvas canvas1 = new GLCanvas(caps);
+ canvas1.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Pre-ToolTip", false, false, false));
+ canvas1.addGLEventListener(new GLClearColor(1f, 0f, 0f, 1f));
+ canvas1.addGLEventListener(glelc1);
+ final JPanel panel1 = new JPanel(new BorderLayout());
+ panel1.add(canvas1, BorderLayout.CENTER);
+ panel1.setPreferredSize(new Dimension(300, 300));
+
+ final GLEventListenerCounter glelc2 = new GLEventListenerCounter();
+ final GLCanvas canvas2 = new GLCanvas(caps);
+ canvas2.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Post-ToolTip", false, false, false));
+ canvas2.addGLEventListener(new GLClearColor(0f, 0f, 1f, 1f));
+ canvas2.addGLEventListener(glelc2);
+ final JPanel panel2 = new JPanel(new BorderLayout());
+ panel2.add(canvas2, BorderLayout.CENTER);
+ panel2.setPreferredSize(new Dimension(300, 300));
+
+ // create file chooser with accessory
+ final JFileChooser fileChooser = new JFileChooser();
+ final String approveButtonText = "Approved";
+ fileChooser.setApproveButtonText(approveButtonText);
+ fileChooser.setApproveButtonToolTipText("Tool-Tip for Approved");
+ fileChooser.setAccessory(panel1);
+
+ final Locale l = fileChooser.getLocale();
+ final String cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l);
+
+ // launch robot action ..
+ new Thread()
+ {
+ public void run()
+ {
+ try {
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(fileChooser, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas1, true));
+
+ final Point approveButtonPos;
+ final AbstractButton approveButton = findButton(0, fileChooser, approveButtonText);
+ if( null != approveButton ) {
+ approveButtonPos = approveButton.getLocationOnScreen();
+ approveButtonPos.translate(2, 2);
+ System.err.println("OK Button: "+approveButton.getClass().getSimpleName()+"; "+approveButton+", "+approveButtonPos);
+ } else {
+ System.err.println("OK Button: NULL");
+ approveButtonPos = null;
+ }
+ final Point cancelButtonPos;
+ final AbstractButton cancelButton = findButton(0, fileChooser, cancelButtonText);
+ if( null != approveButton ) {
+ cancelButtonPos = cancelButton.getLocationOnScreen();
+ cancelButtonPos.translate(2, 2);
+ System.err.println("CANCEL Button: "+cancelButton.getClass().getSimpleName()+"; "+cancelButton+", "+cancelButtonPos);
+ } else {
+ cancelButtonPos = null;
+ System.err.println("CANCEL Button: NULL");
+ }
+ final Robot robot = new Robot();
+ // hover to 'approve' -> 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) {