summaryrefslogtreecommitdiffstats
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/TestAddRemove01GLCanvasSwingAWT.java241
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java246
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove03GLWindowNEWT.java130
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java160
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java11
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch01NEWT.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch11NEWT.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer01GLCanvasAWT.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug664GLCanvasSetVisibleSwingAWT.java283
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java111
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java125
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java19
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java192
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java375
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java340
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java33
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java14
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java45
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java59
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java55
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java113
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java52
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java21
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java32
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyPressReleaseUnmaskRepeatAWT.java26
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java1
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java83
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java136
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java11
37 files changed, 2714 insertions, 301 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
new file mode 100644
index 000000000..ce8f9adc8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
@@ -0,0 +1,241 @@
+/**
+ * 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.acore;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import jogamp.nativewindow.jawt.JAWTUtil;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
+ static long durationPerTest = 50;
+ static int addRemoveCount = 15;
+ static boolean noOnscreenTest = false;
+ static boolean noOffscreenTest = false;
+ static boolean shallUseOffscreenPBufferLayer = false;
+ static GLProfile glp;
+ static int width, height;
+ static boolean waitForKey = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
+ throws InterruptedException, InvocationTargetException
+ {
+ final JPanel[] jPanel = new JPanel[] { null };
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jPanel[0] = new JPanel();
+ jPanel[0].setLayout(new BorderLayout());
+
+ final JFrame jFrame1 = new JFrame("JFrame #"+num);
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.getContentPane().add(jPanel[0]);
+ jFrame1.setSize(width, height);
+
+ top[0] = jFrame1;
+ } } );
+ return jPanel[0];
+ }
+
+ protected void add(final Container cont, final Component comp)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ cont.add(comp, BorderLayout.CENTER);
+ } } );
+ }
+
+ protected void dispose(final GLCanvas glc)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ glc.destroy();
+ } } );
+ }
+
+ protected void setVisible(final JFrame jFrame, final boolean visible) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ if( visible ) {
+ jFrame.pack();
+ jFrame.validate();
+ }
+ jFrame.setVisible(visible);
+ } } ) ;
+ }
+
+ protected void dispose(final JFrame jFrame) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame.dispose();
+ } } ) ;
+ }
+
+ protected void runTestGL(boolean onscreen, GLCapabilities caps, int addRemoveOpCount)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+
+ for(int i=0; i<addRemoveOpCount; i++) {
+ System.err.println("Loop # "+i+" / "+addRemoveCount);
+ final GLCanvas glc = new GLCanvas(caps);
+ Assert.assertNotNull(glc);
+ if( !onscreen ) {
+ glc.setShallUseOffscreenLayer(true);
+ }
+ Dimension glc_sz = new Dimension(width, height);
+ glc.setMinimumSize(glc_sz);
+ glc.setPreferredSize(glc_sz);
+ glc.setSize(glc_sz);
+ final GearsES2 gears = new GearsES2(1);
+ gears.setVerbose(false);
+ glc.addGLEventListener(gears);
+
+ final JFrame[] top = new JFrame[] { null };
+ final Container glcCont = create(top, width, height, i);
+ add(glcCont, glc);
+
+ setVisible(top[0], true);
+
+ final long t0 = System.currentTimeMillis();
+ do {
+ glc.display();
+ Thread.sleep(10);
+ } while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
+
+ System.err.println("GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
+
+ dispose(top[0]);
+ }
+ }
+
+ @Test
+ public void test01Onscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( noOnscreenTest || JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("No onscreen test requested or platform doesn't support onscreen rendering.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(glp);
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(true, caps, addRemoveCount);
+ }
+
+ @Test
+ public void test02Offscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("No offscreen test requested or platform doesn't support offscreen rendering.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(glp);
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(false, caps, addRemoveCount);
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ durationPerTest = Long.parseLong(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-loops")) {
+ i++;
+ try {
+ addRemoveCount = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-noOnscreen")) {
+ noOnscreenTest = true;
+ } else if(args[i].equals("-noOffscreen")) {
+ noOffscreenTest = true;
+ } else if(args[i].equals("-layeredPBuffer")) {
+ shallUseOffscreenPBufferLayer = true;
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ System.err.println("waitForKey "+waitForKey);
+
+ System.err.println("addRemoveCount "+addRemoveCount);
+
+ System.err.println("noOnscreenTest "+noOnscreenTest);
+ System.err.println("noOffscreenTest "+noOffscreenTest);
+ System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
+ if(waitForKey) {
+ UITestCase.waitForKey("Start");
+ }
+ org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java
new file mode 100644
index 000000000..3d78943f9
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java
@@ -0,0 +1,246 @@
+/**
+ * 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.acore;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import jogamp.nativewindow.jawt.JAWTUtil;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase {
+ static long durationPerTest = 50;
+ static int addRemoveCount = 15;
+ static boolean noOnscreenTest = false;
+ static boolean noOffscreenTest = false;
+ static boolean shallUseOffscreenPBufferLayer = false;
+ static GLProfile glp;
+ static int width, height;
+ static boolean waitForKey = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
+ throws InterruptedException, InvocationTargetException
+ {
+ final JPanel[] jPanel = new JPanel[] { null };
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jPanel[0] = new JPanel();
+ jPanel[0].setLayout(new BorderLayout());
+
+ final JFrame jFrame1 = new JFrame("JFrame #"+num);
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.getContentPane().add(jPanel[0]);
+ jFrame1.setSize(width, height);
+
+ top[0] = jFrame1;
+ } } );
+ return jPanel[0];
+ }
+
+ protected void add(final Container cont, final Component comp)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ cont.add(comp, BorderLayout.CENTER);
+ } } );
+ }
+
+ protected void dispose(final GLCanvas glc)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ glc.destroy();
+ } } );
+ }
+
+ protected void setVisible(final JFrame jFrame, final boolean visible) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ if( visible ) {
+ jFrame.pack();
+ jFrame.validate();
+ }
+ jFrame.setVisible(visible);
+ } } ) ;
+ }
+
+ protected void dispose(final JFrame jFrame) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame.dispose();
+ } } ) ;
+ }
+
+ protected void runTestGL(boolean onscreen, GLCapabilities caps, int addRemoveOpCount)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+
+ for(int i=0; i<addRemoveOpCount; i++) {
+ System.err.println("Loop # "+i+" / "+addRemoveCount);
+ final GLWindow glw = GLWindow.create(caps);
+ Assert.assertNotNull(glw);
+ final NewtCanvasAWT glc = new NewtCanvasAWT(glw);
+ Assert.assertNotNull(glc);
+ if( !onscreen ) {
+ glc.setShallUseOffscreenLayer(true);
+ }
+ Dimension glc_sz = new Dimension(width, height);
+ glc.setMinimumSize(glc_sz);
+ glc.setPreferredSize(glc_sz);
+ glc.setSize(glc_sz);
+ final GearsES2 gears = new GearsES2(1);
+ gears.setVerbose(false);
+ glw.addGLEventListener(gears);
+
+ final JFrame[] top = new JFrame[] { null };
+ final Container glcCont = create(top, width, height, i);
+ add(glcCont, glc);
+
+ setVisible(top[0], true);
+
+ final long t0 = System.currentTimeMillis();
+ do {
+ glw.display();
+ Thread.sleep(10);
+ } while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
+
+ System.err.println("GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glw.getChosenGLCapabilities());
+
+ dispose(top[0]);
+ glw.destroy();
+ }
+ }
+
+ @Test
+ public void test01Onscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( noOnscreenTest || JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("No onscreen test requested or platform doesn't support onscreen rendering.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(glp);
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(true, caps, addRemoveCount);
+ }
+
+ @Test
+ public void test02Offscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("No offscreen test requested or platform doesn't support offscreen rendering.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(glp);
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(false, caps, addRemoveCount);
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ durationPerTest = Long.parseLong(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-loops")) {
+ i++;
+ try {
+ addRemoveCount = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-noOnscreen")) {
+ noOnscreenTest = true;
+ } else if(args[i].equals("-noOffscreen")) {
+ noOffscreenTest = true;
+ } else if(args[i].equals("-layeredPBuffer")) {
+ shallUseOffscreenPBufferLayer = true;
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ System.err.println("waitForKey "+waitForKey);
+
+ System.err.println("addRemoveCount "+addRemoveCount);
+
+ System.err.println("noOnscreenTest "+noOnscreenTest);
+ System.err.println("noOffscreenTest "+noOffscreenTest);
+ System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
+ if(waitForKey) {
+ UITestCase.waitForKey("Start");
+ }
+ org.junit.runner.JUnitCore.main(TestAddRemove02GLWindowNewtCanvasAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove03GLWindowNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove03GLWindowNEWT.java
new file mode 100644
index 000000000..9d7a4026b
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove03GLWindowNEWT.java
@@ -0,0 +1,130 @@
+/**
+ * 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.acore;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestAddRemove03GLWindowNEWT extends UITestCase {
+ static long durationPerTest = 50;
+ static int addRemoveCount = 15;
+ static GLProfile glp;
+ static int width, height;
+ static boolean waitForKey = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps, int addRemoveOpCount)
+ throws InterruptedException, InvocationTargetException
+ {
+
+ for(int i=0; i<addRemoveOpCount; i++) {
+ System.err.println("Loop # "+i+" / "+addRemoveCount);
+ final GLWindow glw = GLWindow.create(caps);
+ Assert.assertNotNull(glw);
+ glw.setTitle("GLWindow #"+i);
+ glw.setSize(width, height);
+ final GearsES2 gears = new GearsES2(1);
+ gears.setVerbose(false);
+ glw.addGLEventListener(gears);
+
+ glw.setVisible(true);
+
+ final long t0 = System.currentTimeMillis();
+ do {
+ glw.display();
+ Thread.sleep(10);
+ } while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
+
+ System.err.println("GLWindow: "+glw.getChosenGLCapabilities());
+
+ glw.destroy();
+ }
+ }
+
+ @Test
+ public void test01Onscreen()
+ throws InterruptedException, InvocationTargetException
+ {
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps, addRemoveCount);
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ durationPerTest = Long.parseLong(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-loops")) {
+ i++;
+ try {
+ addRemoveCount = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ System.err.println("waitForKey "+waitForKey);
+
+ System.err.println("addRemoveCount "+addRemoveCount);
+
+ if(waitForKey) {
+ UITestCase.waitForKey("Start");
+ }
+ org.junit.runner.JUnitCore.main(TestAddRemove03GLWindowNEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java
new file mode 100644
index 000000000..2729d6a5d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java
@@ -0,0 +1,160 @@
+/**
+ * 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.acore;
+
+import java.io.IOException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowUpdateEvent;
+import com.jogamp.opengl.GLAutoDrawableDelegate;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+/**
+ * Test using a NEWT {@link Window} for onscreen case.
+ * <p>
+ * Creates a {@link GLDrawable} using the
+ * {@link GLDrawableFactory#createGLDrawable(javax.media.nativewindow.NativeSurface) factory model}.
+ * The {@link GLContext} is derived {@link GLDrawable#createContext(GLContext) from the drawable}.
+ * </p>
+ * <p>
+ * Finally a {@link GLAutoDrawableDelegate} is created with the just created {@link GLDrawable} and {@link GLContext}.
+ * It is being used to run the {@link GLEventListener}.
+ * </p>
+ */
+public class TestGLAutoDrawableDelegateNEWT extends UITestCase {
+ static long duration = 500; // ms
+
+ void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException {
+ final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile());
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ final Window window = NewtFactory.createWindow(reqGLCaps);
+ Assert.assertNotNull(window);
+ window.setSize(640, 400);
+ window.setVisible(true);
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(window, true));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, true));
+ System.out.println("Window: "+window.getClass().getName());
+
+ final GLDrawable drawable = factory.createGLDrawable(window);
+ Assert.assertNotNull(drawable);
+ drawable.setRealized(true);
+
+ final GLAutoDrawableDelegate glad = new GLAutoDrawableDelegate(drawable, drawable.createContext(null), window, false, null) {
+ @Override
+ protected void destroyImplInLock() {
+ super.destroyImplInLock(); // destroys drawable/context
+ window.destroy(); // destroys the actual window, incl. the device
+ }
+ };
+
+ window.setWindowDestroyNotifyAction( new Runnable() {
+ public void run() {
+ glad.windowDestroyNotifyOp();
+ } } );
+
+ window.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowRepaint(WindowUpdateEvent e) {
+ glad.windowRepaintOp();
+ }
+
+ @Override
+ public void windowResized(WindowEvent e) {
+ glad.windowResizedOp(window.getWidth(), window.getHeight());
+ }
+ });
+
+ glad.addGLEventListener(demo);
+
+ QuitAdapter quitAdapter = new QuitAdapter();
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ window.addKeyListener(quitAdapter);
+ window.addWindowListener(quitAdapter);
+
+ Animator animator = new Animator();
+ animator.setUpdateFPSFrames(60, System.err);
+ animator.setModeBits(false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD);
+ animator.add(glad);
+ animator.start();
+ Assert.assertTrue(animator.isStarted());
+ Assert.assertTrue(animator.isAnimating());
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ Thread.sleep(100);
+ }
+ System.out.println("Fin start ...");
+
+ animator.stop();
+ Assert.assertFalse(animator.isAnimating());
+ Assert.assertFalse(animator.isStarted());
+ glad.destroy();
+ System.out.println("Fin Drawable: "+drawable);
+ System.out.println("Fin Window: "+window);
+ }
+
+ @Test
+ public void testOnScreenDblBuf() throws InterruptedException {
+ final GLCapabilities reqGLCaps = new GLCapabilities( GLProfile.getGL2ES2() );
+ doTest(reqGLCaps, new GearsES2(1));
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGLAutoDrawableDelegateNEWT.class.getName());
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java
index c5b4227c2..050e596cf 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java
@@ -55,6 +55,7 @@ import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import jogamp.newt.WindowImpl;
/**
* Tests using a NEWT {@link Window} for on- and offscreen cases.
@@ -169,6 +170,11 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase {
}
};
+ window.setWindowDestroyNotifyAction( new Runnable() {
+ public void run() {
+ glad.windowDestroyNotifyOp();
+ } } );
+
window.addWindowListener(new WindowAdapter() {
@Override
public void windowRepaint(WindowUpdateEvent e) {
@@ -179,11 +185,6 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase {
public void windowResized(WindowEvent e) {
glad.windowResizedOp(window.getWidth(), window.getHeight());
}
-
- @Override
- public void windowDestroyNotify(WindowEvent e) {
- glad.windowDestroyNotifyOp();
- }
});
glad.addGLEventListener(demo);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch01NEWT.java
index 8b1449493..cce4149ba 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch01NEWT.java
@@ -107,6 +107,11 @@ public class TestGLContextDrawableSwitch01NEWT extends UITestCase {
}
};
+ window.setWindowDestroyNotifyAction( new Runnable() {
+ public void run() {
+ glad.windowDestroyNotifyOp();
+ } } );
+
// add basic window interaction
window.addWindowListener(new WindowAdapter() {
@Override
@@ -117,10 +122,6 @@ public class TestGLContextDrawableSwitch01NEWT extends UITestCase {
public void windowResized(WindowEvent e) {
glad.windowResizedOp(window.getWidth(), window.getHeight());
}
- @Override
- public void windowDestroyNotify(WindowEvent e) {
- glad.windowDestroyNotifyOp();
- }
});
window.addWindowListener(wl);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch11NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch11NEWT.java
index 4af9a3932..2ef797fba 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch11NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitch11NEWT.java
@@ -109,6 +109,11 @@ public class TestGLContextDrawableSwitch11NEWT extends UITestCase {
}
};
+ window.setWindowDestroyNotifyAction( new Runnable() {
+ public void run() {
+ glad.windowDestroyNotifyOp();
+ } } );
+
// add basic window interaction
window.addWindowListener(new WindowAdapter() {
@Override
@@ -119,10 +124,6 @@ public class TestGLContextDrawableSwitch11NEWT extends UITestCase {
public void windowResized(WindowEvent e) {
glad.windowResizedOp(window.getWidth(), window.getHeight());
}
- @Override
- public void windowDestroyNotify(WindowEvent e) {
- glad.windowDestroyNotifyOp();
- }
});
window.addWindowListener(wl);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer01GLCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer01GLCanvasAWT.java
index 90407166f..8cc094276 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer01GLCanvasAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer01GLCanvasAWT.java
@@ -33,9 +33,7 @@ import java.awt.Button;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import javax.media.opengl.GLAnimatorControl;
@@ -70,6 +68,7 @@ public class TestOffscreenLayer01GLCanvasAWT extends UITestCase {
static Dimension frameSize1;
static Dimension preferredGLSize;
static long durationPerTest = 1000;
+ static boolean waitForKey = false;
@BeforeClass
public static void initClass() {
@@ -189,7 +188,10 @@ public class TestOffscreenLayer01GLCanvasAWT extends UITestCase {
Thread.sleep(durationPerTest/2);
- end(animator1, frame1, null);
+ end(animator1, frame1, null);
+ if( waitForKey ) {
+ UITestCase.waitForKey("Continue");
+ }
}
public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
@@ -214,7 +216,6 @@ public class TestOffscreenLayer01GLCanvasAWT extends UITestCase {
}
public static void main(String args[]) throws IOException {
- boolean waitForKey = false;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
durationPerTest = atoi(args[++i]);
@@ -234,11 +235,7 @@ public class TestOffscreenLayer01GLCanvasAWT extends UITestCase {
}
}
if(waitForKey) {
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- System.err.println("Press enter to continue");
- try {
- System.err.println(stdin.readLine());
- } catch (IOException e) { }
+ UITestCase.waitForKey("Start");
}
String tstname = TestOffscreenLayer01GLCanvasAWT.class.getName();
/*
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java
index e4a3bce71..2236f4b05 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java
@@ -33,9 +33,7 @@ import java.awt.Button;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import javax.media.opengl.GLAnimatorControl;
@@ -70,6 +68,7 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
static Dimension frameSize1;
static Dimension preferredGLSize;
static long durationPerTest = 1000;
+ static boolean waitForKey = false;
@BeforeClass
public static void initClass() {
@@ -79,7 +78,6 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
}
private void setupFrameAndShow(final Frame f, java.awt.Component comp) throws InterruptedException, InvocationTargetException {
-
Container c = new Container();
c.setLayout(new BorderLayout());
c.add(new Button("north"), BorderLayout.NORTH);
@@ -169,7 +167,7 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
Assert.assertEquals(true, newtCanvasAWT1.isOffscreenLayerSurfaceEnabled());
-
+
GLAnimatorControl animator1 = new Animator(glWindow1);
if(!noAnimation) {
animator1.start();
@@ -187,6 +185,9 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
Thread.sleep(durationPerTest/2);
end(animator1, frame1, glWindow1);
+ if( waitForKey ) {
+ UITestCase.waitForKey("Continue");
+ }
}
public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
@@ -211,7 +212,6 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
}
public static void main(String args[]) throws IOException {
- boolean waitForKey = false;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
durationPerTest = atoi(args[++i]);
@@ -231,11 +231,7 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase {
}
}
if(waitForKey) {
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- System.err.println("Press enter to continue");
- try {
- System.err.println(stdin.readLine());
- } catch (IOException e) { }
+ UITestCase.waitForKey("Start");
}
String tstname = TestOffscreenLayer02NewtCanvasAWT.class.getName();
/*
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
index 7894f3e86..fbea81a54 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
@@ -68,6 +68,7 @@ import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil.WindowClosingListener;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.GLBuffers;
@@ -507,6 +508,8 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase {
*/
public void testContextSharingCreateVisibleDestroy(final boolean useNewt, final boolean shareContext) throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame("Simple JOGL App for testing context sharing");
+ final WindowClosingListener awtClosingListener = AWTRobotUtil.addClosingListener(frame);
+
//
// GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2));
// GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice());
@@ -699,7 +702,7 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase {
while(animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) {
Thread.sleep(100);
}
- AWTRobotUtil.closeWindow(frame, true);
+ AWTRobotUtil.closeWindow(frame, true, awtClosingListener);
boolean windowClosed = closingSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(true, windowClosed);
} catch (InterruptedException e) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug664GLCanvasSetVisibleSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug664GLCanvasSetVisibleSwingAWT.java
new file mode 100644
index 000000000..d59bc2230
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug664GLCanvasSetVisibleSwingAWT.java
@@ -0,0 +1,283 @@
+/**
+ * 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.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import jogamp.nativewindow.jawt.JAWTUtil;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+public class TestBug664GLCanvasSetVisibleSwingAWT extends UITestCase {
+ static long durationPerTest = 500;
+ static boolean shallUseOffscreenFBOLayer = false;
+ static boolean shallUseOffscreenPBufferLayer = false;
+ static GLProfile glp;
+ static int width, height;
+ static boolean waitForKey = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
+ throws InterruptedException, InvocationTargetException
+ {
+ final JPanel[] jPanel = new JPanel[] { null };
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jPanel[0] = new JPanel();
+ jPanel[0].setLayout(new BorderLayout());
+
+ final JFrame jFrame1 = new JFrame("JFrame #"+num);
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.getContentPane().add(jPanel[0]);
+ jFrame1.setSize(width, height);
+
+ top[0] = jFrame1;
+ } } );
+ return jPanel[0];
+ }
+
+ protected void add(final Container cont, final Component comp, final JFrame jFrame)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ cont.add(comp, BorderLayout.CENTER);
+ jFrame.pack();
+ jFrame.validate();
+ } } );
+ }
+
+ protected void dispose(final GLCanvas glc)
+ throws InterruptedException, InvocationTargetException
+ {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ glc.destroy();
+ } } );
+ }
+
+ protected void setFrameVisible(final JFrame jFrame, final boolean visible) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame.setVisible(visible);
+ } } ) ;
+ }
+
+ protected void setComponentVisible(final Component comp, final boolean visible) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ comp.setVisible(visible);
+ } } ) ;
+ }
+
+ protected void dispose(final JFrame jFrame) throws InterruptedException, InvocationTargetException {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame.dispose();
+ } } ) ;
+ }
+
+ private volatile int frameCount = 0;
+
+ protected void runTestGL(boolean onscreen, GLCapabilities caps)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+
+ for(int i=0; i<1; i++) {
+ Animator anim = new Animator();
+ final GLCanvas glc = new GLCanvas(caps);
+ Assert.assertNotNull(glc);
+ anim.add(glc);
+ if( !onscreen ) {
+ glc.setShallUseOffscreenLayer(true);
+ }
+ Dimension glc_sz = new Dimension(width, height);
+ glc.setMinimumSize(glc_sz);
+ glc.setPreferredSize(glc_sz);
+ glc.setSize(glc_sz);
+ glc.addGLEventListener(new GLEventListener() {
+ @Override
+ public void init(GLAutoDrawable drawable) {}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {}
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ frameCount++;
+ }
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ });
+ final GearsES2 gears = new GearsES2(1);
+ gears.setVerbose(false);
+ glc.addGLEventListener(gears);
+
+ final JFrame[] top = new JFrame[] { null };
+ final Container glcCont = create(top, width, height, i);
+ add(glcCont, glc, top[0]);
+
+ frameCount = 0;
+ setFrameVisible(top[0], true);
+ Assert.assertTrue("Component didn't become visible", AWTRobotUtil.waitForVisible(glc, true));
+ Assert.assertTrue("Component didn't become realized", AWTRobotUtil.waitForRealized(glc, true));
+
+ anim.setUpdateFPSFrames(60, null);
+ anim.start();
+ anim.resetFPSCounter();
+ System.err.println("Visible Part 1/3");
+
+ while( anim.getTotalFPSDuration() < durationPerTest ) {
+ Thread.sleep(60);
+ }
+
+ setComponentVisible(glc, false);
+ Assert.assertTrue("Component didn't become invisible", AWTRobotUtil.waitForVisible(glc, false));
+ final int frameCountT0 = frameCount;
+ anim.resetFPSCounter();
+ System.err.println("Invisible Part 2/3");
+
+ while( anim.getTotalFPSDuration() < durationPerTest ) {
+ Thread.sleep(60);
+ }
+
+ final int frameCountT1 = frameCount;
+ System.err.println("GLCanvas invisible frame count: Before "+frameCountT0+", after "+frameCountT1);
+ Assert.assertTrue("GLCanvas rendered more that 4 times while being invisible, before "+frameCountT0+", after "+frameCountT1,
+ 4 >= frameCountT1 - frameCountT0);
+
+ setComponentVisible(glc, true);
+ Assert.assertTrue("Component didn't become visible", AWTRobotUtil.waitForVisible(glc, true));
+ anim.resetFPSCounter();
+ System.err.println("Visible Part 3/3");
+
+ while( anim.getTotalFPSDuration() < durationPerTest ) {
+ Thread.sleep(60);
+ }
+
+ System.err.println("GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
+
+ dispose(top[0]);
+ }
+ }
+
+ @Test
+ public void test01Onscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( shallUseOffscreenFBOLayer || shallUseOffscreenPBufferLayer || JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("Offscreen test requested or platform requires it.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(true, caps);
+ }
+
+ @Test
+ public void test02Offscreen()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("Platform doesn't support offscreen test.");
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ if(shallUseOffscreenPBufferLayer) {
+ caps.setPBuffer(true);
+ caps.setOnscreen(true); // simulate normal behavior ..
+ }
+ runTestGL(false, caps);
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ durationPerTest = Long.parseLong(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-layeredFBO")) {
+ shallUseOffscreenFBOLayer = true;
+ } else if(args[i].equals("-layeredPBuffer")) {
+ shallUseOffscreenPBufferLayer = true;
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ System.err.println("waitForKey "+waitForKey);
+
+ System.err.println("shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
+ System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
+ if(waitForKey) {
+ UITestCase.waitForKey("Start");
+ }
+ org.junit.runner.JUnitCore.main(TestBug664GLCanvasSetVisibleSwingAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java
new file mode 100644
index 000000000..0c0975308
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java
@@ -0,0 +1,111 @@
+/**
+ * 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.Window;
+import java.beans.Beans;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestBug675BeansInDesignTimeAWT extends UITestCase {
+ static boolean waitForKey = false;
+ static long durationPerTest = 200;
+
+ @Test
+ public void test01() throws InterruptedException, InvocationTargetException {
+ Beans.setDesignTime(true);
+
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
+ final GLCanvas glCanvas = new GLCanvas(caps);
+ final Dimension preferredGLSize = new Dimension(400,200);
+ glCanvas.setPreferredSize(preferredGLSize);
+ glCanvas.setMinimumSize(preferredGLSize);
+ glCanvas.setSize(preferredGLSize);
+
+ glCanvas.addGLEventListener(new GearsES2());
+
+ final Window window = new JFrame(this.getSimpleTestName(" - "));
+ window.setLayout(new BorderLayout());
+ window.add(glCanvas, BorderLayout.CENTER);
+
+ // trigger realization on AWT-EDT, otherwise it won't immediatly ..
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ window.pack();
+ window.validate();
+ window.setVisible(true);
+ }
+ } );
+
+ // Immediately displayable after issuing initial setVisible(true) on AWT-EDT!
+ Assert.assertTrue("GLCanvas didn't become displayable", glCanvas.isDisplayable());
+ if( !Beans.isDesignTime() ) {
+ Assert.assertTrue("GLCanvas didn't become realized", glCanvas.isRealized());
+ }
+
+ Thread.sleep(durationPerTest);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ window.dispose();
+ }
+ } );
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ if(waitForKey) {
+ UITestCase.waitForKey("Start");
+ }
+ org.junit.runner.JUnitCore.main(TestBug675BeansInDesignTimeAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
index 9f62e4a49..aca2b675c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
@@ -40,11 +40,14 @@ import com.jogamp.newt.event.TraceKeyAdapter;
import com.jogamp.newt.event.TraceWindowAdapter;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
@@ -55,25 +58,27 @@ import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import org.junit.Assert;
+import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
public class TestGearsES2AWT extends UITestCase {
+ public enum FrameLayout { None, TextOnBottom, BorderCenterSurrounded, DoubleBorderCenterSurrounded };
static int width, height;
static boolean forceES2 = false;
static boolean forceGL3 = false;
- static boolean shallUseOffscreenLayer = false;
+ static boolean shallUseOffscreenFBOLayer = false;
static boolean shallUseOffscreenPBufferLayer = false;
static boolean useMSAA = false;
static boolean useStencil = false;
- static boolean addComp = true;
static boolean shutdownRemoveGLCanvas = true;
static boolean shutdownDisposeFrame = true;
static boolean shutdownSystemExit = false;
static int swapInterval = 1;
static boolean exclusiveContext = false;
static Thread awtEDT;
+ static Dimension rwsize = null;
@BeforeClass
public static void initClass() {
@@ -94,25 +99,70 @@ public class TestGearsES2AWT extends UITestCase {
public static void releaseClass() {
}
- protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException {
+ static void setGLCanvasSize(final Frame frame, final GLCanvas glc, final Dimension new_sz) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ glc.setMinimumSize(new_sz);
+ glc.setPreferredSize(new_sz);
+ glc.setSize(new_sz);
+ if( null != frame ) {
+ frame.pack();
+ }
+ } } );
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ protected void runTestGL(GLCapabilities caps, FrameLayout frameLayout) throws InterruptedException, InvocationTargetException {
final Frame frame = new Frame("GearsES2 AWT Test");
Assert.assertNotNull(frame);
final GLCanvas glCanvas = new GLCanvas(caps);
Assert.assertNotNull(glCanvas);
- Dimension glc_sz = new Dimension(width, height);
- glCanvas.setMinimumSize(glc_sz);
- glCanvas.setPreferredSize(glc_sz);
- glCanvas.setSize(glc_sz);
- if(addComp) {
- final TextArea ta = new TextArea(2, 20);
- ta.append("0123456789");
- ta.append(Platform.getNewline());
- ta.append("Some Text");
- ta.append(Platform.getNewline());
- frame.add(ta, BorderLayout.SOUTH);
+ setGLCanvasSize(null, glCanvas, new Dimension(width, height));
+
+ switch( frameLayout) {
+ case None:
+ frame.add(glCanvas);
+ break;
+ case TextOnBottom:
+ final TextArea ta = new TextArea(2, 20);
+ ta.append("0123456789");
+ ta.append(Platform.getNewline());
+ ta.append("Some Text");
+ ta.append(Platform.getNewline());
+ frame.setLayout(new BorderLayout());
+ frame.add(ta, BorderLayout.SOUTH);
+ frame.add(glCanvas, BorderLayout.CENTER);
+ break;
+ case BorderCenterSurrounded:
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("NORTH"), BorderLayout.NORTH);
+ frame.add(new Button("SOUTH"), BorderLayout.SOUTH);
+ frame.add(new Button("EAST"), BorderLayout.EAST);
+ frame.add(new Button("WEST"), BorderLayout.WEST);
+ frame.add(glCanvas, BorderLayout.CENTER);
+ break;
+ case DoubleBorderCenterSurrounded:
+ Container c = new Container();
+ c.setLayout(new BorderLayout());
+ c.add(new Button("north"), BorderLayout.NORTH);
+ c.add(new Button("south"), BorderLayout.SOUTH);
+ c.add(new Button("east"), BorderLayout.EAST);
+ c.add(new Button("west"), BorderLayout.WEST);
+ c.add(glCanvas, BorderLayout.CENTER);
+
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("NORTH"), BorderLayout.NORTH);
+ frame.add(new Button("SOUTH"), BorderLayout.SOUTH);
+ frame.add(new Button("EAST"), BorderLayout.EAST);
+ frame.add(new Button("WEST"), BorderLayout.WEST);
+ frame.add(c, BorderLayout.CENTER);
+ break;
}
- frame.add(glCanvas, BorderLayout.CENTER);
frame.setTitle("Gears AWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval);
glCanvas.addGLEventListener(new GearsES2(swapInterval));
@@ -130,13 +180,24 @@ public class TestGearsES2AWT extends UITestCase {
public void run() {
frame.pack();
frame.setVisible(true);
- }});
+ }});
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true));
+
animator.start();
Assert.assertTrue(animator.isStarted());
Assert.assertTrue(animator.isAnimating());
Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread());
animator.setUpdateFPSFrames(60, System.err);
+ System.err.println("canvas pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getWidth()+"x"+glCanvas.getHeight());
+
+ if( null != rwsize ) {
+ Thread.sleep(500); // 500ms delay
+ setGLCanvasSize(frame, glCanvas, rwsize);
+ System.err.println("window resize pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getWidth()+"x"+glCanvas.getHeight());
+ }
+
while(!quitAdapter.shouldQuit() /* && animator.isAnimating() */ && animator.getTotalFPSDuration()<duration) {
Thread.sleep(100);
}
@@ -184,19 +245,21 @@ public class TestGearsES2AWT extends UITestCase {
if(useStencil) {
caps.setStencilBits(1);
}
- if(shallUseOffscreenLayer) {
+ if(shallUseOffscreenFBOLayer) {
caps.setOnscreen(false);
}
if(shallUseOffscreenPBufferLayer) {
caps.setPBuffer(true);
}
- runTestGL(caps);
+ runTestGL(caps, frameLayout);
}
static long duration = 500; // ms
-
+ static FrameLayout frameLayout = FrameLayout.None;
+
public static void main(String args[]) {
boolean waitForKey = false;
+ int rw=-1, rh=-1;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -204,6 +267,15 @@ public class TestGearsES2AWT extends UITestCase {
try {
duration = Integer.parseInt(args[i]);
} catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-rwidth")) {
+ i++;
+ rw = MiscUtils.atoi(args[i], rw);
+ } else if(args[i].equals("-rheight")) {
+ i++;
+ rh = MiscUtils.atoi(args[i], rh);
+ } else if(args[i].equals("-layout")) {
+ i++;
+ frameLayout = FrameLayout.valueOf(args[i]);
} else if(args[i].equals("-es2")) {
forceES2 = true;
} else if(args[i].equals("-gl3")) {
@@ -213,8 +285,8 @@ public class TestGearsES2AWT extends UITestCase {
swapInterval = MiscUtils.atoi(args[i], swapInterval);
} else if(args[i].equals("-exclctx")) {
exclusiveContext = true;
- } else if(args[i].equals("-layered")) {
- shallUseOffscreenLayer = true;
+ } else if(args[i].equals("-layeredFBO")) {
+ shallUseOffscreenFBOLayer = true;
} else if(args[i].equals("-layeredPBuffer")) {
shallUseOffscreenPBufferLayer = true;
} else if(args[i].equals("-msaa")) {
@@ -223,8 +295,6 @@ public class TestGearsES2AWT extends UITestCase {
useStencil = true;
} else if(args[i].equals("-wait")) {
waitForKey = true;
- } else if(args[i].equals("-justGears")) {
- addComp = false;
} else if(args[i].equals("-shutdownKeepGLCanvas")) {
shutdownRemoveGLCanvas = false;
} else if(args[i].equals("-shutdownKeepFrame")) {
@@ -236,11 +306,18 @@ public class TestGearsES2AWT extends UITestCase {
shutdownSystemExit = true;
}
}
+ if( 0 < rw && 0 < rh ) {
+ rwsize = new Dimension(rw, rh);
+ }
+
+ System.err.println("resize "+rwsize);
+ System.err.println("frameLayout "+frameLayout);
System.err.println("forceES2 "+forceES2);
System.err.println("forceGL3 "+forceGL3);
System.err.println("swapInterval "+swapInterval);
System.err.println("exclusiveContext "+exclusiveContext);
- System.err.println("shallUseOffscreenLayer "+shallUseOffscreenLayer);
+ System.err.println("shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
+ System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
if(waitForKey) {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
index 3910d1881..47891a8df 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
@@ -71,7 +71,7 @@ import org.junit.Test;
public class TestGearsES2NEWT extends UITestCase {
static int screenIdx = 0;
static PointImmutable wpos;
- static DimensionImmutable wsize;
+ static DimensionImmutable wsize, rwsize=null;
static long duration = 500; // ms
static boolean opaque = true;
@@ -265,6 +265,11 @@ public class TestGearsES2NEWT extends UITestCase {
System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+ if( null != rwsize ) {
+ Thread.sleep(500); // 500ms delay
+ glWindow.setSize(rwsize.getWidth(), rwsize.getHeight());
+ System.err.println("window resize pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+ }
while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
Thread.sleep(100);
@@ -318,7 +323,7 @@ public class TestGearsES2NEWT extends UITestCase {
public static void main(String args[]) throws IOException {
mainRun = true;
- int x=0, y=0, w=640, h=480;
+ int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
boolean usePos = false;
for(int i=0; i<args.length; i++) {
@@ -369,6 +374,12 @@ public class TestGearsES2NEWT extends UITestCase {
i++;
y = MiscUtils.atoi(args[i], y);
usePos = true;
+ } else if(args[i].equals("-rwidth")) {
+ i++;
+ rw = MiscUtils.atoi(args[i], rw);
+ } else if(args[i].equals("-rheight")) {
+ i++;
+ rh = MiscUtils.atoi(args[i], rh);
} else if(args[i].equals("-screen")) {
i++;
screenIdx = MiscUtils.atoi(args[i], 0);
@@ -380,12 +391,16 @@ public class TestGearsES2NEWT extends UITestCase {
}
}
wsize = new Dimension(w, h);
+ if( 0 < rw && 0 < rh ) {
+ rwsize = new Dimension(rw, rh);
+ }
if(usePos) {
wpos = new Point(x, y);
}
System.err.println("position "+wpos);
System.err.println("size "+wsize);
+ System.err.println("resize "+rwsize);
System.err.println("screen "+screenIdx);
System.err.println("translucent "+(!opaque));
System.err.println("forceAlpha "+forceAlpha);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java
index 5fca50593..ad2165301 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java
@@ -29,10 +29,15 @@
package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Component;
+import java.awt.Container;
import java.awt.Frame;
+import java.awt.TextArea;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import com.jogamp.common.os.Platform;
import com.jogamp.newt.Display;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
@@ -62,14 +67,18 @@ import javax.media.opengl.GLProfile;
import javax.swing.SwingUtilities;
import org.junit.Assert;
+import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
public class TestGearsES2NewtCanvasAWT extends UITestCase {
+ public enum FrameLayout { None, TextOnBottom, BorderBottom, BorderBottom2, BorderCenter, BorderCenterSurrounded, DoubleBorderCenterSurrounded };
+ public enum ResizeBy { GLWindow, Component, Frame };
+
static int screenIdx = 0;
static PointImmutable wpos;
- static DimensionImmutable wsize;
+ static DimensionImmutable wsize, rwsize = null;
static long duration = 500; // ms
static boolean opaque = true;
@@ -80,6 +89,7 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
static boolean showFPS = false;
static int loops = 1;
static boolean loop_shutdown = false;
+ static boolean shallUseOffscreenFBOLayer = false;
static boolean forceES2 = false;
static boolean forceGL3 = false;
static boolean mainRun = false;
@@ -96,7 +106,69 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
public static void releaseClass() {
}
- protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException, InvocationTargetException {
+ static void setGLWindowSize(final Frame frame, final GLWindow glw, final DimensionImmutable new_sz) {
+ try {
+ glw.setSize(new_sz.getWidth(), new_sz.getHeight());
+ if( null != frame ) {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.pack();
+ } } );
+ }
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+ static void setComponentSize(final Frame frame, final Component comp, final DimensionImmutable new_sz) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ java.awt.Dimension d = new java.awt.Dimension(new_sz.getWidth(), new_sz.getHeight());
+ comp.setMinimumSize(d);
+ comp.setPreferredSize(d);
+ comp.setSize(d);
+ if( null != frame ) {
+ frame.pack();
+ }
+ } } );
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+ static void setFrameSize(final Frame frame, final boolean frameLayout, final DimensionImmutable new_sz) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ java.awt.Dimension d = new java.awt.Dimension(new_sz.getWidth(), new_sz.getHeight());
+ frame.setSize(d);
+ if( frameLayout ) {
+ frame.validate();
+ }
+ } } );
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ static void setSize(final ResizeBy resizeBy, final Frame frame, final boolean frameLayout, final Component comp, final GLWindow glw, final DimensionImmutable new_sz) {
+ switch( resizeBy ) {
+ case GLWindow:
+ setGLWindowSize(frameLayout ? frame : null, glw, new_sz);
+ break;
+ case Component:
+ setComponentSize(frameLayout ? frame : null, comp, new_sz);
+ break;
+ case Frame:
+ setFrameSize(frame, frameLayout, new_sz);
+ break;
+ }
+ }
+
+ // public enum ResizeBy { GLWindow, Component, Frame };
+ protected void runTestGL(final GLCapabilitiesImmutable caps, final ResizeBy resizeBy, final FrameLayout frameLayout) throws InterruptedException, InvocationTargetException {
System.err.println("requested: vsync "+swapInterval+", "+caps);
Display dpy = NewtFactory.createDisplay(null);
Screen screen = NewtFactory.createScreen(dpy, screenIdx);
@@ -104,13 +176,68 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
Assert.assertNotNull(glWindow);
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ if ( shallUseOffscreenFBOLayer ) {
+ newtCanvasAWT.setShallUseOffscreenLayer(true);
+ }
+
+ final Frame frame = new Frame("AWT Parent Frame");
+
+ setSize(resizeBy, frame, false, newtCanvasAWT, glWindow, wsize);
+
+ switch( frameLayout) {
+ case None:
+ frame.add(newtCanvasAWT);
+ break;
+ case TextOnBottom:
+ final TextArea ta = new TextArea(2, 20);
+ ta.append("0123456789");
+ ta.append(Platform.getNewline());
+ ta.append("Some Text");
+ ta.append(Platform.getNewline());
+ frame.setLayout(new BorderLayout());
+ frame.add(ta, BorderLayout.SOUTH);
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case BorderBottom:
+ frame.setLayout(new BorderLayout());
+ frame.add(newtCanvasAWT, BorderLayout.SOUTH);
+ break;
+ case BorderBottom2:
+ frame.setLayout(new BorderLayout());
+ frame.add(newtCanvasAWT, BorderLayout.SOUTH);
+ frame.add(new Button("North"), BorderLayout.NORTH);
+ break;
+ case BorderCenter:
+ frame.setLayout(new BorderLayout());
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case BorderCenterSurrounded:
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("NORTH"), BorderLayout.NORTH);
+ frame.add(new Button("SOUTH"), BorderLayout.SOUTH);
+ frame.add(new Button("EAST"), BorderLayout.EAST);
+ frame.add(new Button("WEST"), BorderLayout.WEST);
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case DoubleBorderCenterSurrounded:
+ Container c = new Container();
+ c.setLayout(new BorderLayout());
+ c.add(new Button("north"), BorderLayout.NORTH);
+ c.add(new Button("south"), BorderLayout.SOUTH);
+ c.add(new Button("east"), BorderLayout.EAST);
+ c.add(new Button("west"), BorderLayout.WEST);
+ c.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("NORTH"), BorderLayout.NORTH);
+ frame.add(new Button("SOUTH"), BorderLayout.SOUTH);
+ frame.add(new Button("EAST"), BorderLayout.EAST);
+ frame.add(new Button("WEST"), BorderLayout.WEST);
+ frame.add(c, BorderLayout.CENTER);
+ break;
+ }
- final Frame frame1 = new Frame("AWT Parent Frame");
- frame1.setLayout(new BorderLayout());
- frame1.add(newtCanvasAWT, BorderLayout.CENTER);
- frame1.setSize(wsize.getWidth(), wsize.getHeight());
- frame1.setLocation(0, 0);
- frame1.setTitle("Gears NewtCanvasAWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval+", size "+wsize+", pos "+wpos);
+ frame.setTitle("Gears NewtCanvasAWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval+", size "+wsize+", pos "+wpos);
final GearsES2 demo = new GearsES2(swapInterval);
demo.setPMVUseBackingArray(pmvUseBackingArray);
@@ -158,9 +285,16 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- frame1.setVisible(true);
+ if( ResizeBy.Frame == resizeBy ) {
+ frame.validate();
+ } else {
+ frame.pack();
+ }
+ frame.setVisible(true);
}
- });
+ });
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, true));
animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
@@ -168,6 +302,12 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+ if( null != rwsize ) {
+ Thread.sleep(500); // 500ms delay
+ setSize(resizeBy, frame, true, newtCanvasAWT, glWindow, rwsize);
+ System.err.println("window resize "+rwsize+" -> pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+ }
+
while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
Thread.sleep(100);
}
@@ -179,7 +319,7 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
Assert.assertEquals(null, glWindow.getExclusiveContextThread());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- frame1.dispose();
+ frame.dispose();
}
});
glWindow.destroy();
@@ -203,7 +343,7 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
if(-1 < forceAlpha) {
caps.setAlphaBits(forceAlpha);
}
- runTestGL(caps);
+ runTestGL(caps, resizeBy, frameLayout);
if(loop_shutdown) {
GLProfile.shutdown();
}
@@ -219,19 +359,35 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
}
final GLProfile glp = GLProfile.get(GLProfile.GL3);
final GLCapabilities caps = new GLCapabilities( glp );
- runTestGL(caps);
+ runTestGL(caps, resizeBy, frameLayout);
}
+ static FrameLayout frameLayout = FrameLayout.None;
+ static ResizeBy resizeBy = ResizeBy.Component;
+
public static void main(String args[]) throws IOException {
mainRun = true;
int x=0, y=0, w=640, h=480;
+ int rw=-1, rh=-1;
boolean usePos = false;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-rwidth")) {
+ i++;
+ rw = MiscUtils.atoi(args[i], rw);
+ } else if(args[i].equals("-rheight")) {
+ i++;
+ rh = MiscUtils.atoi(args[i], rh);
+ } else if(args[i].equals("-layout")) {
+ i++;
+ frameLayout = FrameLayout.valueOf(args[i]);
+ } else if(args[i].equals("-resizeBy")) {
+ i++;
+ resizeBy = ResizeBy.valueOf(args[i]);
} else if(args[i].equals("-translucent")) {
opaque = false;
} else if(args[i].equals("-forceAlpha")) {
@@ -244,6 +400,8 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
} else if(args[i].equals("-vsync")) {
i++;
swapInterval = MiscUtils.atoi(args[i], swapInterval);
+ } else if(args[i].equals("-layeredFBO")) {
+ shallUseOffscreenFBOLayer = true;
} else if(args[i].equals("-exclctx")) {
exclusiveContext = true;
} else if(args[i].equals("-es2")) {
@@ -277,12 +435,19 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
}
}
wsize = new Dimension(w, h);
+ if( 0 < rw && 0 < rh ) {
+ rwsize = new Dimension(rw, rh);
+ }
if(usePos) {
wpos = new Point(x, y);
}
+
+ System.err.println("frameLayout "+frameLayout);
+ System.err.println("resizeBy "+resizeBy);
System.err.println("position "+wpos);
System.err.println("size "+wsize);
+ System.err.println("resize "+rwsize);
System.err.println("screen "+screenIdx);
System.err.println("translucent "+(!opaque));
System.err.println("forceAlpha "+forceAlpha);
@@ -290,6 +455,7 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase {
System.err.println("pmvDirect "+(!pmvUseBackingArray));
System.err.println("loops "+loops);
System.err.println("loop shutdown "+loop_shutdown);
+ System.err.println("shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
System.err.println("forceES2 "+forceES2);
System.err.println("forceGL3 "+forceGL3);
System.err.println("swapInterval "+swapInterval);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java
new file mode 100644
index 000000000..cb2cf064f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java
@@ -0,0 +1,375 @@
+/**
+ * Copyright 2011 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.demos.es2.newt;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import com.jogamp.nativewindow.swt.SWTAccessor;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.swt.NewtCanvasSWT;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.PointImmutable;
+import javax.media.nativewindow.util.DimensionImmutable;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLProfile;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestGearsES2NewtCanvasSWT extends UITestCase {
+ static int screenIdx = 0;
+ static PointImmutable wpos;
+ static DimensionImmutable wsize, rwsize = null;
+
+ static long duration = 500; // ms
+ static boolean opaque = true;
+ static int forceAlpha = -1;
+ static boolean fullscreen = false;
+ static boolean pmvUseBackingArray = true;
+ static int swapInterval = 1;
+ static boolean showFPS = false;
+ static int loops = 1;
+ static boolean loop_shutdown = false;
+ static boolean forceES2 = false;
+ static boolean forceGL3 = false;
+ static boolean mainRun = false;
+ static boolean exclusiveContext = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(null == wsize) {
+ wsize = new Dimension(640, 480);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+
+ @Before
+ public void init() {
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ }});
+ display.syncExec(new Runnable() {
+ public void run() {
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.NONE );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ }});
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ try {
+ display.syncExec(new Runnable() {
+ public void run() {
+ composite.dispose();
+ shell.dispose();
+ }});
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ display.dispose();
+ }});
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ }
+
+ protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException, InvocationTargetException {
+ System.err.println("requested: vsync "+swapInterval+", "+caps);
+ com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null);
+ com.jogamp.newt.Screen screen = NewtFactory.createScreen(dpy, screenIdx);
+ final GLWindow glWindow = GLWindow.create(screen, caps);
+ Assert.assertNotNull(glWindow);
+
+ final GearsES2 demo = new GearsES2(swapInterval);
+ demo.setPMVUseBackingArray(pmvUseBackingArray);
+ glWindow.addGLEventListener(demo);
+
+ Animator animator = new Animator();
+ animator.setModeBits(false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD);
+ animator.setExclusiveContext(exclusiveContext);
+
+ QuitAdapter quitAdapter = new QuitAdapter();
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+
+ glWindow.addWindowListener(new WindowAdapter() {
+ public void windowResized(WindowEvent e) {
+ System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight());
+ }
+ public void windowMoved(WindowEvent e) {
+ System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight());
+ }
+ });
+
+ glWindow.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='f') {
+ new Thread() {
+ public void run() {
+ final Thread t = glWindow.setExclusiveContextThread(null);
+ System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
+ glWindow.setFullscreen(!glWindow.isFullscreen());
+ System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
+ glWindow.setExclusiveContextThread(t);
+ } }.start();
+ }
+ }
+ });
+
+ animator.add(glWindow);
+ animator.start();
+ Assert.assertTrue(animator.isStarted());
+ Assert.assertTrue(animator.isAnimating());
+ Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
+
+ final NewtCanvasSWT canvas1 = NewtCanvasSWT.create( composite, 0, glWindow );
+ Assert.assertNotNull( canvas1 );
+
+ display.syncExec( new Runnable() {
+ public void run() {
+ shell.setText( getSimpleTestName(".") );
+ shell.setSize( wsize.getWidth(), wsize.getHeight() );
+ if( null != wpos ) {
+ shell.setLocation( wpos.getX(), wpos.getY() );
+ }
+ shell.open();
+ }
+ });
+
+ animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
+
+ System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
+ System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
+ System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+
+ if( null != rwsize ) {
+ for(int i=0; i<50; i++) { // 500 ms dispatched delay
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ display.syncExec( new Runnable() {
+ public void run() {
+ shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
+ }
+ });
+ System.err.println("window resize pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets());
+ }
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+
+ Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
+ animator.stop();
+ Assert.assertFalse(animator.isAnimating());
+ Assert.assertFalse(animator.isStarted());
+ Assert.assertEquals(null, glWindow.getExclusiveContextThread());
+
+ canvas1.dispose();
+ glWindow.destroy();
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, false));
+ }
+
+ @Test
+ public void test01GL2ES2() throws InterruptedException, InvocationTargetException {
+ for(int i=1; i<=loops; i++) {
+ System.err.println("Loop "+i+"/"+loops);
+ final GLProfile glp;
+ if(forceGL3) {
+ glp = GLProfile.get(GLProfile.GL3);
+ } else if(forceES2) {
+ glp = GLProfile.get(GLProfile.GLES2);
+ } else {
+ glp = GLProfile.getGL2ES2();
+ }
+ final GLCapabilities caps = new GLCapabilities( glp );
+ caps.setBackgroundOpaque(opaque);
+ if(-1 < forceAlpha) {
+ caps.setAlphaBits(forceAlpha);
+ }
+ runTestGL(caps);
+ if(loop_shutdown) {
+ GLProfile.shutdown();
+ }
+ }
+ }
+
+ @Test
+ public void test02GL3() throws InterruptedException, InvocationTargetException {
+ if(mainRun) return;
+
+ if( !GLProfile.isAvailable(GLProfile.GL3) ) {
+ System.err.println("GL3 n/a");
+ }
+ final GLProfile glp = GLProfile.get(GLProfile.GL3);
+ final GLCapabilities caps = new GLCapabilities( glp );
+ runTestGL(caps);
+ }
+
+ public static void main(String args[]) throws IOException {
+ mainRun = true;
+
+ int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
+ boolean usePos = false;
+
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-translucent")) {
+ opaque = false;
+ } else if(args[i].equals("-forceAlpha")) {
+ i++;
+ forceAlpha = MiscUtils.atoi(args[i], 0);
+ } else if(args[i].equals("-fullscreen")) {
+ fullscreen = true;
+ } else if(args[i].equals("-pmvDirect")) {
+ pmvUseBackingArray = false;
+ } else if(args[i].equals("-vsync")) {
+ i++;
+ swapInterval = MiscUtils.atoi(args[i], swapInterval);
+ } else if(args[i].equals("-exclctx")) {
+ exclusiveContext = true;
+ } else if(args[i].equals("-es2")) {
+ forceES2 = true;
+ } else if(args[i].equals("-gl3")) {
+ forceGL3 = true;
+ } else if(args[i].equals("-showFPS")) {
+ showFPS = true;
+ } else if(args[i].equals("-width")) {
+ i++;
+ w = MiscUtils.atoi(args[i], w);
+ } else if(args[i].equals("-height")) {
+ i++;
+ h = MiscUtils.atoi(args[i], h);
+ } else if(args[i].equals("-x")) {
+ i++;
+ x = MiscUtils.atoi(args[i], x);
+ usePos = true;
+ } else if(args[i].equals("-y")) {
+ i++;
+ y = MiscUtils.atoi(args[i], y);
+ usePos = true;
+ } else if(args[i].equals("-rwidth")) {
+ i++;
+ rw = MiscUtils.atoi(args[i], rw);
+ } else if(args[i].equals("-rheight")) {
+ i++;
+ rh = MiscUtils.atoi(args[i], rh);
+ } else if(args[i].equals("-screen")) {
+ i++;
+ screenIdx = MiscUtils.atoi(args[i], 0);
+ } else if(args[i].equals("-loops")) {
+ i++;
+ loops = MiscUtils.atoi(args[i], 1);
+ } else if(args[i].equals("-loop-shutdown")) {
+ loop_shutdown = true;
+ }
+ }
+ wsize = new Dimension(w, h);
+ if( 0 < rw && 0 < rh ) {
+ rwsize = new Dimension(rw, rh);
+ }
+
+ if(usePos) {
+ wpos = new Point(x, y);
+ }
+ System.err.println("position "+wpos);
+ System.err.println("size "+wsize);
+ System.err.println("resize "+rwsize);
+ System.err.println("screen "+screenIdx);
+ System.err.println("translucent "+(!opaque));
+ System.err.println("forceAlpha "+forceAlpha);
+ System.err.println("fullscreen "+fullscreen);
+ System.err.println("pmvDirect "+(!pmvUseBackingArray));
+ System.err.println("loops "+loops);
+ System.err.println("loop shutdown "+loop_shutdown);
+ System.err.println("forceES2 "+forceES2);
+ System.err.println("forceGL3 "+forceGL3);
+ System.err.println("swapInterval "+swapInterval);
+ System.err.println("exclusiveContext "+exclusiveContext);
+
+ org.junit.runner.JUnitCore.main(TestGearsES2NewtCanvasSWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
new file mode 100644
index 000000000..c6f299e83
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
@@ -0,0 +1,340 @@
+/**
+ * Copyright 2011 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.demos.es2.swt;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import com.jogamp.nativewindow.swt.SWTAccessor;
+import com.jogamp.opengl.swt.GLCanvas;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.PointImmutable;
+import javax.media.nativewindow.util.DimensionImmutable;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLProfile;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestGearsES2SWT extends UITestCase {
+ static int screenIdx = 0;
+ static PointImmutable wpos;
+ static DimensionImmutable wsize, rwsize=null;
+
+ static long duration = 500; // ms
+ static boolean opaque = true;
+ static int forceAlpha = -1;
+ static boolean fullscreen = false;
+ static boolean pmvUseBackingArray = true;
+ static int swapInterval = 1;
+ static boolean showFPS = false;
+ static int loops = 1;
+ static boolean loop_shutdown = false;
+ static boolean forceES2 = false;
+ static boolean forceGL3 = false;
+ static boolean mainRun = false;
+ static boolean exclusiveContext = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(null == wsize) {
+ wsize = new Dimension(640, 480);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+
+ @Before
+ public void init() {
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ }});
+ display.syncExec(new Runnable() {
+ public void run() {
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.NONE );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ }});
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ try {
+ display.syncExec(new Runnable() {
+ public void run() {
+ composite.dispose();
+ shell.dispose();
+ }});
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ display.dispose();
+ }});
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ }
+
+ protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException, InvocationTargetException {
+ System.err.println("requested: vsync "+swapInterval+", "+caps);
+
+ final GLCanvas canvas = GLCanvas.create( composite, 0, caps, null, null);
+ Assert.assertNotNull( canvas );
+
+ final GearsES2 demo = new GearsES2(swapInterval);
+ demo.setPMVUseBackingArray(pmvUseBackingArray);
+ canvas.addGLEventListener(demo);
+
+ Animator animator = new Animator();
+ animator.setModeBits(false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD);
+ animator.setExclusiveContext(exclusiveContext);
+
+ animator.add(canvas);
+ animator.start();
+ Assert.assertTrue(animator.isStarted());
+ Assert.assertTrue(animator.isAnimating());
+ Assert.assertEquals(exclusiveContext ? animator.getThread() : null, canvas.getExclusiveContextThread());
+
+ display.syncExec( new Runnable() {
+ public void run() {
+ shell.setText( getSimpleTestName(".") );
+ shell.setSize( wsize.getWidth(), wsize.getHeight() );
+ if( null != wpos ) {
+ shell.setLocation( wpos.getX(), wpos.getY() );
+ }
+ shell.open();
+ }
+ });
+
+ animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
+
+ while(animator.isAnimating() && !canvas.isRealized() && animator.getTotalFPSDuration()<duration) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ System.err.println("NW chosen: "+canvas.getDelegatedDrawable().getChosenGLCapabilities());
+ System.err.println("GL chosen: "+canvas.getChosenGLCapabilities());
+ System.err.println("window pos/siz: "+canvas.getLocation()+" "+canvas.getWidth()+"x"+canvas.getHeight());
+
+ if( null != rwsize ) {
+ for(int i=0; i<50; i++) { // 500 ms dispatched delay
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ display.syncExec( new Runnable() {
+ public void run() {
+ shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
+ }
+ });
+ System.err.println("window resize pos/siz: "+canvas.getLocation()+" "+canvas.getWidth()+"x"+canvas.getHeight());
+ }
+
+ while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+
+ Assert.assertEquals(exclusiveContext ? animator.getThread() : null, canvas.getExclusiveContextThread());
+ animator.stop();
+ Assert.assertFalse(animator.isAnimating());
+ Assert.assertFalse(animator.isStarted());
+ Assert.assertEquals(null, canvas.getExclusiveContextThread());
+
+ display.syncExec(new Runnable() {
+ public void run() {
+ canvas.dispose();
+ } } );
+ }
+
+ @Test
+ public void test01GL2ES2() throws InterruptedException, InvocationTargetException {
+ for(int i=1; i<=loops; i++) {
+ System.err.println("Loop "+i+"/"+loops);
+ final GLProfile glp;
+ if(forceGL3) {
+ glp = GLProfile.get(GLProfile.GL3);
+ } else if(forceES2) {
+ glp = GLProfile.get(GLProfile.GLES2);
+ } else {
+ glp = GLProfile.getGL2ES2();
+ }
+ final GLCapabilities caps = new GLCapabilities( glp );
+ caps.setBackgroundOpaque(opaque);
+ if(-1 < forceAlpha) {
+ caps.setAlphaBits(forceAlpha);
+ }
+ runTestGL(caps);
+ if(loop_shutdown) {
+ GLProfile.shutdown();
+ }
+ }
+ }
+
+ @Test
+ public void test02GL3() throws InterruptedException, InvocationTargetException {
+ if(mainRun) return;
+
+ if( !GLProfile.isAvailable(GLProfile.GL3) ) {
+ System.err.println("GL3 n/a");
+ }
+ final GLProfile glp = GLProfile.get(GLProfile.GL3);
+ final GLCapabilities caps = new GLCapabilities( glp );
+ runTestGL(caps);
+ }
+
+ public static void main(String args[]) throws IOException {
+ mainRun = true;
+
+ int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
+ boolean usePos = false;
+
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-translucent")) {
+ opaque = false;
+ } else if(args[i].equals("-forceAlpha")) {
+ i++;
+ forceAlpha = MiscUtils.atoi(args[i], 0);
+ } else if(args[i].equals("-fullscreen")) {
+ fullscreen = true;
+ } else if(args[i].equals("-pmvDirect")) {
+ pmvUseBackingArray = false;
+ } else if(args[i].equals("-vsync")) {
+ i++;
+ swapInterval = MiscUtils.atoi(args[i], swapInterval);
+ } else if(args[i].equals("-exclctx")) {
+ exclusiveContext = true;
+ } else if(args[i].equals("-es2")) {
+ forceES2 = true;
+ } else if(args[i].equals("-gl3")) {
+ forceGL3 = true;
+ } else if(args[i].equals("-showFPS")) {
+ showFPS = true;
+ } else if(args[i].equals("-width")) {
+ i++;
+ w = MiscUtils.atoi(args[i], w);
+ } else if(args[i].equals("-height")) {
+ i++;
+ h = MiscUtils.atoi(args[i], h);
+ } else if(args[i].equals("-x")) {
+ i++;
+ x = MiscUtils.atoi(args[i], x);
+ usePos = true;
+ } else if(args[i].equals("-y")) {
+ i++;
+ y = MiscUtils.atoi(args[i], y);
+ usePos = true;
+ } else if(args[i].equals("-rwidth")) {
+ i++;
+ rw = MiscUtils.atoi(args[i], rw);
+ } else if(args[i].equals("-rheight")) {
+ i++;
+ rh = MiscUtils.atoi(args[i], rh);
+ } else if(args[i].equals("-screen")) {
+ i++;
+ screenIdx = MiscUtils.atoi(args[i], 0);
+ } else if(args[i].equals("-loops")) {
+ i++;
+ loops = MiscUtils.atoi(args[i], 1);
+ } else if(args[i].equals("-loop-shutdown")) {
+ loop_shutdown = true;
+ }
+ }
+ wsize = new Dimension(w, h);
+ if( 0 < rw && 0 < rh ) {
+ rwsize = new Dimension(rw, rh);
+ }
+
+ if(usePos) {
+ wpos = new Point(x, y);
+ }
+ System.err.println("position "+wpos);
+ System.err.println("size "+wsize);
+ System.err.println("resize "+rwsize);
+ System.err.println("screen "+screenIdx);
+ System.err.println("translucent "+(!opaque));
+ System.err.println("forceAlpha "+forceAlpha);
+ System.err.println("fullscreen "+fullscreen);
+ System.err.println("pmvDirect "+(!pmvUseBackingArray));
+ System.err.println("loops "+loops);
+ System.err.println("loop shutdown "+loop_shutdown);
+ System.err.println("forceES2 "+forceES2);
+ System.err.println("forceGL3 "+forceGL3);
+ System.err.println("swapInterval "+swapInterval);
+ System.err.println("exclusiveContext "+exclusiveContext);
+
+ org.junit.runner.JUnitCore.main(TestGearsES2SWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java
index 4ebb7dddd..d63193445 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java
@@ -45,6 +45,7 @@ import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil.WindowClosingListener;
public class TestCloseNewtAWT extends UITestCase {
@@ -107,9 +108,11 @@ public class TestCloseNewtAWT extends UITestCase {
frame.setVisible(true);
}
});
- Thread.sleep(500);
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(newtWindow, true));
+ final WindowClosingListener closingListener = AWTRobotUtil.addClosingListener(frame);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true, closingListener));
}
public static void main(String[] args) {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
index 5d6218df4..a87cbe0ac 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -115,7 +115,8 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
// Wrap the window in a canvas.
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
-
+ // newtCanvasAWT.setShallUseOffscreenLayer(true);
+
// Monitor AWT focus and keyboard events.
AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
@@ -146,7 +147,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
frame1.setVisible(true);
} } );
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame1, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
AWTRobotUtil.clearAWTFocus(robot);
Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java
index d63f0d2a7..5b7986f4d 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java
@@ -46,13 +46,14 @@ import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil.WindowClosingListener;
public class TestWindowClosingProtocol01AWT extends UITestCase {
@Test
public void testCloseFrameGLCanvas() throws InterruptedException, InvocationTargetException {
final Frame frame = new Frame("testCloseFrameGLCanvas AWT");
-
+ final WindowClosingListener closingListener = AWTRobotUtil.addClosingListener(frame);
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
final GLCanvas glCanvas = new GLCanvas(caps);
@@ -74,12 +75,14 @@ public class TestWindowClosingProtocol01AWT extends UITestCase {
WindowClosingMode op = glCanvas.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // nop
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false, closingListener)); // nop
Thread.sleep(100);
- Assert.assertEquals(true, frame.isDisplayable());
+ Assert.assertEquals(true, frame.isDisplayable());
Assert.assertEquals(true, frame.isVisible());
- Assert.assertEquals(true, glCanvas.isValid());
- Assert.assertEquals(true, glCanvas.isDisplayable());
+ Assert.assertEquals(true, glCanvas.isValid());
+ Assert.assertEquals(true, glCanvas.isDisplayable());
+ Assert.assertEquals(true, closingListener.isWindowClosing());
+ Assert.assertEquals(false, closingListener.isWindowClosed());
//
// close with op (GLCanvas): DISPOSE_ON_CLOSE -> dispose
@@ -87,11 +90,18 @@ public class TestWindowClosingProtocol01AWT extends UITestCase {
glCanvas.setDefaultCloseOperation(WindowClosingMode.DISPOSE_ON_CLOSE);
op = glCanvas.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
+
+ Thread.sleep(300);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // no frame close
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, false));
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false, closingListener)); // no frame close, but GLCanvas's GL resources will be destroyed
+ Thread.sleep(100);
Assert.assertEquals(true, frame.isDisplayable());
Assert.assertEquals(true, frame.isVisible());
+ Assert.assertEquals(true, closingListener.isWindowClosing());
+ Assert.assertEquals(false, closingListener.isWindowClosed());
+ for (int wait=0; wait<AWTRobotUtil.POLL_DIVIDER && glCanvas.isRealized(); wait++) {
+ Thread.sleep(AWTRobotUtil.TIME_SLICE);
+ }
Assert.assertEquals(false, glCanvas.isRealized());
SwingUtilities.invokeAndWait(new Runnable() {
@@ -103,7 +113,8 @@ public class TestWindowClosingProtocol01AWT extends UITestCase {
@Test
public void testCloseJFrameGLCanvas() throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame("testCloseJFrameGLCanvas AWT");
-
+ final WindowClosingListener closingListener = AWTRobotUtil.addClosingListener(frame);
+
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
GLCanvas glCanvas = new GLCanvas(caps);
@@ -126,7 +137,9 @@ public class TestWindowClosingProtocol01AWT extends UITestCase {
WindowClosingMode op = glCanvas.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // nop
+ Thread.sleep(300);
+
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false, closingListener)); // nop
Thread.sleep(100);
Assert.assertEquals(true, frame.isDisplayable());
Assert.assertEquals(true, glCanvas.isValid());
@@ -147,7 +160,7 @@ public class TestWindowClosingProtocol01AWT extends UITestCase {
op = glCanvas.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true, closingListener));
Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, false));
Assert.assertEquals(false, frame.isDisplayable());
Assert.assertEquals(false, glCanvas.isValid());
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java
index 1657fcbe9..8d32beea3 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java
@@ -52,7 +52,7 @@ public class TestWindowClosingProtocol02NEWT extends UITestCase {
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
final GLWindow glWindow = GLWindow.create(caps);
- final AWTRobotUtil.WindowClosingListener windowClosingListener = AWTRobotUtil.addClosingListener(glWindow);
+ final AWTRobotUtil.WindowClosingListener closingListener = AWTRobotUtil.addClosingListener(glWindow);
glWindow.addGLEventListener(new GearsES2());
glWindow.setSize(512, 512);
@@ -69,11 +69,13 @@ public class TestWindowClosingProtocol02NEWT extends UITestCase {
glWindow.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE);
op = glWindow.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
+
+ Thread.sleep(300);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, false)); // nop
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, false, closingListener)); // nop
Assert.assertEquals(true, glWindow.isNativeValid());
- Assert.assertEquals(true, windowClosingListener.isWindowClosing());
- windowClosingListener.reset();
+ Assert.assertEquals(true, closingListener.isWindowClosing());
+ closingListener.reset();
//
// close with op (GLCanvas): DISPOSE_ON_CLOSE -> dispose
@@ -82,9 +84,9 @@ public class TestWindowClosingProtocol02NEWT extends UITestCase {
op = glWindow.getDefaultCloseOperation();
Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, true));
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, true, closingListener));
Assert.assertEquals(false, glWindow.isNativeValid());
- Assert.assertEquals(true, windowClosingListener.isWindowClosing());
+ Assert.assertEquals(true, closingListener.isWindowClosing());
}
public static void main(String[] args) {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java
index 65068e9e8..b0a222a5a 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java
@@ -46,17 +46,19 @@ import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil.WindowClosingListener;
public class TestWindowClosingProtocol03NewtAWT extends UITestCase {
@Test
public void testCloseJFrameNewtCanvasAWT() throws InterruptedException, InvocationTargetException {
final JFrame frame = new JFrame("testCloseJFrameNewtCanvasAWT");
-
+ final WindowClosingListener awtClosingListener = AWTRobotUtil.addClosingListener(frame);
+
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
final GLWindow glWindow = GLWindow.create(caps);
- final AWTRobotUtil.WindowClosingListener windowClosingListener = AWTRobotUtil.addClosingListener(glWindow);
+ final AWTRobotUtil.WindowClosingListener newtClosingListener = AWTRobotUtil.addClosingListener(glWindow);
glWindow.addGLEventListener(new GearsES2());
@@ -81,18 +83,26 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase {
//
// close with op: DO_NOTHING_ON_CLOSE -> NOP / HIDE (default)
//
- Assert.assertEquals(JFrame.HIDE_ON_CLOSE, frame.getDefaultCloseOperation());
- WindowClosingMode op = newtCanvas.getDefaultCloseOperation();
- Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
+ {
+ Assert.assertEquals(JFrame.HIDE_ON_CLOSE, frame.getDefaultCloseOperation());
+ WindowClosingMode op = newtCanvas.getDefaultCloseOperation();
+ Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
+ }
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false));
+ Thread.sleep(300);
+
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false, awtClosingListener));
Assert.assertEquals(true, frame.isDisplayable());
Assert.assertEquals(false, frame.isVisible());
Assert.assertEquals(true, newtCanvas.isValid());
Assert.assertEquals(true, newtCanvas.isDisplayable());
Assert.assertEquals(true, glWindow.isNativeValid());
- Assert.assertEquals(true, windowClosingListener.isWindowClosing());
- windowClosingListener.reset();
+ Assert.assertEquals(true, awtClosingListener.isWindowClosing());
+ Assert.assertEquals(false, awtClosingListener.isWindowClosed());
+ Assert.assertEquals(true, newtClosingListener.isWindowClosing());
+ Assert.assertEquals(false, newtClosingListener.isWindowClosed());
+ awtClosingListener.reset();
+ newtClosingListener.reset();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
@@ -105,18 +115,25 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase {
//
// close with op (JFrame): DISPOSE_ON_CLOSE -- newtCanvas -- glWindow --> dispose
//
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- Assert.assertEquals(JFrame.DISPOSE_ON_CLOSE, frame.getDefaultCloseOperation());
- op = newtCanvas.getDefaultCloseOperation();
- Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
+ {
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ Assert.assertEquals(JFrame.DISPOSE_ON_CLOSE, frame.getDefaultCloseOperation());
+ WindowClosingMode op = newtCanvas.getDefaultCloseOperation();
+ Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
+ }
+
+ Thread.sleep(300);
- Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true, awtClosingListener));
Assert.assertEquals(false, frame.isDisplayable());
Assert.assertEquals(false, frame.isVisible());
Assert.assertEquals(false, newtCanvas.isValid());
Assert.assertEquals(false, newtCanvas.isDisplayable());
Assert.assertEquals(false, glWindow.isNativeValid());
- Assert.assertEquals(true, windowClosingListener.isWindowClosing());
+ Assert.assertEquals(true, awtClosingListener.isWindowClosing());
+ Assert.assertEquals(true, awtClosingListener.isWindowClosed());
+ Assert.assertEquals(true, newtClosingListener.isWindowClosing());
+ Assert.assertEquals(true, newtClosingListener.isWindowClosed());
}
public static void main(String[] args) {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
index 31fa11e9d..4dd3bb98a 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
@@ -33,6 +33,7 @@ import java.util.ArrayList ;
import javax.media.opengl.GLProfile ;
+import org.junit.After;
import org.junit.Assert ;
import org.junit.BeforeClass ;
import org.junit.Test ;
@@ -335,33 +336,32 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
_robot.setAutoDelay( MS_ROBOT_AUTO_DELAY ) ;
{
// Make sure all the buttons and modifier keys are released.
- _releaseModifiers() ;
- _escape() ;
- eventDispatch(); eventDispatch(); eventDispatch();
- Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ;
- eventDispatch(); eventDispatch(); eventDispatch();
+ clearKeyboadAndMouse();
}
_testMouseListener.setModifierCheckEnabled( true ) ;
Throwable throwable = null;
- final Object sync = new Object();
- final RunnableTask rt = new RunnableTask( testAction, sync, true );
+ // final Object sync = new Object();
+ final RunnableTask rt = new RunnableTask( testAction, null, true );
try {
- new Thread(rt, "Test-Thread").start();
- while( !rt.isExecuted() && null == throwable ) {
- eventDispatch();
- }
- if(null==throwable) {
- throwable = rt.getThrowable();
- }
- if(null!=throwable) {
- throw new RuntimeException(throwable);
- }
+ // synchronized(sync) {
+ new Thread(rt, "Test-Thread").start();
+ int i=0;
+ while( !rt.isExecuted() && null == throwable ) {
+ System.err.println("WAIT-till-done: eventDispatch() #"+i++);
+ eventDispatch();
+ }
+ if(null==throwable) {
+ throwable = rt.getThrowable();
+ }
+ if(null!=throwable) {
+ throw new RuntimeException(throwable);
+ }
+ // }
} finally {
- _testMouseListener.setModifierCheckEnabled( false ) ;
- eventDispatch(); eventDispatch(); eventDispatch();
- Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ;
- eventDispatch(); eventDispatch(); eventDispatch();
+ System.err.println("WAIT-till-done: DONE");
+ _testMouseListener.setModifierCheckEnabled( false ) ;
+ clearKeyboadAndMouse();
}
}
@@ -677,19 +677,24 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
////////////////////////////////////////////////////////////////////////////
- public static void baseAfterClass() throws Exception {
-
+ public void eventDispatchedPostTestDelay() throws Exception {
+ eventDispatch(); eventDispatch(); eventDispatch();
+ Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ;
+ eventDispatch(); eventDispatch(); eventDispatch();
+ _testMouseListener.clear();
+ }
+
+ public void clearKeyboadAndMouse() throws Exception {
// Make sure all modifiers are released, otherwise the user's
// desktop can get locked up (ask me how I know this).
-
_releaseModifiers() ;
_escape() ;
- Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ;
+ eventDispatchedPostTestDelay();
}
////////////////////////////////////////////////////////////////////////////
- private static void _releaseModifiers() {
+ private void _releaseModifiers() {
if (_robot != null) {
@@ -714,7 +719,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
}
}
- private static void _escape() {
+ private void _escape() {
if (_robot != null) {
_robot.keyPress( java.awt.event.KeyEvent.VK_ESCAPE ) ;
_robot.keyRelease( java.awt.event.KeyEvent.VK_ESCAPE ) ;
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java
index 17f81c583..a847ca671 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java
@@ -62,25 +62,27 @@ public class TestNewtEventModifiersAWTCanvas extends BaseNewtEventModifiers {
_testFrame = new JFrame( "Event Modifier Test AWTCanvas" ) ;
_testFrame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ) ;
- _testFrame.getContentPane().add( canvas ) ;
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
+ _testFrame.getContentPane().add( canvas ) ;
_testFrame.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ;
_testFrame.setVisible( true ) ;
}
}) ;
- Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(canvas, true));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(canvas, true));
+
AWTRobotUtil.assertRequestFocusAndWait(null, canvas, canvas, null, null); // programmatic
Assert.assertNotNull(_robot);
- AWTRobotUtil.requestFocus(_robot, canvas, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
+ AWTRobotUtil.requestFocus(_robot, canvas, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
}
////////////////////////////////////////////////////////////////////////////
@AfterClass
public static void afterClass() throws Exception {
- baseAfterClass();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
_testFrame.dispose() ;
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java
index 5428958a0..71191c863 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java
@@ -58,7 +58,9 @@ public class TestNewtEventModifiersNEWTWindowAWT extends BaseNewtEventModifiers
_glWindow.setPosition(TEST_FRAME_X, TEST_FRAME_Y);
_glWindow.setVisible(true);
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(_glWindow, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(_glWindow, true));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(_glWindow, true));
+
AWTRobotUtil.assertRequestFocusAndWait(null, _glWindow, _glWindow, null, null); // programmatic
Assert.assertNotNull(_robot);
AWTRobotUtil.requestFocus(_robot, _glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
@@ -68,7 +70,6 @@ public class TestNewtEventModifiersNEWTWindowAWT extends BaseNewtEventModifiers
@AfterClass
public static void afterClass() throws Exception {
- baseAfterClass();
_glWindow.destroy();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java
index 6a3f4a54b..968d1af79 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java
@@ -82,6 +82,9 @@ public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers
}
} ) ;
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(_glWindow, true));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(_glWindow, true));
+
AWTRobotUtil.assertRequestFocusAndWait(null, _glWindow, _glWindow, null, null); // programmatic
Assert.assertNotNull(_robot);
AWTRobotUtil.requestFocus(_robot, _glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
@@ -93,7 +96,6 @@ public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers
@AfterClass
public static void afterClass() throws Exception {
- baseAfterClass();
SwingUtilities.invokeAndWait( new Runnable() {
public void run() {
_testFrame.dispose() ;
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java
index cafc3dd46..6279b70dc 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java
@@ -62,22 +62,23 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers
////////////////////////////////////////////////////////////////////////////
- protected static void eventDispatch2xImpl() {
- eventDispatchImpl();
+ protected static void eventDispatchImpl() {
+ final int maxEvents = 10;
try {
Thread.sleep(100);
} catch (InterruptedException e) { }
- eventDispatchImpl();
- }
-
- protected static void eventDispatchImpl() {
- if( !_display.isDisposed() ) {
- if( !_display.readAndDispatch() ) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) { }
- }
- }
+ final boolean[] res = { false };
+ int i=0;
+ do {
+ SWTAccessor.invoke(_display, true, new Runnable() {
+ public void run() {
+ if( !_display.isDisposed() ) {
+ res[0] = _display.readAndDispatch();
+ } else {
+ res[0] = false;
+ }
+ } } );
+ } while( i<maxEvents && res[0] );
}
@Override
@@ -96,7 +97,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers
}});
Assert.assertNotNull( _display );
- _display.syncExec(new Runnable() {
+ SWTAccessor.invoke(_display, true, new Runnable() {
public void run() {
_shell = new Shell( _display );
Assert.assertNotNull( _shell );
@@ -115,7 +116,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers
NewtCanvasSWT.create( _composite, SWT.NO_BACKGROUND, _glWindow ) ;
}
- _display.syncExec( new Runnable() {
+ SWTAccessor.invoke(_display, true, new Runnable() {
public void run() {
_shell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ;
_shell.open();
@@ -128,9 +129,9 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers
// no waiting for results ..
AWTRobotUtil.requestFocus(null, _glWindow, false); // programmatic
- eventDispatch2xImpl();
+ eventDispatchImpl();
AWTRobotUtil.requestFocus(_robot, _glWindow, INITIAL_MOUSE_X, INITIAL_MOUSE_Y);
- eventDispatch2xImpl();
+ eventDispatchImpl();
_glWindow.addMouseListener( _testMouseListener ) ;
}
@@ -139,23 +140,17 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers
@AfterClass
public static void afterClass() throws Exception {
- baseAfterClass();
-
_glWindow.destroy() ;
try {
- _display.syncExec(new Runnable() {
- public void run() {
- _composite.dispose();
- _shell.dispose();
- }});
-
- if(!_display.isDisposed()) {
- SWTAccessor.invoke(true, new Runnable() {
- public void run() {
+ SWTAccessor.invoke(_display, true, new Runnable() {
+ public void run() {
+ _composite.dispose();
+ _shell.dispose();
+ if(!_display.isDisposed()) {
_display.dispose();
- }});
- }
+ }
+ }});
}
catch( Throwable throwable ) {
throwable.printStackTrace();
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
index ec06379e0..08a181e10 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
@@ -47,6 +47,8 @@ import javax.swing.JFrame;
import java.io.IOException;
+import jogamp.nativewindow.jawt.JAWTUtil;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -61,6 +63,11 @@ import com.jogamp.opengl.test.junit.util.*;
/**
* Testing combinations of key code modifiers of key event.
+ *
+ * <p>
+ * Due to limitation of AWT Robot, the test machine needs to have US keyboard enabled,
+ * even though we do unify VK codes to US keyboard across all layouts.
+ * </p>
*/
public class TestNewtKeyCodeModifiersAWT extends UITestCase {
static int width, height;
@@ -99,12 +106,14 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
glWindow.destroy();
}
- @Test
- public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ private void testNewtCanvasAWT_Impl(boolean onscreen) throws AWTException, InterruptedException, InvocationTargetException {
GLWindow glWindow = GLWindow.create(glCaps);
// Wrap the window in a canvas.
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ if( !onscreen ) {
+ newtCanvasAWT.setShallUseOffscreenLayer(true);
+ }
// Add the canvas to a frame, and make it all visible.
final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle());
@@ -129,42 +138,63 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
throwable.printStackTrace();
Assume.assumeNoException( throwable );
}
- glWindow.destroy();
+ glWindow.destroy();
+ }
+
+ @Test
+ public void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("Platform doesn't support onscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(true);
}
- static void testKeyCodeModifier(Robot robot, NEWTKeyAdapter keyAdapter, int modifierKey, int modifierMask) {
+ @Test
+ public void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("Platform doesn't support offscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(false);
+ }
+
+ @SuppressWarnings("deprecation")
+ static void testKeyCodeModifier(Robot robot, NEWTKeyAdapter keyAdapter, int modifierKey, int modifierMask, int keyCode, char keyCharOnly, char keyCharMod) {
keyAdapter.reset();
- AWTRobotUtil.keyPress(0, robot, true, KeyEvent.VK_P, 10); // press P
- AWTRobotUtil.keyPress(0, robot, false, KeyEvent.VK_P, 100); // release+typed P
+ AWTRobotUtil.keyPress(0, robot, true, keyCode, 10); // press keyCode
+ AWTRobotUtil.keyPress(0, robot, false, keyCode, 100); // release+typed keyCode
robot.waitForIdle();
- for(int j=0; j < 10 && keyAdapter.getQueueSize() < 3; j++) { // wait until events are collected
+ for(int j=0; j < 40 && keyAdapter.getQueueSize() < 3; j++) { // wait until events are collected
robot.delay(100);
}
AWTRobotUtil.keyPress(0, robot, true, modifierKey, 10); // press MOD
- AWTRobotUtil.keyPress(0, robot, true, KeyEvent.VK_P, 10); // press P
- AWTRobotUtil.keyPress(0, robot, false, KeyEvent.VK_P, 10); // release+typed P
- AWTRobotUtil.keyPress(0, robot, false, modifierKey, 100); // release+typed MOD
+ AWTRobotUtil.keyPress(0, robot, true, keyCode, 10); // press keyCode
+ AWTRobotUtil.keyPress(0, robot, false, keyCode, 10); // release+typed keyCode
+ AWTRobotUtil.keyPress(0, robot, false, modifierKey, 100); // release MOD
robot.waitForIdle();
- for(int j=0; j < 20 && keyAdapter.getQueueSize() < 3+6; j++) { // wait until events are collected
+ for(int j=0; j < 40 && keyAdapter.getQueueSize() < 3+5; j++) { // wait until events are collected
robot.delay(100);
}
- NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, 3+6, 0);
+ NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
+ 3 /* press-SI */, 3 /* release-SI */, 2 /* typed-SI */,
+ 0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
final List<EventObject> queue = keyAdapter.getQueued();
int i=0;
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, 0, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, 0, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, 0, KeyEvent.VK_P);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, 0, keyCode, keyCharOnly);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, 0, keyCode, keyCharOnly);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, 0, keyCode, keyCharOnly);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, modifierKey);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, modifierMask, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, modifierKey);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, modifierMask, modifierKey);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, modifierKey, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, keyCode, keyCharMod);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, keyCode, keyCharMod);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, modifierMask, keyCode, keyCharMod);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, modifierKey, (char)0);
}
+ @SuppressWarnings("deprecation")
static void testKeyCodeAllModifierV1(Robot robot, NEWTKeyAdapter keyAdapter) {
final int m1k = KeyEvent.VK_ALT;
final int m1m = InputEvent.ALT_MASK;
@@ -180,32 +210,31 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
AWTRobotUtil.keyPress(0, robot, true, KeyEvent.VK_P, 10); // press P
AWTRobotUtil.keyPress(0, robot, false, KeyEvent.VK_P, 100); // release+typed P
- AWTRobotUtil.keyPress(0, robot, false, m3k, 10); // release+typed MOD
- AWTRobotUtil.keyPress(0, robot, false, m2k, 10); // release+typed MOD
- AWTRobotUtil.keyPress(0, robot, false, m1k, 10); // release+typed MOD
+ AWTRobotUtil.keyPress(0, robot, false, m3k, 10); // release MOD
+ AWTRobotUtil.keyPress(0, robot, false, m2k, 10); // release MOD
+ AWTRobotUtil.keyPress(0, robot, false, m1k, 10); // release MOD
robot.waitForIdle();
- for(int j=0; j < 20 && keyAdapter.getQueueSize() < 3*4; j++) { // wait until events are collected
+ for(int j=0; j < 40 && keyAdapter.getQueueSize() < 4+4+1; j++) { // wait until events are collected
robot.delay(100);
}
- NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, 3*4, 0);
+ NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
+ 4 /* press-SI */, 4 /* release-SI */, 1 /* typed-SI */,
+ 0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
final List<EventObject> queue = keyAdapter.getQueued();
int i=0;
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m, m1k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m, m2k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, m3k);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m, m1k, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m, m2k, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, m3k, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, KeyEvent.VK_P);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m|m2m|m3m, KeyEvent.VK_P);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, m3k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m|m2m|m3m, m3k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m, m2k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m|m2m, m2k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m, m1k);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m, m1k);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, m3k, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m, m2k, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m, m1k, (char)0);
}
void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException {
@@ -233,9 +262,11 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
AWTRobotUtil.requestFocus(robot, glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
glWindow1KA.reset();
- testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK);
- testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_CONTROL, InputEvent.CTRL_MASK);
- testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_ALT, InputEvent.ALT_MASK);
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_1, '1', '!');
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_Y, 'y', 'Y'); // US: Y, DE: Z
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_P, 'p', 'P');
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_CONTROL, InputEvent.CTRL_MASK, KeyEvent.VK_P, 'p', (char)0);
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_ALT, InputEvent.ALT_MASK, KeyEvent.VK_P, 'p', (char)0);
testKeyCodeAllModifierV1(robot, glWindow1KA);
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
index ef4b17375..b3ba71795 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
@@ -48,10 +48,13 @@ import javax.swing.JFrame;
import java.io.IOException;
+import jogamp.nativewindow.jawt.JAWTUtil;
+
import org.junit.BeforeClass;
import org.junit.Test;
import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
@@ -99,12 +102,14 @@ public class TestNewtKeyCodesAWT extends UITestCase {
glWindow.destroy();
}
- @Test
- public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ private void testNewtCanvasAWT_Impl(boolean onscreen) throws AWTException, InterruptedException, InvocationTargetException {
GLWindow glWindow = GLWindow.create(glCaps);
// Wrap the window in a canvas.
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ if( !onscreen ) {
+ newtCanvasAWT.setShallUseOffscreenLayer(true);
+ }
// Add the canvas to a frame, and make it all visible.
final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle());
@@ -131,7 +136,25 @@ public class TestNewtKeyCodesAWT extends UITestCase {
}
glWindow.destroy();
}
+
+ @Test
+ public void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("Platform doesn't support onscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(true);
+ }
+ @Test
+ public void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("Platform doesn't support offscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(false);
+ }
+
static CodeSeg[] codeSegments = new CodeSeg[] {
new CodeSeg(0x008, 0x008, "bs"),
// new CodeSeg(0x009, 0x009, "tab"), // TAB functions as focus traversal key
@@ -167,14 +190,29 @@ public class TestNewtKeyCodesAWT extends UITestCase {
keyAdapter.reset();
final CodeSeg codeSeg = codeSegments[i];
// System.err.println("*** Segment "+codeSeg.description);
- for(int c=codeSeg.min; c<=codeSeg.max; c++) {
+ int eventCount = 0;
+ for(short c=codeSeg.min; c<=codeSeg.max; c++) {
// System.err.println("*** KeyCode 0x"+Integer.toHexString(c));
- AWTRobotUtil.keyPress(0, robot, true, c, 10);
- AWTRobotUtil.keyPress(0, robot, false, c, 100);
+ try {
+ AWTRobotUtil.keyPress(0, robot, true, c, 10);
+ } catch (Exception e) {
+ System.err.println("Exception @ AWT Robot.PRESS "+MiscUtils.toHexString(c)+" - "+e.getMessage());
+ break;
+ }
+ eventCount++;
+ try {
+ AWTRobotUtil.keyPress(0, robot, false, c, 100);
+ } catch (Exception e) {
+ System.err.println("Exception @ AWT Robot.RELEASE "+MiscUtils.toHexString(c)+" - "+e.getMessage());
+ break;
+ }
+ eventCount++;
+ if( KeyEvent.isPrintableKey(c) ) {
+ eventCount++;
+ }
robot.waitForIdle();
}
- final int codeCount = codeSeg.max - codeSeg.min + 1;
- for(int j=0; j < 20 && keyAdapter.getQueueSize() < 3 * codeCount; j++) { // wait until events are collected
+ for(int j=0; j < 20 && keyAdapter.getQueueSize() < eventCount; j++) { // wait until events are collected
robot.delay(100);
}
final ArrayList<EventObject> events = new ArrayList<EventObject>(keyAdapter.getQueued());
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java
index 00fbc0500..d7de4e735 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java
@@ -153,6 +153,7 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase {
glWindow.destroy();
}
+ @SuppressWarnings("deprecation")
static void testKeyEventAutoRepeat(Robot robot, NEWTKeyAdapter keyAdapter, int loops, int pressDurationMS) {
System.err.println("KEY Event Auto-Repeat Test: "+loops);
EventObject[][] first = new EventObject[loops][3];
@@ -201,9 +202,19 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase {
final boolean hasAR = 0 < keyAdapter.getKeyPressedCount(true) ;
{
- final int expTotal = keyEvents.size();
- final int expAR = hasAR ? expTotal - 3 * 2 * loops : 0; // per loop: 3 for non AR events and 3 for non AR 'B'
- NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, expTotal, expAR);
+ final int perLoopSI = 2; // per loop: 1 non AR event and 1 for non AR 'B'
+ final int expSI, expAR;
+ if( hasAR ) {
+ expSI = perLoopSI * loops;
+ expAR = ( keyEvents.size() - expSI*3 ) / 2; // AR: no typed -> 2, SI: typed -> 3
+ } else {
+ expSI = keyEvents.size() / 3; // all typed events
+ expAR = 0;
+ }
+
+ NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
+ expSI /* press-SI */, expSI /* release-SI */, expSI /* typed-SI */,
+ expAR /* press-AR */, expAR /* release-AR */, 0 /* typed-AR */ );
}
if( !hasAR ) {
@@ -216,7 +227,7 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase {
NEWTKeyUtil.dumpKeyEvents(Arrays.asList(first[i]));
System.err.println("Auto-Repeat Loop "+i+" - Tail:");
NEWTKeyUtil.dumpKeyEvents(Arrays.asList(last[i]));
- }
+ }
for(int i=0; i<loops; i++) {
KeyEvent e = (KeyEvent) first[i][0];
Assert.assertTrue("1st Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
@@ -230,7 +241,7 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase {
e = (KeyEvent) first[i][2];
Assert.assertTrue("3rd Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
- Assert.assertTrue("3rd Shall be TYPED, but is "+e, KeyEvent.EVENT_KEY_TYPED == e.getEventType() );
+ Assert.assertTrue("3rd Shall be PRESSED, but is "+e, KeyEvent.EVENT_KEY_PRESSED == e.getEventType() );
Assert.assertTrue("3rd Shall be AR, but is "+e, 0 != ( InputEvent.AUTOREPEAT_MASK & e.getModifiers() ) );
e = (KeyEvent) last[i][0];
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
index 256536bbb..bdf932904 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
@@ -45,6 +45,8 @@ import javax.swing.JFrame;
import java.io.IOException;
+import jogamp.nativewindow.jawt.JAWTUtil;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -104,12 +106,14 @@ public class TestNewtKeyEventOrderAWT extends UITestCase {
glWindow.destroy();
}
- @Test
- public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ private void testNewtCanvasAWT_Impl(boolean onscreen) throws AWTException, InterruptedException, InvocationTargetException {
GLWindow glWindow = GLWindow.create(glCaps);
// Wrap the window in a canvas.
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ if( !onscreen ) {
+ newtCanvasAWT.setShallUseOffscreenLayer(true);
+ }
// Add the canvas to a frame, and make it all visible.
final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle());
@@ -137,6 +141,24 @@ public class TestNewtKeyEventOrderAWT extends UITestCase {
glWindow.destroy();
}
+ @Test
+ public void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("Platform doesn't support onscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(true);
+ }
+
+ @Test
+ public void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("Platform doesn't support offscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(false);
+ }
+
static void testKeyEventOrder(Robot robot, NEWTKeyAdapter keyAdapter, int loops) {
System.err.println("KEY Event Order Test: "+loops);
keyAdapter.reset();
@@ -167,7 +189,11 @@ public class TestNewtKeyEventOrderAWT extends UITestCase {
NEWTKeyUtil.validateKeyEventOrder(keyAdapter.getQueued());
- NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, 6*3*loops, 0);
+ final int expTotal = 6*loops; // all typed events
+ NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
+ expTotal /* press-SI */, expTotal /* release-SI */, expTotal /* typed-SI */,
+ 0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
+
}
void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyPressReleaseUnmaskRepeatAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyPressReleaseUnmaskRepeatAWT.java
index 61579998e..2a35a15eb 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyPressReleaseUnmaskRepeatAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyPressReleaseUnmaskRepeatAWT.java
@@ -45,6 +45,8 @@ import javax.swing.JFrame;
import java.io.IOException;
+import jogamp.nativewindow.jawt.JAWTUtil;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -98,12 +100,14 @@ public class TestNewtKeyPressReleaseUnmaskRepeatAWT extends UITestCase {
glWindow.destroy();
}
- @Test
- public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ private void testNewtCanvasAWT_Impl(boolean onscreen) throws AWTException, InterruptedException, InvocationTargetException {
GLWindow glWindow = GLWindow.create(glCaps);
// Wrap the window in a canvas.
final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ if( !onscreen ) {
+ newtCanvasAWT.setShallUseOffscreenLayer(true);
+ }
// Add the canvas to a frame, and make it all visible.
final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle());
@@ -131,6 +135,24 @@ public class TestNewtKeyPressReleaseUnmaskRepeatAWT extends UITestCase {
glWindow.destroy();
}
+ @Test
+ public void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( JAWTUtil.isOffscreenLayerRequired() ) {
+ System.err.println("Platform doesn't support onscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(true);
+ }
+
+ @Test
+ public void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
+ if( !JAWTUtil.isOffscreenLayerSupported() ) {
+ System.err.println("Platform doesn't support offscreen rendering.");
+ return;
+ }
+ testNewtCanvasAWT_Impl(false);
+ }
+
void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException {
final Robot robot = new Robot();
robot.setAutoWaitForIdle(true);
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java
index d6f1f817a..122138f6d 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java
@@ -191,6 +191,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase {
frame1.setVisible(true);
}});
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
AWTRobotUtil.clearAWTFocus(robot);
Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
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 ffc42e318..8b46760e1 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -28,6 +28,7 @@
package com.jogamp.opengl.test.junit.util;
+import jogamp.common.awt.AWTEDTExecutor;
import jogamp.newt.WindowImplAccess;
import java.lang.reflect.InvocationTargetException;
@@ -41,6 +42,8 @@ import javax.media.opengl.awt.GLCanvas;
import org.junit.Assert;
+import com.jogamp.newt.event.WindowEvent;
+
public class AWTRobotUtil {
static final boolean DEBUG = false;
@@ -646,16 +649,19 @@ public class AWTRobotUtil {
*
* @param obj either an AWT Window (Frame, JFrame) or NEWT Window
* @param willClose indicating that the window will close, hence this method waits for the window to be closed
+ * @param wcl the WindowClosingListener to determine whether the AWT or NEWT widget has been closed. It should be attached
+ * to the widget ASAP before any other listener, e.g. via {@link #addClosingListener(Object)}.
+ * The WindowClosingListener will be reset before attempting to close the widget.
* @return True if the Window is closing and closed (if willClose is true), each within TIME_OUT
* @throws InterruptedException
*/
- public static boolean closeWindow(Object obj, boolean willClose) throws InterruptedException, InvocationTargetException {
- WindowClosingListener closingListener = addClosingListener(obj);
+ public static boolean closeWindow(Object obj, boolean willClose, WindowClosingListener closingListener) throws InterruptedException {
+ closingListener.reset();
if(obj instanceof java.awt.Window) {
final java.awt.Window win = (java.awt.Window) obj;
java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
final java.awt.EventQueue evtQ = tk.getSystemEventQueue();
- java.awt.EventQueue.invokeAndWait(new Runnable() {
+ AWTEDTExecutor.singleton.invoke(true, new Runnable() {
public void run() {
evtQ.postEvent(new java.awt.event.WindowEvent(win, java.awt.event.WindowEvent.WINDOW_CLOSING));
} });
@@ -675,12 +681,15 @@ public class AWTRobotUtil {
return wait<POLL_DIVIDER;
}
- public static WindowClosingListener addClosingListener(Object obj) throws InterruptedException {
+ public static WindowClosingListener addClosingListener(Object obj) {
WindowClosingListener cl = null;
if(obj instanceof java.awt.Window) {
- java.awt.Window win = (java.awt.Window) obj;
- AWTWindowClosingAdapter acl = new AWTWindowClosingAdapter();
- win.addWindowListener(acl);
+ final java.awt.Window win = (java.awt.Window) obj;
+ final AWTWindowClosingAdapter acl = new AWTWindowClosingAdapter();
+ AWTEDTExecutor.singleton.invoke(true, new Runnable() {
+ public void run() {
+ win.addWindowListener(acl);
+ } } );
cl = acl;
} else if(obj instanceof com.jogamp.newt.Window) {
com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj;
@@ -694,53 +703,77 @@ public class AWTRobotUtil {
}
public static interface WindowClosingListener {
void reset();
+ public int getWindowClosingCount();
+ public int getWindowClosedCount();
public boolean isWindowClosing();
public boolean isWindowClosed();
}
static class AWTWindowClosingAdapter
extends java.awt.event.WindowAdapter implements WindowClosingListener
{
- volatile boolean closing = false;
- volatile boolean closed = false;
+ volatile int closing = 0;
+ volatile int closed = 0;
public void reset() {
- closing = false;
- closed = false;
+ closing = 0;
+ closed = 0;
}
- public boolean isWindowClosing() {
+ public int getWindowClosingCount() {
return closing;
}
- public boolean isWindowClosed() {
+ public int getWindowClosedCount() {
return closed;
}
+ public boolean isWindowClosing() {
+ return 0 < closing;
+ }
+ public boolean isWindowClosed() {
+ return 0 < closed;
+ }
public void windowClosing(java.awt.event.WindowEvent e) {
- closing = true;
+ closing++;
+ System.err.println("AWTWindowClosingAdapter.windowClosing: "+this);
}
public void windowClosed(java.awt.event.WindowEvent e) {
- closed = true;
+ closed++;
+ System.err.println("AWTWindowClosingAdapter.windowClosed: "+this);
+ }
+ public String toString() {
+ return "AWTWindowClosingAdapter[closing "+closing+", closed "+closed+"]";
}
}
static class NEWTWindowClosingAdapter
extends com.jogamp.newt.event.WindowAdapter implements WindowClosingListener
{
- volatile boolean closing = false;
- volatile boolean closed = false;
+ volatile int closing = 0;
+ volatile int closed = 0;
public void reset() {
- closing = false;
- closed = false;
+ closing = 0;
+ closed = 0;
}
- public boolean isWindowClosing() {
+ public int getWindowClosingCount() {
return closing;
}
- public boolean isWindowClosed() {
+ public int getWindowClosedCount() {
return closed;
}
- public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent e) {
- closing = true;
+ public boolean isWindowClosing() {
+ return 0 < closing;
+ }
+ public boolean isWindowClosed() {
+ return 0 < closed;
+ }
+ public void windowDestroyNotify(WindowEvent e) {
+ closing++;
+ System.err.println("NEWTWindowClosingAdapter.windowDestroyNotify: "+this);
+ }
+ public void windowDestroyed(WindowEvent e) {
+ closed++;
+ System.err.println("NEWTWindowClosingAdapter.windowDestroyed: "+this);
}
- public void windowDestroyed(com.jogamp.newt.event.WindowEvent e) {
- closed = true;
+ public String toString() {
+ return "NEWTWindowClosingAdapter[closing "+closing+", closed "+closed+"]";
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
index c230f0aa1..0aee0f087 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -51,6 +51,22 @@ public class MiscUtils {
return def;
}
+ public static String toHexString(byte hex) {
+ return "0x" + Integer.toHexString( (int)hex & 0x000000FF );
+ }
+
+ public static String toHexString(short hex) {
+ return "0x" + Integer.toHexString( (int)hex & 0x0000FFFF );
+ }
+
+ public static String toHexString(int hex) {
+ return "0x" + Integer.toHexString( hex );
+ }
+
+ public static String toHexString(long hex) {
+ return "0x" + Long.toHexString( hex );
+ }
+
public static void assertFloatBufferEquals(String errmsg, FloatBuffer expected, FloatBuffer actual, float delta) {
if(null == expected && null == actual) {
return;
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
index e090ed4cf..d007d2424 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
@@ -38,28 +38,28 @@ import com.jogamp.newt.event.KeyEvent;
public class NEWTKeyUtil {
public static class CodeSeg {
- public final int min;
- public final int max;
+ public final short min;
+ public final short max;
public final String description;
public CodeSeg(int min, int max, String description) {
- this.min = min;
- this.max = max;
+ this.min = (short)min;
+ this.max = (short)max;
this.description = description;
}
}
public static class CodeEvent {
- public final int code;
+ public final short code;
public final String description;
public final KeyEvent event;
- public CodeEvent(int code, String description, KeyEvent event) {
+ public CodeEvent(short code, String description, KeyEvent event) {
this.code = code;
this.description = description;
this.event = event;
}
public String toString() {
- return "Code 0x"+Integer.toHexString(code)+" != "+event+" // "+description;
+ return "Code 0x"+Integer.toHexString( (int)code & 0x0000FFFF )+" != "+event+" // "+description;
}
}
@@ -90,46 +90,63 @@ public class NEWTKeyUtil {
public static boolean validateKeyCodes(List<CodeEvent> missCodes, CodeSeg codeSeg, List<EventObject> keyEvents, boolean verbose) {
final int codeCount = codeSeg.max - codeSeg.min + 1;
int misses = 0;
+ int evtIdx = 0;
for(int i=0; i<codeCount; i++) {
- final int c = codeSeg.min + i;
- final int j = i*3+0; // KEY_PRESSED
- final KeyEvent e = (KeyEvent) ( j < keyEvents.size() ? keyEvents.get(j) : null );
- if( null == e || c != e.getKeyCode() ) {
+ // evtIdx -> KEY_PRESSED !
+ final short c = (short) ( codeSeg.min + i );
+ final KeyEvent e = (KeyEvent) ( evtIdx < keyEvents.size() ? keyEvents.get(evtIdx) : null );
+ if( null == e ) {
missCodes.add(new CodeEvent(c, codeSeg.description, e));
misses++;
+ evtIdx++;
+ } else {
+ if( c != e.getKeyCode() ) {
+ missCodes.add(new CodeEvent(c, codeSeg.description, e));
+ misses++;
+ }
+ if( KeyEvent.isPrintableKey(c) ) {
+ evtIdx += 3; // w/ TYPED
+ } else {
+ evtIdx += 2;
+ }
}
}
- final boolean res = 3*codeCount == keyEvents.size() && 0 == missCodes.size();
+ final boolean res = evtIdx == keyEvents.size() && 0 == missCodes.size();
if(verbose) {
System.err.println("+++ Code Segment "+codeSeg.description+", Misses: "+misses+" / "+codeCount+", events "+keyEvents.size()+", valid "+res);
}
return res;
}
- public static void validateKeyEvent(KeyEvent e, int eventType, int modifier, int keyCode) {
- if(0 <= keyCode) {
- Assert.assertTrue("KeyEvent code mismatch, expected 0x"+Integer.toHexString(keyCode)+", has "+e, keyCode == e.getKeyCode());
- }
+ public static void validateKeyEvent(KeyEvent e, int eventType, int modifier, int keyCode, char keyChar) {
if(0 <= eventType) {
Assert.assertTrue("KeyEvent type mismatch, expected 0x"+Integer.toHexString(eventType)+", has "+e, eventType == e.getEventType());
}
if(0 <= modifier) {
Assert.assertTrue("KeyEvent modifier mismatch, expected 0x"+Integer.toHexString(modifier)+", has "+e, modifier == e.getModifiers());
}
+ if(0 < keyCode) {
+ Assert.assertTrue("KeyEvent code mismatch, expected 0x"+Integer.toHexString(keyCode)+", has "+e, keyCode == e.getKeyCode());
+ }
+ if(0 < keyChar) {
+ Assert.assertTrue("KeyEvent char mismatch, expected 0x"+Integer.toHexString(keyChar)+", has "+e, keyChar == e.getKeyChar());
+ }
}
- public static int getNextKeyEventType(int et) {
+ @SuppressWarnings("deprecation")
+ public static short getNextKeyEventType(KeyEvent e) {
+ final int et = e.getEventType();
switch( et ) {
case KeyEvent.EVENT_KEY_PRESSED:
return KeyEvent.EVENT_KEY_RELEASED;
case KeyEvent.EVENT_KEY_RELEASED:
- return KeyEvent.EVENT_KEY_TYPED;
+ return e.isPrintableKey() && !e.isAutoRepeat() ? KeyEvent.EVENT_KEY_TYPED : KeyEvent.EVENT_KEY_PRESSED;
case KeyEvent.EVENT_KEY_TYPED:
return KeyEvent.EVENT_KEY_PRESSED;
default:
- Assert.assertTrue("Invalid event type "+et, false);
+ Assert.assertTrue("Invalid event "+e, false);
return 0;
- }
+ }
}
public static void validateKeyEventOrder(List<EventObject> keyEvents) {
@@ -141,45 +158,68 @@ public class NEWTKeyUtil {
eet = KeyEvent.EVENT_KEY_PRESSED;
}
final int et = e.getEventType();
- Assert.assertEquals("Key event not in proper order", eet, et);
- eet = getNextKeyEventType(et);
+ Assert.assertEquals("Key event not in proper order "+i+"/"+keyEvents.size()+" - event "+e, eet, et);
+ eet = getNextKeyEventType(e);
keyCode2NextEvent.put(e.getKeyCode(), eet);
}
}
/**
- *
* @param keyAdapter
- * @param expTotalCount number of key press/release/types events
- * @param expARCount number of key press/release/types Auto-Release events
+ * @param expPressedCountSI number of single key press events
+ * @param expReleasedCountSI number of single key release events
+ * @param expTypedCountSI number of single key types events
+ * @param expPressedCountAR number of auto-repeat key press events
+ * @param expReleasedCountAR number of auto-repeat key release events
+ * @param expTypedCountAR number of auto-repeat key types events
*/
- public static void validateKeyAdapterStats(NEWTKeyAdapter keyAdapter, int expTotalCount, int expARCount) {
- final int keyPressed = keyAdapter.getKeyPressedCount(false);
+ public static void validateKeyAdapterStats(NEWTKeyAdapter keyAdapter,
+ int expPressedCountSI, int expReleasedCountSI, int expTypedCountSI,
+ int expPressedCountAR, int expReleasedCountAR, int expTypedCountAR) {
+ final int expTotalCountSI = expPressedCountSI + expReleasedCountSI + expTypedCountSI;
+ final int expTotalCountAR = expPressedCountAR + expReleasedCountAR + expTypedCountAR;
+ final int expTotalCountALL = expTotalCountSI + expTotalCountAR;
+
+ final int keyPressedALL = keyAdapter.getKeyPressedCount(false);
final int keyPressedAR = keyAdapter.getKeyPressedCount(true);
- final int keyReleased = keyAdapter.getKeyReleasedCount(false);
+ final int keyReleasedALL = keyAdapter.getKeyReleasedCount(false);
final int keyReleasedAR = keyAdapter.getKeyReleasedCount(true);
- final int keyTyped = keyAdapter.getKeyTypedCount(false);
+ final int keyTypedALL = keyAdapter.getKeyTypedCount(false);
final int keyTypedAR = keyAdapter.getKeyTypedCount(true);
- final int keyPressedNR = keyPressed-keyPressedAR;
- final int keyReleasedNR = keyReleased-keyReleasedAR;
- final int keyTypedNR = keyTyped-keyTypedAR;
- System.err.println("Total Press "+keyPressed +", Release "+keyReleased +", Typed "+keyTyped);
- System.err.println("AutoR Press "+keyPressedAR+", Release "+keyReleasedAR+", Typed "+keyTypedAR);
- System.err.println("No AR Press "+keyPressedNR+", Release "+keyReleasedNR+", Typed "+keyTypedNR);
+
+ final int keyPressedSI = keyPressedALL-keyPressedAR;
+ final int keyReleasedSI = keyReleasedALL-keyReleasedAR;
+ final int keyTypedSI = keyTypedALL-keyTypedAR;
+
+ final int totalCountALL = keyPressedALL + keyReleasedALL + keyTypedALL;
+ final int totalCountSI = keyPressedSI + keyReleasedSI + keyTypedSI;
+ final int totalCountAR = keyPressedAR + keyReleasedAR + keyTypedAR;
+
+ System.err.println("Expec Single Press "+expPressedCountSI +", Release "+expReleasedCountSI +", Typed "+expTypedCountSI +", Events "+expTotalCountSI);
+ System.err.println("Expec AutoRp Press "+expPressedCountAR +", Release "+expReleasedCountAR +", Typed "+expTypedCountAR +", Events "+expTotalCountAR);
+
+ System.err.println("Total Single Press "+keyPressedSI +", Release "+keyReleasedSI +", Typed "+keyTypedSI +", Events "+totalCountSI);
+ System.err.println("Total AutoRp Press "+keyPressedAR +", Release "+keyReleasedAR +", Typed "+keyTypedAR +", Events "+totalCountAR);
+ System.err.println("Total ALL Press "+keyPressedALL +", Release "+keyReleasedALL +", Typed "+keyTypedALL+", Events "+totalCountALL);
+
+ Assert.assertEquals("Internal Error: totalSI != totalALL - totalAR", totalCountSI, totalCountALL - totalCountAR);
+
+ Assert.assertEquals("Invalid: Has AR Typed events", 0, keyTypedAR);
+ Assert.assertEquals("Invalid: Exp AR Typed events", 0, expTypedCountAR);
+
+ Assert.assertEquals("Key press count failure (SI)", expPressedCountSI, keyPressedSI);
+ Assert.assertEquals("Key released count failure (SI)", expReleasedCountSI, keyReleasedSI);
+ Assert.assertEquals("Key typed count failure (SI)", expTypedCountSI, keyTypedSI);
+
+ Assert.assertEquals("Key press count failure (AR)", expPressedCountAR, keyPressedAR);
+ Assert.assertEquals("Key released count failure (AR)", expReleasedCountAR, keyReleasedAR);
+
+ Assert.assertEquals("Key total count failure (SI)", expTotalCountSI, totalCountSI);
+ Assert.assertEquals("Key total count failure (AR)", expTotalCountAR, totalCountAR);
final List<EventObject> keyEvents = keyAdapter.getQueued();
- Assert.assertEquals("Key event count not multiple of 3", 0, keyEvents.size()%3);
- Assert.assertEquals("Key event count not 3 * press_release_count", expTotalCount, keyEvents.size());
- Assert.assertEquals("Key press count failure", expTotalCount/3, keyPressed);
- Assert.assertEquals("Key press count failure (AR)", expARCount/3, keyPressedAR);
- Assert.assertEquals("Key released count failure", expTotalCount/3, keyReleased);
- Assert.assertEquals("Key released count failure (AR)", expARCount/3, keyReleasedAR);
- Assert.assertEquals("Key typed count failure", expTotalCount/3, keyTyped);
- Assert.assertEquals("Key typed count failure (AR)", expARCount/3, keyTypedAR);
- // should be true - always, reaching this point - duh!
- Assert.assertEquals( ( expTotalCount - expARCount ) / 3, keyPressedNR);
- Assert.assertEquals( ( expTotalCount - expARCount ) / 3, keyReleasedNR);
- Assert.assertEquals( ( expTotalCount - expARCount ) / 3, keyTypedNR);
- }
+ Assert.assertEquals("Key total count failure (ALL) w/ list sum ", expTotalCountALL, totalCountALL);
+ Assert.assertEquals("Key total count failure (ALL) w/ list size ", expTotalCountALL, keyEvents.size());
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
index b028df377..44e2eeda7 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -28,7 +28,10 @@
package com.jogamp.opengl.test.junit.util;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
@@ -141,6 +144,14 @@ public abstract class UITestCase {
System.err.println("++++ UITestCase.tearDown: "+getFullTestName(" - "));
}
+ public static void waitForKey(String preMessage) {
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ System.err.println(preMessage+"> Press enter to continue");
+ try {
+ System.err.println(stdin.readLine());
+ } catch (IOException e) { }
+ }
+
static final String unsupportedTestMsg = "Test not supported on this platform.";
public String getSnapshotFilename(int sn, String postSNDetail, GLCapabilitiesImmutable caps, int width, int height, boolean sinkHasAlpha, String fileSuffix, String destPath) {