aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit/com/jogamp')
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java161
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java142
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/awt/TestAWT02WindowClosing.java111
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java153
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java169
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java316
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java125
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java126
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java114
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java184
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java202
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java330
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java70
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java188
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java91
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java107
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java79
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java492
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java110
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java146
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java109
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java320
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java391
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java110
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java212
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java301
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java411
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java258
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java167
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java137
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java293
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java193
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java189
-rw-r--r--src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java42
-rw-r--r--src/junit/com/jogamp/test/junit/newt/WindowEventCom2.java48
-rw-r--r--src/junit/com/jogamp/test/junit/newt/WindowEventCom3.java44
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java57
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java45
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java724
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java441
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java205
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java243
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java376
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java267
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java235
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03AWT.java203
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03bAWT.java258
-rw-r--r--src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java44
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java73
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java54
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java53
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java338
-rw-r--r--src/junit/com/jogamp/test/junit/util/DumpVersion.java61
-rw-r--r--src/junit/com/jogamp/test/junit/util/EventCountAdapter.java36
-rw-r--r--src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java49
-rw-r--r--src/junit/com/jogamp/test/junit/util/MiscUtils.java64
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java64
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java58
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java57
-rw-r--r--src/junit/com/jogamp/test/junit/util/QuitAdapter.java53
-rw-r--r--src/junit/com/jogamp/test/junit/util/SingletonInstance.java143
-rw-r--r--src/junit/com/jogamp/test/junit/util/UITestCase.java73
62 files changed, 10915 insertions, 0 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java
new file mode 100644
index 000000000..0c64cfdf2
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.acore;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.DumpVersion;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import com.jogamp.newt.*;
+import com.jogamp.newt.opengl.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+public class TestGLProfile01NEWT extends UITestCase {
+ static GLProfile glp;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ @Test
+ public void test01GLProfileDefault() {
+ System.out.println("GLProfile <static> "+GLProfile.glAvailabilityToString());
+ GLProfile glp = GLProfile.getDefault();
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test02GLProfileMaxFixedFunc() {
+ // Assuming at least one fixed profile is available
+ GLProfile glp = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile <static> getMaxFixedFunc(): "+glp);
+ if(glp.getName().equals(GLProfile.GL4bc)) {
+ Assert.assertTrue(GLProfile.isGL4bcAvailable());
+ Assert.assertTrue(GLProfile.isGL3bcAvailable());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL3bc)) {
+ Assert.assertTrue(GLProfile.isGL3bcAvailable());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2)) {
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2ES1)) {
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ }
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test03GLProfileMaxProgrammable() {
+ // Assuming at least one programmable profile is available
+ GLProfile glp = GLProfile.getMaxProgrammable();
+ System.out.println("GLProfile <static> getMaxProgrammable(): "+glp);
+ if(glp.getName().equals(GLProfile.GL4)) {
+ Assert.assertTrue(GLProfile.isGL4Available());
+ Assert.assertTrue(GLProfile.isGL3Available());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL3)) {
+ Assert.assertTrue(GLProfile.isGL3Available());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2)) {
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2ES2)) {
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ }
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test04GLProfileGL2ES1() {
+ if(!GLProfile.isGL2ES1Available()) {
+ System.out.println("GLProfile GL2ES1 n/a");
+ return;
+ }
+ GLProfile glp = GLProfile.getGL2ES1();
+ System.out.println("GLProfile <static> GL2ES1: "+glp);
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test05GLProfileGL2ES2() {
+ if(!GLProfile.isGL2ES2Available()) {
+ System.out.println("GLProfile GL2ES2 n/a");
+ return;
+ }
+ GLProfile glp = GLProfile.getGL2ES2();
+ System.out.println("GLProfile <static> GL2ES2: "+glp);
+ dumpVersion(glp);
+ }
+
+ protected void dumpVersion(GLProfile glp) {
+ GLCapabilities caps = new GLCapabilities(glp);
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("TestGLProfile01NEWT");
+
+ glWindow.addGLEventListener(new DumpVersion());
+
+ glWindow.setSize(128, 128);
+ glWindow.setVisible(true);
+ glWindow.display();
+ glWindow.destroy(true);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestGLProfile01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java
new file mode 100644
index 000000000..f3c228a5d
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java
@@ -0,0 +1,142 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.awt;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+import java.awt.Frame;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+
+public class TestAWT01GLn extends UITestCase {
+ Frame frame=null;
+ GLCanvas glCanvas=null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton(true);
+ System.out.println("GLProfile <static> "+GLProfile.glAvailabilityToString());
+ }
+
+ @Before
+ public void init() {
+ frame = new Frame("Texture Test");
+ Assert.assertNotNull(frame);
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas);
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ frame.remove(glCanvas);
+ frame.dispose();
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ frame=null;
+ glCanvas=null;
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ glCanvas = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas);
+ frame.add(glCanvas);
+ frame.setSize(512, 512);
+
+ glCanvas.addGLEventListener(new Gears());
+
+ glCanvas.display(); // one in process display
+
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(true);
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ Animator animator = new Animator(glCanvas);
+ animator.start();
+
+ Thread.sleep(500); // 500 ms
+
+ animator.stop();
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+ System.out.println("GLProfile Default: "+glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test03GLMaxFixed() throws InterruptedException {
+ GLProfile maxFixed = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile MaxFixed: "+maxFixed);
+ GLCapabilities caps = new GLCapabilities(maxFixed);
+ try {
+ runTestGL(caps);
+ } catch (Throwable t) {
+ // FIXME:
+ // Stop test and ignore if GL3bc and GL4bc
+ // currently this won't work on ATI!
+ if(maxFixed.equals(GLProfile.GL3bc) ||
+ maxFixed.equals(GLProfile.GL4bc)) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ // else .. serious unexpected exception
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT02WindowClosing.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT02WindowClosing.java
new file mode 100644
index 000000000..6132f8232
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT02WindowClosing.java
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.awt;
+
+import com.jogamp.test.junit.util.UITestCase;
+import javax.media.opengl.GLProfile;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestAWT02WindowClosing extends UITestCase {
+
+ static long durationPerTest = 200; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @Test
+ public void test01WindowClosing() throws InterruptedException {
+ Frame frame = new Frame();
+ frame.setSize(500, 500);
+ ClosingWindowAdapter closingWindowAdapter = new ClosingWindowAdapter(frame);
+ frame.addWindowListener(closingWindowAdapter);
+ final Frame _frame = frame;
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _frame.setVisible(true);
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ Thread.sleep(durationPerTest);
+ if(!closingWindowAdapter.closingCalled) {
+ // programatically issue windowClosing
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ EventQueue evtQ = tk.getSystemEventQueue();
+ evtQ.postEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
+ Thread.sleep(200);
+ }
+ Assert.assertEquals(true, closingWindowAdapter.closingCalled);
+ }
+
+ static class ClosingWindowAdapter extends WindowAdapter {
+ boolean closingCalled = false;
+ Frame frame;
+ public ClosingWindowAdapter(Frame frame) {
+ this.frame = frame;
+ }
+ public void windowClosing(WindowEvent ev) {
+ System.out.println("windowClosing() called ..");
+ closingCalled = true;
+ frame.dispose();
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ org.junit.runner.JUnitCore.main(TestAWT02WindowClosing.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java
new file mode 100644
index 000000000..03d4f37bf
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.awt;
+
+import java.lang.reflect.InvocationTargetException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import java.awt.Frame;
+import java.awt.Window;
+import javax.swing.JFrame;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assume.*;
+import static org.junit.Assert.*;
+import static javax.swing.SwingUtilities.*;
+
+/**
+ * Tests context creation + display on various kinds of Window implementations.
+ * @author Michael Bien
+ */
+public class TestSwingAWT01GLn extends UITestCase {
+ private Window[] windows;
+
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton(true);
+ System.out.println("GLProfile <static> "+GLProfile.glAvailabilityToString());
+ }
+
+ @Before
+ public void init() {
+ windows = new Window[]{
+ new Window(null),
+ new Frame("Frame GL test"),
+ new JFrame("JFrame GL test")
+ };
+ }
+
+ protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
+
+ for (final Window window : windows) {
+
+ System.out.println("testing with "+window.getClass().getName());
+
+ // final array as mutable container hack
+ final GLCanvas[] glCanvas = new GLCanvas[1];
+
+ Runnable test = new Runnable() {
+ public void run() {
+ glCanvas[0] = new GLCanvas(caps);
+ glCanvas[0].addGLEventListener(new Gears());
+ window.add(glCanvas[0]);
+ window.setSize(512, 512);
+ glCanvas[0].display();
+ window.setVisible(true);
+ }
+ };
+
+ Runnable cleanup = new Runnable() {
+ public void run() {
+ System.out.println("cleaning up...");
+ window.setVisible(false);
+ try {
+ window.removeAll();
+ } catch (Throwable t) {
+ assumeNoException(t);
+ t.printStackTrace();
+ }
+ window.dispose();
+ }
+
+ };
+
+ // AWT / Swing on EDT..
+ invokeAndWait(test);
+
+ Animator animator = new Animator(glCanvas[0]);
+ animator.start();
+ Thread.sleep(1000);
+ animator.stop();
+
+ // AWT / Swing on EDT..
+ invokeAndWait(cleanup);
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException, InvocationTargetException {
+ GLProfile glp = GLProfile.getDefault();
+ System.out.println("GLProfile Default: "+glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test03GLMaxFixed() throws InterruptedException, InvocationTargetException {
+ GLProfile maxFixed = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile MaxFixed: "+maxFixed);
+ GLCapabilities caps = new GLCapabilities(maxFixed);
+ try {
+ runTestGL(caps);
+ } catch (Throwable t) {
+ // FIXME:
+ // Stop test and ignore if GL3bc and GL4bc
+ // currently this won't work on ATI!
+ if(maxFixed.getName().equals(GLProfile.GL3bc) ||
+ maxFixed.getName().equals(GLProfile.GL4bc)) {
+ t.printStackTrace();
+ assumeNoException(t);
+ }
+ // else .. serious unexpected exception
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestSwingAWT01GLn.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java
new file mode 100644
index 000000000..be416f01d
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java
@@ -0,0 +1,169 @@
+package com.jogamp.test.junit.jogl.demos.es1;
+
+import com.jogamp.common.nio.Buffers;
+import java.nio.*;
+import java.util.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.*;
+import com.jogamp.opengl.util.glsl.fixedfunc.*;
+
+public class RedSquare implements GLEventListener {
+
+ public static boolean glDebugEmu = false;
+ public static boolean glDebug = false ;
+ public static boolean glTrace = false ;
+ public static boolean oneThread = false;
+ public static boolean useAnimator = false;
+ public static int swapInterval = -1;
+
+ boolean debug = false;
+ long startTime = 0;
+ long curTime = 0;
+
+ GLU glu = null;
+
+ public RedSquare() {
+ this(false);
+ }
+
+ public RedSquare(boolean debug) {
+ this.debug = debug;
+ }
+
+ // FIXME: we must add storage of the pointers in the GL state to
+ // the GLImpl classes. The need for this can be seen by making
+ // these variables method local instead of instance members. The
+ // square will disappear after a second or so due to garbage
+ // collection. On desktop OpenGL this implies a stack of
+ // references due to the existence of glPush/PopClientAttrib. On
+ // OpenGL ES 1/2 it can simply be one set of references.
+ private FloatBuffer colors;
+ private FloatBuffer vertices;
+
+ public void init(GLAutoDrawable drawable) {
+ System.out.println("RedSquare: Init");
+ GL _gl = drawable.getGL();
+
+ if(glDebugEmu) {
+ try {
+ // Debug ..
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES2.class, _gl, null) );
+
+ if(glTrace) {
+ // Trace ..
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
+ }
+ } catch (Exception e) {e.printStackTrace();}
+ glDebug = false;
+ glTrace = false;
+ }
+
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl);
+ if(swapInterval>=0) {
+ gl.setSwapInterval(swapInterval);
+ }
+
+ if(glDebug) {
+ try {
+ // Debug ..
+ gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) );
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ if(glTrace) {
+ try {
+ // Trace ..
+ gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) );
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ glu = GLU.createGLU(gl);
+
+ if(debug) {
+ System.err.println(Thread.currentThread()+" Entering initialization");
+ System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile());
+ System.err.println(Thread.currentThread()+" GL:" + gl);
+ System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println(Thread.currentThread()+" GL_EXTENSIONS:");
+ System.err.println(Thread.currentThread()+" " + gl.glGetString(gl.GL_EXTENSIONS));
+ System.err.println(Thread.currentThread()+" swapInterval: " + swapInterval + " (GL: "+gl.getSwapInterval()+")");
+ System.err.println(Thread.currentThread()+" GLU: " + glu);
+ }
+
+ // Allocate vertex arrays
+ colors = Buffers.newDirectFloatBuffer(16);
+ vertices = Buffers.newDirectFloatBuffer(12);
+ // Fill them up
+ colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1);
+ colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1);
+ colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1);
+ colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1);
+ vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0);
+ vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0);
+ vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0);
+ vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);
+ gl.glColorPointer(4, GL.GL_FLOAT, 0, colors);
+
+ // OpenGL Render Settings
+ gl.glClearColor(0, 0, 0, 1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+
+ startTime = System.currentTimeMillis();
+ curTime = startTime;
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ System.out.println("RedSquare: Reshape");
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ // Set location in front of camera
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
+ //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ curTime = System.currentTimeMillis();
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ // One rotation every four seconds
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0, 0, -10);
+ float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f;
+ gl.glRotatef(ang, 0, 0, 1);
+ gl.glRotatef(ang, 0, 1, 0);
+
+
+ // Draw a square
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.out.println("RedSquare: Dispose");
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ if(debug) {
+ System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext());
+ }
+ gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ glu.destroy();
+ glu = null;
+ colors.clear();
+ colors = null;
+ vertices.clear();
+ vertices = null;
+ if(debug) {
+ System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN");
+ }
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
new file mode 100644
index 000000000..d9194c216
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
@@ -0,0 +1,316 @@
+
+package com.jogamp.test.junit.jogl.demos.gl2.gears;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.event.awt.*;
+import com.jogamp.newt.Window;
+
+/**
+ * Gears.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+
+public class Gears implements GLEventListener {
+ private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
+ private int gear1, gear2, gear3;
+ private float angle = 0.0f;
+ private int swapInterval;
+
+ private boolean mouseRButtonDown = false;
+ private int prevMouseX, prevMouseY;
+
+ public Gears(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public Gears() {
+ this.swapInterval = 1;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ System.err.println("Gears: Init");
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ GL2 gl = drawable.getGL().getGL2();
+
+ float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
+ float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
+ float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
+ float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
+
+ gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0);
+ gl.glEnable(GL2.GL_CULL_FACE);
+ gl.glEnable(GL2.GL_LIGHTING);
+ gl.glEnable(GL2.GL_LIGHT0);
+ gl.glEnable(GL2.GL_DEPTH_TEST);
+
+ /* make the gears */
+ gear1 = gl.glGenLists(1);
+ gl.glNewList(gear1, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0);
+ gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
+ gl.glEndList();
+
+ gear2 = gl.glGenLists(1);
+ gl.glNewList(gear2, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0);
+ gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
+ gl.glEndList();
+
+ gear3 = gl.glGenLists(1);
+ gl.glNewList(gear3, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0);
+ gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
+ gl.glEndList();
+
+ gl.glEnable(GL2.GL_NORMALIZE);
+
+ // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter());
+ MouseListener gearsMouse = new GearsMouseAdapter();
+
+ if (drawable instanceof Window) {
+ Window window = (Window) drawable;
+ window.addMouseListener(gearsMouse);
+ } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) drawable;
+ new AWTMouseAdapter(gearsMouse).addTo(comp);
+ }
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.setSwapInterval(swapInterval);
+
+ float h = (float)height / (float)width;
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+
+ gl.glLoadIdentity();
+ gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, 0.0f, -40.0f);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.err.println("Gears: Dispose");
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ // Turn the gears' teeth
+ angle += 2.0f;
+
+ // Get the GL corresponding to the drawable we are animating
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ // Special handling for the case where the GLJPanel is translucent
+ // and wants to be composited with other Java 2D content
+ if (GLProfile.isAWTAvailable() &&
+ (drawable instanceof javax.media.opengl.awt.GLJPanel) &&
+ !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() &&
+ ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
+ gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
+ } else {
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ }
+
+ // Rotate the entire assembly of gears based on how the user
+ // dragged the mouse around
+ gl.glPushMatrix();
+ gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
+ // Place the first gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.0f, -2.0f, 0.0f);
+ gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear1);
+ gl.glPopMatrix();
+
+ // Place the second gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(3.1f, -2.0f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear2);
+ gl.glPopMatrix();
+
+ // Place the third gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.1f, 4.2f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear3);
+ gl.glPopMatrix();
+
+ // Remember that every push needs a pop; this one is paired with
+ // rotating the entire gear assembly
+ gl.glPopMatrix();
+ }
+
+ public static void gear(GL2 gl,
+ float inner_radius,
+ float outer_radius,
+ float width,
+ int teeth,
+ float tooth_depth)
+ {
+ int i;
+ float r0, r1, r2;
+ float angle, da;
+ float u, v, len;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth / 2.0f;
+ r2 = outer_radius + tooth_depth / 2.0f;
+
+ da = 2.0f * (float) Math.PI / teeth / 4.0f;
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+
+ /* draw front face */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ if(i < teeth)
+ {
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
+ }
+ }
+ gl.glEnd();
+
+ /* draw front sides of teeth */
+ gl.glBegin(GL2.GL_QUADS);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw back face */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw back sides of teeth */
+ gl.glBegin(GL2.GL_QUADS);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw outward faces of teeth */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle);
+ v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle);
+ len = (float)Math.sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+ gl.glNormal3f(v, -u, 0.0f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
+ gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
+ u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da);
+ v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da);
+ gl.glNormal3f(v, -u, 0.0f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ }
+ gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
+ gl.glEnd();
+
+ gl.glShadeModel(GL2.GL_SMOOTH);
+
+ /* draw inside radius cylinder */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ }
+ gl.glEnd();
+ }
+
+ class GearsMouseAdapter extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+ if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
+ mouseRButtonDown = true;
+ }
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
+ mouseRButtonDown = false;
+ }
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ int width=0, height=0;
+ Object source = e.getSource();
+ if(source instanceof Window) {
+ Window window = (Window) source;
+ width=window.getWidth();
+ height=window.getHeight();
+ } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) source;
+ width=comp.getWidth();
+ height=comp.getHeight();
+ } else {
+ throw new RuntimeException("Event source neither Window nor Component: "+source);
+ }
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ }
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java
new file mode 100644
index 000000000..9639c384b
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.demos.gl2.gears;
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.Animator;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.newt.event.awt.AWTKeyAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.newt.event.TraceKeyAdapter;
+import com.jogamp.newt.event.TraceWindowAdapter;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.QuitAdapter;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import java.awt.Frame;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestGearsAWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ Frame frame = new Frame("Gears AWT Test");
+ Assert.assertNotNull(frame);
+
+ GLCanvas glCanvas = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas);
+ frame.add(glCanvas);
+ frame.setSize(512, 512);
+
+ glCanvas.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glCanvas);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas);
+ new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
+
+ frame.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas);
+ Assert.assertNotNull(animator);
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ frame.setVisible(false);
+ Assert.assertEquals(false, frame.isVisible());
+ frame.remove(glCanvas);
+ frame.dispose();
+ frame=null;
+ glCanvas=null;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java
new file mode 100644
index 000000000..f88d4d16f
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.demos.gl2.gears.newt;
+
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.QuitAdapter;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestGearsNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Gears NEWT Test");
+
+ glWindow.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glWindow);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+
+ final GLWindow f_glWindow = glWindow;
+ glWindow.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='f') {
+ f_glWindow.invoke(false, new GLRunnable() {
+ public void run(GLAutoDrawable drawable) {
+ GLWindow win = (GLWindow)drawable;
+ win.setFullscreen(!win.isFullscreen());
+ } });
+ }
+ }
+ });
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.destroy(true);
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsNEWT.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java
new file mode 100644
index 000000000..c965d5c21
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.demos.gl2.gears.newt;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.QuitAdapter;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestGearsNewtAWTWrapper extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display
+ Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0
+ Window nWindow = NewtFactory.createWindow(nScreen, caps);
+
+ GLWindow glWindow = GLWindow.create(nWindow);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Gears NewtAWTWrapper Test");
+
+ glWindow.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glWindow);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.destroy(true);
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsNewtAWTWrapper.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
new file mode 100644
index 000000000..95db913ab
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
@@ -0,0 +1,184 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.drawable;
+
+import com.jogamp.test.junit.util.UITestCase;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+public class TestDrawable01NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLDrawableFactory factory;
+ static int width, height;
+ GLCapabilities caps;
+ Window window;
+ GLDrawable drawable;
+ GLContext context;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ factory = GLDrawableFactory.getFactory(glp);
+ Assert.assertNotNull(factory);
+ width = 640;
+ height = 480;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ Assert.assertNotNull(factory);
+ factory=null;
+ }
+
+ @Before
+ public void initTest() {
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ void createWindow(boolean onscreen, boolean pbuffer, boolean undecorated) {
+ caps.setOnscreen(onscreen);
+ caps.setPBuffer(!onscreen && pbuffer);
+ caps.setDoubleBuffered(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ window.setVisible(true);
+ // System.out.println("Created: "+window);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(glCaps);
+ Assert.assertTrue(glCaps.getGreenBits()>5);
+ Assert.assertTrue(glCaps.getBlueBits()>5);
+ Assert.assertTrue(glCaps.getRedBits()>5);
+ Assert.assertEquals(glCaps.isOnscreen(),onscreen);
+ Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer
+ Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen);
+ Assert.assertTrue(glCaps.getDepthBits()>4);
+
+ drawable = factory.createGLDrawable(window);
+ Assert.assertNotNull(drawable);
+ // System.out.println("Pre: "+drawable);
+ //
+ drawable.setRealized(true);
+ // Assert.assertEquals(width,drawable.getWidth());
+ // Assert.assertEquals(height,drawable.getHeight());
+ // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities());
+ Assert.assertEquals(window,drawable.getNativeSurface());
+ // System.out.println("Post: "+drawable);
+
+ context = drawable.createContext(null);
+ Assert.assertNotNull(context);
+ // System.out.println(context);
+
+ int res = context.makeCurrent();
+ Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res);
+
+ // draw something ..
+
+ drawable.swapBuffers();
+ context.release();
+
+ // System.out.println("Final: "+window);
+ }
+
+ void destroyWindow() {
+ // GLWindow.dispose(..) sequence
+ Assert.assertNotNull(context);
+ context.destroy();
+
+ Assert.assertNotNull(drawable);
+ drawable.setRealized(false);
+
+ // GLWindow.destroy(..) sequence cont..
+ Assert.assertNotNull(window);
+ window.destroy(true); // incl screen + display
+
+ drawable = null;
+ context = null;
+ window = null;
+ }
+
+ @Test
+ public void testOnScreenDecorated() throws InterruptedException {
+ createWindow(true, false, false);
+ Thread.sleep(1000); // 1000 ms
+ destroyWindow();
+ }
+
+ @Test
+ public void testOnScreenUndecorated() throws InterruptedException {
+ createWindow(true, false, true);
+ Thread.sleep(1000); // 1000 ms
+ destroyWindow();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestDrawable01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java b/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java
new file mode 100644
index 000000000..0d9a595aa
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java
@@ -0,0 +1,202 @@
+package com.jogamp.test.junit.jogl.glsl;
+
+import com.jogamp.test.junit.util.UITestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import javax.media.opengl.GL3;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.opengl.util.glsl.ShaderUtil;
+
+import java.io.IOException;
+
+/**
+ * Bug 'Function glTransformFeedbackVaryings incorrectly passes argument'
+ * http://jogamp.org/bugzilla/show_bug.cgi?id=407
+ */
+public class TestTransformFeedbackVeryingsBug407NEWT extends UITestCase {
+
+ private GLContext context;
+ private String VERTEX_SHADER_TEXT;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @Before
+ public void setUp() {
+ if(!GLProfile.isGL3Available()) {
+ System.err.println("GL3 not available");
+ System.err.println(GLProfile.glAvailabilityToString());
+ return;
+ }
+ VERTEX_SHADER_TEXT =
+ "#version 150 \n"
+ + " \n"
+ + "out vec4 Position; \n"
+ + " \n"
+ + "void main() { \n"
+ + " Position = vec4(1.0, 1.0, 1.0, 1.0); \n"
+ + "} \n";
+
+ GLCapabilities caps;
+ Window window;
+ GLDrawable drawable;
+
+ GLProfile glp = null;
+ try {
+ glp = GLProfile.get(GLProfile.GL3);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ caps = new GLCapabilities(glp);
+
+ caps.setOnscreen(true);
+ caps.setDoubleBuffered(true);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+
+ window = NewtFactory.createWindow(screen, caps);
+ window.setUndecorated(true);
+ window.setSize(800, 600);
+ window.setVisible(true);
+
+ drawable = GLDrawableFactory.getFactory(glp).createGLDrawable(window);
+ drawable.setRealized(true);
+
+ context = drawable.createContext(null);
+
+ context.makeCurrent();
+ }
+
+ @After
+ public void tearDown() {
+ if(null!=context) {
+ context.release();
+ }
+ }
+
+ private int getShader(GL3 gl, String text, int type) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ int shaderProgram = gl.glCreateProgram();
+
+ int vertShader = gl.glCreateShader(type);
+
+ String[] lines = new String[]{text};
+ int[] lengths = new int[]{lines[0].length()};
+ gl.glShaderSource(vertShader, lines.length, lines, lengths, 0);
+ gl.glCompileShader(vertShader);
+
+ if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) {
+ System.out.println("getShader:postCompile: "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+
+ gl.glAttachShader(shaderProgram, vertShader);
+
+
+ return shaderProgram;
+ }
+
+ @Test
+ public void testGlTransformFeedbackVaryings_WhenVarNameOK() {
+ if(!GLProfile.isGL3Available()) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ // given
+
+ GL3 gl = context.getGL().getGL3();
+ int shaderProgram = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER);
+ String[] vars = new String[]{"Position"};
+
+ // when
+
+ gl.glTransformFeedbackVaryings(shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS);
+ gl.glLinkProgram(shaderProgram);
+
+ // then
+
+ if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) {
+ System.out.println("testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+
+ Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError());
+ }
+
+ @Test
+ public void testGlTransformFeedbackVaryings_WhenVarNameWrong() {
+ if(!GLProfile.isGL3Available()) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ // given
+
+ GL3 gl = context.getGL().getGL3();
+ int shaderProgram = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER);
+ String[] vars = new String[]{"PPPosition"};
+
+ // when
+
+ gl.glTransformFeedbackVaryings(shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS);
+ gl.glLinkProgram(shaderProgram);
+
+ // then
+
+ if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) {
+ System.out.println("testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString());
+ // should be invalid, due to wrong var name
+ } else {
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+
+ Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError());
+ // You cannot assume this error message - Assert.assertTrue(baos.toString().contains("(named PPPosition)"));
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestTransformFeedbackVeryingsBug407NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java
new file mode 100644
index 000000000..79d899b6c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java
@@ -0,0 +1,330 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.newt;
+
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.*;
+
+import java.lang.reflect.InvocationTargetException;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.media.opengl.GLEventListener;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.BorderFactory;
+import javax.swing.border.Border;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase {
+ static long durationPerTest = 500; // ms
+ static Robot robot;
+ static Border border;
+ static JFrame frame;
+ static JButton button;
+ static JPanel panel;
+ static JPanel colorPanel;
+ static boolean windowClosing;
+
+ boolean modLightBrighter = true;
+
+ Color modLight(Color c) {
+ Color c2;
+ if(modLightBrighter) {
+ c2 = c.brighter();
+ } else {
+ c2 = c.darker();
+ }
+ if(c2.equals(c)) {
+ modLightBrighter = !modLightBrighter;
+ }
+ return c2;
+ }
+
+ class SwingGLAction implements GLEventListener {
+ public void init(GLAutoDrawable glad) {
+ }
+
+ public void dispose(GLAutoDrawable glad) {
+ }
+
+ public void display(GLAutoDrawable glad) {
+ colorPanel.setBackground(modLight(colorPanel.getBackground()));
+ colorPanel.repaint();
+ }
+
+ public void reshape(GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
+ }
+ }
+
+ @BeforeClass
+ public static void setup() throws InterruptedException, InvocationTargetException, AWTException {
+ int count;
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Start Pre-JOGL-Swing");
+
+ // GLProfile.initSingleton(false);
+ // GLProfile.initSingleton(true);
+
+ // simulate AWT usage before JOGL's initialization of X11 threading
+ windowClosing=false;
+ border = BorderFactory.createLineBorder (Color.yellow, 2);
+
+ panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+
+ button = new JButton("Click me");
+ button.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ System.err.println("Test: "+e);
+ }
+ });
+ panel.add(button, BorderLayout.NORTH);
+
+ colorPanel = new JPanel();
+ Dimension size = new Dimension(400,100);
+ colorPanel.setPreferredSize(size);
+ colorPanel.setBorder(border);
+ panel.add(colorPanel, BorderLayout.SOUTH);
+
+ frame = new JFrame("PRE JOGL");
+ frame.addWindowListener( new WindowAdapter() {
+ public void windowClosing(WindowEvent ev) {
+ windowClosing=true;
+ }
+ });
+ frame.setContentPane(panel);
+ frame.setSize(512, 512);
+ frame.setLocation(0, 0);
+ frame.pack();
+
+ // AWT/Swing: From here on (post setVisible(true)
+ // you need to use AWT/Swing's invokeAndWait()
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(true);
+ colorPanel.setBackground(Color.white);
+ colorPanel.repaint();
+ }});
+
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+
+ AWTRobotUtil.toFront(robot, frame);
+ AWTRobotUtil.requestFocus(robot, button);
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before JOGL init");
+
+ GLProfile.initSingleton(false);
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): End Pre-JOGL-Swing");
+ }
+
+ @AfterClass
+ public static void release() throws InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): Start");
+ robot = null;
+ Assert.assertNotNull(frame);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.dispose();
+ }
+ });
+ frame=null;
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): End");
+ }
+
+ protected void runTestGL(final Canvas canvas, GLAutoDrawable drawable)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ Dimension size = new Dimension(400,400);
+ canvas.setPreferredSize(size);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ panel.add(canvas, BorderLayout.CENTER);
+ frame.pack();
+ }
+ });
+
+ AWTRobotUtil.toFront(robot, frame);
+
+ drawable.addGLEventListener(new Gears());
+
+ for(int i=0; i<100; i++) {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ colorPanel.setBackground(modLight(colorPanel.getBackground()));
+ colorPanel.repaint();
+ }
+ });
+ drawable.display(); // one in process display
+ Thread.sleep(10);
+ }
+
+ colorPanel.setBackground(Color.blue);
+ drawable.addGLEventListener(new SwingGLAction());
+
+ Point p0 = canvas.getLocationOnScreen();
+ Rectangle r0 = canvas.getBounds();
+ robot.mouseMove( (int) ( p0.getX() + .5 ) ,
+ (int) ( p0.getY() + .5 ) );
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ for(int i=0; !windowClosing && i<durationPerTest/10; i++) {
+ p0.translate(1,1);
+ robot.mouseMove( (int) ( p0.getX() + .5 ) ,
+ (int) ( p0.getY() + .5 ) );
+ Thread.sleep(10);
+ }
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ for(int i=0; !windowClosing && i<durationPerTest/100; i++) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertNotNull(canvas);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ panel.remove(canvas);
+ frame.pack();
+ }
+ });
+ }
+
+ @Test
+ public void test01NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): Start");
+
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+
+ GLWindow win0 = GLWindow.create(caps);
+ win0.setSize(100,100);
+ win0.setVisible(true);
+ Screen screen = win0.getScreen();
+ win0.setPosition(screen.getWidth()-150, 0);
+ win0.addGLEventListener(new Gears());
+ Animator anim0 = new Animator(win0);
+ anim0.start();
+
+ GLWindow win1 = GLWindow.create(caps);
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(win1);
+ Animator anim1 = new Animator(win1);
+ anim1.start();
+ runTestGL(newtCanvasAWT, win1);
+
+ win0.destroy(true);
+ Assert.assertEquals(false, anim0.isAnimating());
+
+ newtCanvasAWT.destroy(true);
+ Assert.assertEquals(false, anim1.isAnimating());
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): End");
+ }
+
+ @Test
+ public void test02GLCanvas() throws AWTException, InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): Start");
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+
+ /**
+ * Using GLCanvas _and_ NEWT side by side currently causes a deadlock
+ * in AWT with AMD drivers !
+ *
+ GLWindow win0 = GLWindow.create(caps);
+ win0.setSize(100,100);
+ win0.setVisible(true);
+ Screen screen = win0.getScreen();
+ win0.setPosition(screen.getWidth()-150, 0);
+ win0.addGLEventListener(new Gears());
+ Animator anim0 = new Animator(win0);
+ anim0.start();
+ */
+
+ GLCanvas glCanvas = new GLCanvas(caps);
+ Animator anim1 = new Animator(glCanvas);
+ anim1.start();
+ runTestGL(glCanvas, glCanvas);
+
+ Thread.sleep(100); // wait 1/10Hz to allow animation to be paused
+ Assert.assertEquals(false, anim1.isAnimating());
+
+ /**
+ win0.destroy(true);
+ Assert.assertEquals(false, anim0.isAnimating());
+ */
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): End");
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ org.junit.runner.JUnitCore.main(TestSwingAWTRobotUsageBeforeJOGLInitBug411.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java
new file mode 100644
index 000000000..b09d27702
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import java.io.IOException;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.TextureIO;
+import java.io.File;
+
+public class ReadBuffer2File extends ReadBufferBase {
+
+ public ReadBuffer2File(GLDrawable externalRead) {
+ super(externalRead);
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ super.dispose(drawable);
+ }
+ int shotNum = 0;
+
+ void copyTextureData2File() throws IOException {
+ if (!readBufferUtil.isValid()) {
+ return;
+ }
+
+ File file = File.createTempFile("shot" + shotNum + "-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ System.out.println("Wrote: " + file.getAbsolutePath() + ", ...");
+ shotNum++;
+ readBufferUtil.rewindPixelBuffer();
+ }
+
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ super.display(drawable);
+ try {
+ copyTextureData2File();
+ } catch (IOException ex) {
+ throw new RuntimeException("can not read buffer to file", ex);
+ }
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java
new file mode 100644
index 000000000..5d414c708
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java
@@ -0,0 +1,188 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+
+import com.jogamp.opengl.util.*;
+
+import javax.media.opengl.fixedfunc.GLPointerFunc;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.GLArrayDataClient;
+import com.jogamp.opengl.util.GLArrayDataServer;
+
+public class ReadBuffer2Screen extends ReadBufferBase {
+ PMVMatrix pmvMatrix;
+ GLArrayDataClient readTextureVertices = null;
+ GLArrayDataClient readTextureCoords = null;
+ boolean enableBufferAlways = false; // FIXME
+ boolean enableBufferVBO = true; // FIXME
+
+ public ReadBuffer2Screen (GLDrawable externalRead) {
+ super(externalRead);
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+
+ GL gl = drawable.getGL();
+
+ pmvMatrix = new PMVMatrix();
+
+ float f_edge = 1f;
+ if(null==readTextureVertices) {
+ //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
+ // 2, GL.GL_FLOAT, true, 4);
+ readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ readTextureVertices.setEnableAlways(enableBufferAlways);
+ readTextureVertices.setVBOUsage(enableBufferVBO);
+ {
+ FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer();
+ vb.put(-f_edge); vb.put(-f_edge);
+ vb.put( f_edge); vb.put(-f_edge);
+ vb.put(-f_edge); vb.put( f_edge);
+ vb.put( f_edge); vb.put( f_edge);
+ }
+ readTextureVertices.seal(gl, true);
+ System.out.println(readTextureVertices);
+ }
+
+ // Clear background to gray
+ gl.glClearColor(0.5f, 0.5f, 0.5f, 0.4f);
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ super.reshape(drawable, x, y, width, height);
+
+ GL gl = drawable.getGL();
+
+ gl.glViewport(0, 0, width, height);
+
+ if(gl instanceof GLLightingFunc) {
+ ((GLLightingFunc)gl).glShadeModel(GLLightingFunc.GL_SMOOTH);
+ }
+
+ GLMatrixFunc glM;
+ if(gl instanceof GLMatrixFunc) {
+ glM = (GLMatrixFunc)gl;
+ } else {
+ throw new GLException("ES2 currently unhandled .. ");
+ }
+
+ // Identity ..
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -2.5f);
+ if(null!=glM) {
+ glM.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ glM.glLoadMatrixf(pmvMatrix.glGetMvMatrixf());
+ }
+
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
+ if(null!=glM) {
+ glM.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ glM.glLoadMatrixf(pmvMatrix.glGetPMatrixf());
+ }
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ super.dispose(drawable);
+ }
+
+ void renderOffscreenTexture(GL gl) {
+ if(!readBufferUtil.isValid()) return;
+
+ // Now draw one quad with the texture
+ readBufferUtil.getTexture().enable();
+ readBufferUtil.getTexture().bind();
+
+ if(gl.isGL2ES1()) {
+ // gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_REPLACE);
+ gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE);
+ }
+
+ updateTextureCoords(gl, false);
+
+ readTextureVertices.enableBuffer(gl, true);
+ if(null!=readTextureCoords) {
+ readTextureCoords.enableBuffer(gl, true);
+ }
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, readTextureVertices.getElementNumber());
+ /**
+ if(null!=readTextureCoords) {
+ readTextureCoords.enableBuffer(gl, false);
+ }
+ readTextureVertices.enableBuffer(gl, false); */
+
+ readBufferUtil.getTexture().disable();
+ }
+
+ void updateTextureCoords(GL gl, boolean force) {
+ if(force || null==readTextureCoords) {
+ readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0",
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ readTextureCoords.setEnableAlways(enableBufferAlways);
+ readTextureCoords.setVBOUsage(enableBufferVBO);
+ {
+ TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords();
+ FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer();
+ cb.put(coords.left()); cb.put(coords.bottom());
+ cb.put(coords.right()); cb.put(coords.bottom());
+ cb.put(coords.left()); cb.put(coords.top());
+ cb.put(coords.right()); cb.put(coords.top());
+ }
+ readTextureCoords.seal(gl, true);
+ System.out.println(readTextureCoords);
+ }
+ }
+
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ super.display(drawable);
+
+ GL gl = drawable.getGL();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+ if(gl instanceof GLLightingFunc) {
+ ((GLLightingFunc)gl).glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ renderOffscreenTexture(gl);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java
new file mode 100644
index 000000000..bd85dd879
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import javax.media.opengl.*;
+
+public class ReadBufferBase implements GLEventListener {
+ public boolean glDebug = false ;
+ public boolean glTrace = false ;
+
+ protected GLDrawable externalRead;
+
+ ReadBufferUtil readBufferUtil = new ReadBufferUtil();
+
+ public ReadBufferBase (GLDrawable externalRead) {
+ this.externalRead = externalRead ;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL _gl = drawable.getGL();
+
+ _gl.glGetError(); // flush error ..
+
+ if(glDebug) {
+ try {
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) );
+ } catch (Exception e) {
+ throw new RuntimeException("can not set debug pipeline", e);
+ }
+ }
+
+ if(glTrace) {
+ try {
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) );
+ } catch (Exception e) {
+ throw new RuntimeException("can not set trace pipeline", e);
+ }
+ }
+
+ System.out.println(_gl);
+
+ _gl.getContext().setGLDrawableRead(externalRead);
+ if(_gl.isGL2GL3()) {
+ _gl.getGL2GL3().glReadBuffer(GL2GL3.GL_FRONT);
+ }
+ System.out.println("---------------------------");
+ System.out.println(_gl.getContext());
+ System.out.println("---------------------------");
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ readBufferUtil.dispose();
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+
+ readBufferUtil.fetchOffscreenTexture(drawable, gl);
+ }
+
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java
new file mode 100644
index 000000000..f10a60a45
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import com.jogamp.opengl.util.GLBuffers;
+import java.nio.*;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureData;
+
+public class ReadBufferUtil {
+ protected int readPixelSizeLast = 0;
+ protected Buffer readPixelBuffer = null;
+ protected TextureData readTextureData = null;
+ protected Texture readTexture = new Texture(GL.GL_TEXTURE_2D);
+
+ public Buffer getPixelBuffer() { return readPixelBuffer; }
+ public void rewindPixelBuffer() { readPixelBuffer.rewind(); }
+
+ public TextureData getTextureData() { return readTextureData; }
+ public Texture getTexture() { return readTexture; }
+
+ public boolean isValid() {
+ return null!=readTexture && null!=readTextureData && null!=readPixelBuffer ;
+ }
+
+ public void fetchOffscreenTexture(GLDrawable drawable, GL gl) {
+ int readPixelSize = drawable.getWidth() * drawable.getHeight() * 3 ; // RGB
+ boolean newData = false;
+ if(readPixelSize>readPixelSizeLast) {
+ readPixelBuffer = GLBuffers.newDirectGLBuffer(GL.GL_UNSIGNED_BYTE, readPixelSize);
+ readPixelSizeLast = readPixelSize ;
+ try {
+ readTextureData = new TextureData(
+ gl.getGLProfile(),
+ // gl.isGL2GL3()?gl.GL_RGBA:gl.GL_RGB,
+ gl.GL_RGB,
+ drawable.getWidth(), drawable.getHeight(),
+ 0,
+ gl.GL_RGB,
+ gl.GL_UNSIGNED_BYTE,
+ false, false,
+ false /* flip */,
+ readPixelBuffer,
+ null /* Flusher */);
+ newData = true;
+ } catch (Exception e) {
+ readTextureData = null;
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ throw new RuntimeException("can not fetch offscreen texture", e);
+ }
+ }
+ if(null!=readPixelBuffer) {
+ readPixelBuffer.clear();
+ gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, readPixelBuffer);
+ readPixelBuffer.rewind();
+ if(newData) {
+ readTexture.updateImage(readTextureData);
+ } else {
+ readTexture.updateSubImage(readTextureData, 0,
+ 0, 0, // src offset
+ 0, 0, // dst offset
+ drawable.getWidth(), drawable.getHeight());
+ }
+ readPixelBuffer.rewind();
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void dispose() {
+ readTexture.dispose();
+ readTextureData = null;
+ readPixelBuffer.clear();
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ }
+
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java
new file mode 100644
index 000000000..c5d770bb8
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.TextureIO;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.media.nativewindow.*;
+
+public class Surface2File implements SurfaceUpdatedListener {
+
+ ReadBufferUtil readBufferUtil = new ReadBufferUtil();
+ int shotNum = 0;
+
+ public void dispose() {
+ readBufferUtil.dispose();
+ }
+
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ if (updater instanceof GLDrawable) {
+ GLDrawable drawable = (GLDrawable) updater;
+ GLContext ctx = GLContext.getCurrent();
+ if (null != ctx && ctx.getGLDrawable() == drawable) {
+ GL gl = ctx.getGL();
+ // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec
+ gl.glFinish();
+ readBufferUtil.fetchOffscreenTexture(drawable, gl);
+ gl.glFinish();
+ try {
+ surface2File("shot");
+ } catch (IOException ex) {
+ throw new RuntimeException("can not write survace to file", ex);
+ }
+ }
+ }
+ }
+
+ public void surface2File(String basename) throws IOException {
+ if (!readBufferUtil.isValid()) {
+ return;
+ }
+
+ File file = File.createTempFile(basename + shotNum + "-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ System.out.println("Wrote: " + file.getAbsolutePath() + ", ...");
+ shotNum++;
+ readBufferUtil.rewindPixelBuffer();
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
new file mode 100644
index 000000000..ea77b2876
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
@@ -0,0 +1,492 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import java.io.IOException;
+
+public class TestOffscreen01NEWT extends UITestCase {
+ static GLProfile glpDefault;
+ static GLDrawableFactory glDrawableFactory;
+ static int width, height;
+ GLCapabilities capsDefault;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glpDefault = GLProfile.getDefault();
+ Assert.assertNotNull(glpDefault);
+ glDrawableFactory = GLDrawableFactory.getFactory(glpDefault);
+ System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null));
+ width = 640;
+ height = 480;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ @Before
+ public void init() {
+ capsDefault = new GLCapabilities(glpDefault);
+ Assert.assertNotNull(capsDefault);
+ }
+
+ private void do01OffscreenWindowPBuffer(GLCapabilities caps) {
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ GLEventListener demo = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demo, window, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ while ( glWindow.getTotalFrames() < 2) {
+ try {
+ glWindow.display();
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test01aOffscreenWindowPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01bOffscreenWindowPBufferStencil() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setStencilBits(8);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01cOffscreenWindowPBufferStencilAlpha() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setStencilBits(8);
+ caps2.setAlphaBits(8);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01cOffscreenWindowPBuffer555() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setRedBits(5);
+ caps2.setGreenBits(5);
+ caps2.setBlueBits(5);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test02Offscreen3Windows1DisplayPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ int winnum = 3, i;
+ Window windows[] = new Window[winnum];
+ GLWindow glWindows[] = new GLWindow[winnum];
+ GLEventListener demos[] = new GLEventListener[winnum];
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ for(i=0; i<winnum; i++) {
+ System.out.println("Create Window "+i);
+ windows[i] = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(windows[i]);
+ windows[i].setSize(width, height);
+ glWindows[i] = GLWindow.create(windows[i]);
+ Assert.assertNotNull(glWindows[i]);
+ try {
+ glWindows[i].setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ demos[i] = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
+ glWindows[i].addGLEventListener(demos[i]);
+ }
+
+ try {
+ while ( glWindows[0].getTotalFrames() < 2) {
+ for(i=0; i<winnum; i++) {
+ glWindows[i].display();
+ }
+ }
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ for(i=0; i<winnum; i++) {
+ if(null!=glWindows[i]) {
+ glWindows[i].destroy();
+ }
+ if(null!=windows[i]) {
+ windows[i].destroy();
+ }
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test03Offscreen3Windows3DisplaysPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ int winnum = 3, i;
+ Display displays[] = new Display[winnum];
+ Screen screens[] = new Screen[winnum];
+ Window windows[] = new Window[winnum];
+ GLWindow glWindows[] = new GLWindow[winnum];
+ GLEventListener demos[] = new GLEventListener[winnum];
+
+ for(i=0; i<winnum; i++) {
+ System.out.println("Create Window "+i);
+ displays[i] = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(displays[i]);
+ screens[i] = NewtFactory.createScreen(displays[i], 0); // screen 0
+ Assert.assertNotNull(screens[i]);
+ windows[i] = NewtFactory.createWindow(screens[i], caps2);
+ Assert.assertNotNull(windows[i]);
+ windows[i].setSize(width, height);
+ glWindows[i] = GLWindow.create(windows[i]);
+ Assert.assertNotNull(glWindows[i]);
+ try {
+ glWindows[i].setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ demos[i] = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
+ glWindows[i].addGLEventListener(demos[i]);
+ }
+
+ try {
+ while ( glWindows[0].getTotalFrames() < 2) {
+ for(i=0; i<winnum; i++) {
+ glWindows[i].display();
+ }
+ }
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+
+ for(i=0; i<winnum; i++) {
+ if(null!=glWindows[i]) {
+ glWindows[i].destroy();
+ }
+ if(null!=windows[i]) {
+ windows[i].destroy();
+ }
+ if(null!=screens[i]) {
+ screens[i].destroy();
+ }
+ if(null!=displays[i]) {
+ displays[i].destroy();
+ }
+ }
+ }
+
+ @Test
+ public void test04OffscreenSnapshotWithDemoPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+
+ System.out.println("Create Window 1");
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ GLWindow windowOnScreen = null;
+ WindowListener wl=null;
+ MouseListener ml=null;
+ SurfaceUpdatedListener ul=null;
+
+ GLEventListener demo = new RedSquare();
+ Assert.assertNotNull(demo);
+
+ try {
+ WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/);
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ if(null!=windowOnScreen) {
+ windowOnScreen.destroy();
+ }
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test11OffscreenWindowPixmap() {
+ // Offscreen doesn't work on >= GL3 (ATI)
+ GLProfile glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ GLEventListener demo = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demo, window, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ while ( glWindow.getTotalFrames() < 2) {
+ try {
+ glWindow.display();
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test14OffscreenSnapshotWithDemoPixmap() {
+ // Offscreen doesn't work on >= GL3 (ATI)
+ GLProfile glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false);
+
+ System.out.println("Create Window 1");
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ GLWindow windowOnScreen = null;
+ WindowListener wl=null;
+ MouseListener ml=null;
+ SurfaceUpdatedListener ul=null;
+
+ GLEventListener demo = new RedSquare();
+ Assert.assertNotNull(demo);
+
+ try {
+ WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ if(null!=windowOnScreen) {
+ windowOnScreen.destroy();
+ }
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+ public static void main(String args[]) throws IOException {
+ String tstname = TestOffscreen01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java
new file mode 100644
index 000000000..6deacf726
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.offscreen;
+
+import com.jogamp.test.junit.util.*;
+
+import org.junit.Assert;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+public class WindowUtilNEWT {
+
+ public static GLCapabilities fixCaps(GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) {
+ GLCapabilities caps2 = (GLCapabilities) caps.clone();
+ caps2.setOnscreen(onscreen);
+ caps2.setPBuffer(!onscreen && pbuffer);
+ caps2.setDoubleBuffered(!onscreen);
+ return caps2;
+ }
+
+ public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(window);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ public static void run(GLWindow windowOffScreen, GLEventListener demo,
+ GLWindow windowOnScreen, WindowListener wl, MouseListener ml,
+ SurfaceUpdatedListener ul, int frames, boolean snapshot, boolean debug) {
+ Assert.assertNotNull(windowOffScreen);
+ Assert.assertNotNull(demo);
+
+ setDemoFields(demo, windowOffScreen, windowOffScreen, debug);
+ windowOffScreen.addGLEventListener(demo);
+
+ if ( null != windowOnScreen ) {
+ if(null!=wl) {
+ windowOnScreen.addWindowListener(wl);
+ }
+ if(null!=ml) {
+ windowOnScreen.addMouseListener(ml);
+ }
+ windowOnScreen.setVisible(true);
+ }
+
+ GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ;
+
+ if ( null == windowOnScreen ) {
+ if(snapshot) {
+ Surface2File s2f = new Surface2File();
+ windowOffScreen.addSurfaceUpdatedListener(s2f);
+ }
+ } else {
+ ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ;
+ windowOnScreen.addGLEventListener(readDemo);
+ }
+ if(null!=ul) {
+ windowOffScreen.addSurfaceUpdatedListener(ul);
+ }
+
+ if(debug) {
+ System.out.println("+++++++++++++++++++++++++++");
+ System.out.println(windowOffScreen);
+ System.out.println("+++++++++++++++++++++++++++");
+ }
+
+ while ( windowOffScreen.getTotalFrames() < frames) {
+ windowOffScreen.display();
+ }
+ windowOffScreen.removeAllSurfaceUpdatedListener();
+
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java
new file mode 100644
index 000000000..2eb66663c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.texture;
+
+import com.jogamp.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1;
+
+import com.jogamp.test.junit.util.UITestCase;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+import com.jogamp.opengl.util.Animator;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Frame;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestTexture01AWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ BufferedImage textureImage;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.get(GLProfile.GL2GL3);
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ @Before
+ public void initTest() {
+ // create base image
+ BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
+ Assert.assertNotNull(baseImage);
+ Graphics2D g = baseImage.createGraphics();
+ Assert.assertNotNull(g);
+ g.setPaint(new GradientPaint(0, 0, Color.CYAN,
+ baseImage.getWidth(), baseImage.getHeight(), Color.BLUE));
+ g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight());
+ g.dispose();
+
+ // create texture image
+ int imageType = BufferedImage.TYPE_3BYTE_BGR;
+ textureImage = new BufferedImage(baseImage.getWidth(),
+ baseImage.getHeight(),
+ imageType);
+ Assert.assertNotNull(textureImage);
+ g = textureImage.createGraphics();
+ g.setComposite(AlphaComposite.Src);
+ g.drawImage(baseImage, 0, 0, null);
+ g.dispose();
+
+ baseImage.flush();
+ baseImage=null;
+ }
+
+ @After
+ public void cleanupTest() {
+ Assert.assertNotNull(textureImage);
+ textureImage.flush();
+ textureImage=null;
+ }
+
+ @Test
+ public void test1() throws InterruptedException {
+ GLCanvas glCanvas = new GLCanvas(caps);
+
+ Frame frame = new Frame("Texture Test");
+ Assert.assertNotNull(frame);
+ frame.add(glCanvas);
+ frame.setSize(512, 512);
+
+ // create texture
+ TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false);
+ glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData));
+
+ Animator animator = new Animator(glCanvas);
+ frame.setVisible(true);
+ animator.start();
+
+ Thread.sleep(500); // 500 ms
+
+ animator.stop();
+ frame.setVisible(false);
+ frame.remove(glCanvas);
+ glCanvas=null;
+ Assert.assertNotNull(frame);
+ frame.dispose();
+ frame=null;
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestTexture01AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java
new file mode 100644
index 000000000..a0c0fc7f6
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2010 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.test.junit.jogl.util.texture.gl2;
+
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.glu.GLU;
+
+public class TextureGL2ListenerDraw1 implements GLEventListener {
+ private GLU glu = new GLU();
+ private TextureData textureData;
+ private Texture texture;
+
+ public TextureGL2ListenerDraw1(TextureData td) {
+ this.textureData = td;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ if(null!=textureData) {
+ this.texture = TextureIO.newTexture(textureData);
+ }
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glMatrixMode(GL2ES1.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluOrtho2D(0, 1, 0, 1);
+ gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ if(null!=texture) {
+ texture.disable();
+ texture.destroy(gl);
+ }
+ if(null!=textureData) {
+ textureData.destroy();
+ }
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ // need a valid GL context for this ..
+
+ /** OpenGL ..
+ texture.updateSubImage(textureData, 0,
+ 20, 20,
+ 20, 20,
+ 100, 100); */
+
+
+ // Now draw one quad with the texture
+ if(null!=texture) {
+ texture.enable();
+ texture.bind();
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
+ TextureCoords coords = texture.getImageTexCoords();
+ gl.glBegin(GL2.GL_QUADS);
+ gl.glTexCoord2f(coords.left(), coords.bottom());
+ gl.glVertex3f(0, 0, 0);
+ gl.glTexCoord2f(coords.right(), coords.bottom());
+ gl.glVertex3f(1, 0, 0);
+ gl.glTexCoord2f(coords.right(), coords.top());
+ gl.glVertex3f(1, 1, 0);
+ gl.glTexCoord2f(coords.left(), coords.top());
+ gl.glVertex3f(0, 1, 0);
+ gl.glEnd();
+ texture.disable();
+ }
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java
new file mode 100644
index 000000000..dbe51174e
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java
@@ -0,0 +1,320 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.MiscUtils;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestDisplayLifecycle01NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ caps = new GLCapabilities(glp);
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ glWindow = GLWindow.create(window);
+ } else {
+ glWindow = GLWindow.create(caps);
+ }
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ glWindow.setSize(width, height);
+ return glWindow;
+ }
+
+ private void testDisplayCreate01(Display display, Screen screen, boolean destroyWhenUnused) throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ // Setup/Verify default DestroyWhenUnused behavior
+ if(destroyWhenUnused) {
+ screen.setDestroyWhenUnused(true);
+ }
+ Assert.assertEquals(destroyWhenUnused,display.getDestroyWhenUnused());
+ Assert.assertEquals(destroyWhenUnused,screen.getDestroyWhenUnused());
+
+ // Create Window, pending lazy native creation
+ GLWindow window = createWindow(screen, caps, width, height);
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ int wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // just make the Window invisible
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // just make the Window visible again
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<2*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // recoverable destruction, ie Display/Screen untouched
+ window.destroy(false);
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+
+ // a display call shall not change a thing
+ window.display();
+ Assert.assertEquals(0, window.getTotalFrames());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // recover Window
+ window.setVisible(true);
+ wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // unrecoverable destruction, ie Display/Screen will be unreferenced
+ window.destroy(true);
+ Assert.assertEquals(null,window.getScreen());
+ display.dumpDisplayList("Post destroy(true)");
+ if(!destroyWhenUnused) {
+ // display/screen untouched when unused, default
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ // manual destruction: Screen
+ screen.destroy();
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ // manual destruction: Display
+ display.destroy();
+ } else {
+ // display/screen destroyed when unused
+ }
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ }
+
+ @Test
+ public void testDisplayCreate01_DestroyWhenUnused_False() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ Display display = NewtFactory.createDisplay(null);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ testDisplayCreate01(display, screen, false);
+ testDisplayCreate01(display, screen, false);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ @Test
+ public void testDisplayCreate01_DestroyWhenUnused_True() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ Display display = NewtFactory.createDisplay(null);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ testDisplayCreate01(display, screen, true);
+ testDisplayCreate01(display, screen, true);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestDisplayLifecycle01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java
new file mode 100644
index 000000000..9e0804a3d
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java
@@ -0,0 +1,391 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.MiscUtils;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestDisplayLifecycle02NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ caps = new GLCapabilities(glp);
+ }
+
+ static GLWindow createWindow(GLCapabilities caps, int width, int height)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow = GLWindow.create(caps);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ glWindow.setSize(width, height);
+ return glWindow;
+ }
+
+ private void testDisplayCreate01Impl() throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Window, pending lazy native creation
+ GLWindow window = createWindow(caps, width, height);
+ Screen screen = window.getScreen();
+ Display display = screen.getDisplay();
+
+ Assert.assertEquals(true,display.getDestroyWhenUnused());
+ Assert.assertEquals(true,screen.getDestroyWhenUnused());
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ int wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // just make the Window invisible
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // just make the Window visible again
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<2*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // recoverable destruction, ie Display/Screen untouched
+ window.destroy(false);
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+
+ // a display call shall not change a thing
+ window.display();
+ Assert.assertEquals(0, window.getTotalFrames());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // recover Window
+ window.setVisible(true);
+ wait=0;
+ while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // unrecoverable destruction, ie Display/Screen will be unreferenced
+ window.destroy(true);
+ Assert.assertEquals(null,window.getScreen());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ display.dumpDisplayList("Post destroy(true)");
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
+
+ @Test
+ public void testDisplayCreate01() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ testDisplayCreate01Impl();
+ testDisplayCreate01Impl();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ private void testDisplayCreate02Impl() throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Window, pending lazy native creation
+ GLWindow window1 = createWindow(caps, width, height);
+ window1.setPosition(0, 0);
+ Screen screen = window1.getScreen();
+ Display display = screen.getDisplay();
+
+ GLWindow window2 = createWindow(caps, width, height);
+ Assert.assertSame(screen, window2.getScreen());
+ Assert.assertSame(display, window2.getScreen().getDisplay());
+ window2.setPosition(screen.getWidth()-width, 0);
+
+ Assert.assertEquals(true,display.getDestroyWhenUnused());
+ Assert.assertEquals(true,screen.getDestroyWhenUnused());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+ Assert.assertEquals(false,window2.isNativeValid());
+ Assert.assertEquals(false,window2.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window1.getTotalFrames());
+ window1.setVisible(true);
+ int wait=0;
+ while(wait<10 && window1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames());
+ Assert.assertTrue(0 < window1.getTotalFrames());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(true,window1.isVisible());
+
+ Assert.assertEquals(0, window2.getTotalFrames());
+ window2.setVisible(true);
+ wait=0;
+ while(wait<10 && window2.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames());
+ Assert.assertTrue(0 < window2.getTotalFrames());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window2.isNativeValid());
+ Assert.assertEquals(true,window2.isVisible());
+
+ while(window1.getDuration()<1*durationPerTest) {
+ window1.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window1.getDuration());
+
+ // just make the Window invisible
+ window1.setVisible(false);
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+
+ // unrecoverable destruction, ie Display/Screen will be unreferenced
+ window1.destroy(true);
+ Assert.assertEquals(null,window1.getScreen());
+ Assert.assertEquals(false,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ // unrecoverable destruction, ie Display/Screen will be unreferenced
+ window2.destroy(true);
+ Assert.assertEquals(null,window2.getScreen());
+ Assert.assertEquals(false,window2.isNativeValid());
+ Assert.assertEquals(false,window2.isVisible());
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ }
+
+ @Test
+ public void testDisplayCreate02() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ testDisplayCreate02Impl();
+ testDisplayCreate02Impl();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestDisplayLifecycle02NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java b/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java
new file mode 100644
index 000000000..8776b7be8
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+import javax.swing.WindowConstants;
+
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.*;
+
+/**
+ * This simple program will throw a {@link RuntimeException} when the application is closed.
+ */
+public class TestEventSourceNotAWTBug extends UITestCase {
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @Test
+ public void testEventSourceNotNewtBug() throws InterruptedException {
+ JFrame jf = new JFrame();
+
+ jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ final GLWindow glWindow = GLWindow.create(caps);
+ final NewtCanvasAWT canvas = new NewtCanvasAWT(glWindow);
+ jf.getContentPane().add(canvas);
+
+ // The following line isn't event necessary to see the problem.
+ glWindow.addGLEventListener(new Gears());
+
+ final JFrame f_jf = jf;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ f_jf.setSize(800, 600);
+ f_jf.setVisible(true);
+ }
+ });
+
+ Thread.sleep(500);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ f_jf.dispose();
+ }
+ });
+ glWindow.destroy(true);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestEventSourceNotAWTBug.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java
new file mode 100644
index 000000000..1002fc9f8
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -0,0 +1,212 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Robot;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.swing.JFrame;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+
+import com.jogamp.test.junit.util.*;
+
+public class TestFocus01SwingAWTRobot extends UITestCase {
+ static int width, height;
+
+ static long durationPerTest = 800;
+
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ @Test
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ testFocus01ProgrFocusImpl(null);
+ }
+
+ @Test
+ public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ Robot robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ testFocus01ProgrFocusImpl(robot);
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException,
+ InvocationTargetException, InterruptedException {
+ ArrayList eventCountAdapters = new ArrayList();
+
+ // Create a window.
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testNewtChildFocus");
+ GLEventListener demo1 = new RedSquare();
+ TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1FA);
+ glWindow1.addWindowListener(glWindow1FA);
+
+ // Monitor NEWT focus and keyboard events.
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1KA);
+ glWindow1.addKeyListener(glWindow1KA);
+
+ // Wrap the window in a canvas.
+ final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ // Monitor AWT focus and keyboard events.
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
+
+ // Add the canvas to a frame, and make it all visible.
+ JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
+ + glWindow1.getTitle());
+ frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
+ Button button = new Button("Click me ..");
+ AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
+ button.addFocusListener(buttonFA);
+ eventCountAdapters.add(buttonFA);
+ AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
+ button.addKeyListener(buttonKA);
+ eventCountAdapters.add(buttonKA);
+ frame1.getContentPane().add(button, BorderLayout.NORTH);
+ frame1.setSize(width, height);
+ frame1.setVisible(true);
+ Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1));
+
+ int wait=0;
+ while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.out.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ // Continuous animation ..
+ Animator animator = new Animator(glWindow1);
+ animator.start();
+
+ // Button Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button, buttonFA, null));
+ Assert.assertEquals(1, buttonFA.getCount());
+ Assert.assertEquals(0, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ System.err.println("FOCUS AWT Button sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, button, buttonKA));
+
+ // Request the AWT focus, which should automatically provide the NEWT window with focus.
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(-1, buttonFA.getCount()); // lost focus
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+
+ // Remove listeners to avoid logging during dispose/destroy.
+ glWindow1.removeKeyListener(glWindow1KA);
+ glWindow1.removeWindowListener(glWindow1FA);
+ newtCanvasAWT.removeKeyListener(newtCanvasAWTKA);
+ newtCanvasAWT.removeFocusListener(newtCanvasAWTFA);
+
+ // Shutdown the test.
+ animator.stop();
+ frame1.dispose();
+ glWindow1.destroy(true);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestFocus01SwingAWTRobot.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java
new file mode 100644
index 000000000..3891f1565
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java
@@ -0,0 +1,301 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.AWTException;
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Robot;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestFocus02SwingAWTRobot extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() throws AWTException {
+ width = 640;
+ height = 480;
+
+ JFrame f = new JFrame();
+ f.setSize(100,100);
+ f.setVisible(true);
+ f.dispose();
+ f=null;
+
+ GLProfile.initSingleton(false);
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ ArrayList eventCountAdapters = new ArrayList();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new Gears();
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ glWindow1.addWindowListener(glWindow1FA);
+ eventCountAdapters.add(glWindow1FA);
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ glWindow1.addKeyListener(glWindow1KA);
+ eventCountAdapters.add(glWindow1KA);
+ NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1");
+ glWindow1.addMouseListener(glWindow1MA);
+ eventCountAdapters.add(glWindow1MA);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
+ eventCountAdapters.add(newtCanvasAWTMA);
+
+ Button buttonNorthInner = new Button("north");
+ AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
+ buttonNorthInner.addFocusListener(buttonNorthInnerFA);
+ eventCountAdapters.add(buttonNorthInnerFA);
+ AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
+ buttonNorthInner.addKeyListener(buttonNorthInnerKA);
+ eventCountAdapters.add(buttonNorthInnerKA);
+ AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner");
+ buttonNorthInner.addMouseListener(buttonNorthInnerMA);
+ eventCountAdapters.add(buttonNorthInnerMA);
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(buttonNorthInner, BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ Button buttonNorthOuter = new Button("north");
+ AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
+ eventCountAdapters.add(buttonNorthOuterFA);
+ AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
+ eventCountAdapters.add(buttonNorthOuterKA);
+ AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
+ eventCountAdapters.add(buttonNorthOuterMA);
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ AWTFocusAdapter jFrame1FA = new AWTFocusAdapter("JFrame1");
+ jFrame1.addFocusListener(jFrame1FA);
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setSize(width, height);
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+ Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1));
+
+ int wait=0;
+ while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ // Continuous animation ..
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ // Button Outer Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button Outer request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null));
+ Assert.assertEquals(1, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS AWT Button Outer sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthOuter, buttonNorthOuterKA));
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ buttonNorthOuter, buttonNorthOuterMA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ buttonNorthOuter, buttonNorthOuterMA));
+
+ // NEWT Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
+
+ // Button Inner Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA));
+ Assert.assertEquals(1, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS AWT Button sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthInner, buttonNorthInnerKA));
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ buttonNorthInner, buttonNorthInnerMA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ buttonNorthInner, buttonNorthInnerMA));
+
+ // NEWT Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus
+ Assert.assertEquals(0, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
+
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.setVisible(false);
+ _jPanel1.remove(_container1);
+ _jFrame1.dispose();
+ } });
+
+ glWindow1.destroy(true);
+ }
+
+ @Test
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ testFocus01ProgrFocusImpl(null);
+ }
+
+ @Test
+ public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ Robot robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ testFocus01ProgrFocusImpl(robot);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest "+durationPerTest);
+ System.err.println("waitReparent "+waitReparent);
+ String tstname = TestFocus02SwingAWTRobot.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java
new file mode 100644
index 000000000..112bb943c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java
@@ -0,0 +1,411 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.MiscUtils;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestGLWindows01NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ // GLProfile.initSingleton(false);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps,
+ int width, int height, boolean onscreen, boolean undecorated,
+ boolean addGLEventListenerAfterVisible)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ boolean destroyWhenUnused = screen.getDestroyWhenUnused();
+ Assert.assertEquals(destroyWhenUnused, screen.getDisplay().getDestroyWhenUnused());
+ glWindow = GLWindow.create(screen, caps);
+ Assert.assertNotNull(glWindow);
+ Assert.assertEquals(destroyWhenUnused, glWindow.getScreen().getDestroyWhenUnused());
+ } else {
+ glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ Assert.assertTrue(glWindow.getScreen().getDestroyWhenUnused());
+ }
+
+ glWindow.setUndecorated(onscreen && undecorated);
+ Assert.assertEquals(false,glWindow.isVisible());
+ Assert.assertEquals(false,glWindow.isNativeValid());
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ if(!addGLEventListenerAfterVisible) {
+ glWindow.addGLEventListener(demo);
+ }
+ glWindow.addWindowListener(new TraceWindowAdapter());
+
+ glWindow.setSize(width, height);
+
+ Assert.assertEquals(0, glWindow.getTotalFrames());
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+ int wait=0;
+ while(wait<10 && glWindow.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.out.println("Frames for initial setVisible(true): "+glWindow.getTotalFrames());
+ Assert.assertTrue(0 < glWindow.getTotalFrames());
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ caps = glWindow.getChosenGLCapabilities();
+ Assert.assertNotNull(caps);
+ Assert.assertTrue(caps.getGreenBits()>5);
+ Assert.assertTrue(caps.getBlueBits()>5);
+ Assert.assertTrue(caps.getRedBits()>5);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
+
+ if(addGLEventListenerAfterVisible) {
+ glWindow.addGLEventListener(demo);
+ glWindow.display();
+ }
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow, Screen screen, Display display, boolean unrecoverable) {
+ if(null!=glWindow) {
+ glWindow.destroy(unrecoverable);
+ Assert.assertEquals(false,glWindow.isNativeValid());
+ }
+ if(null!=screen) {
+ screen.destroy();
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
+ if(null!=display) {
+ display.destroy();
+ Assert.assertEquals(false,display.isNativeValid());
+ }
+ }
+
+ @Test
+ public void testWindowNativeRecreate01aSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ window.destroy(false);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.display();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ destroyWindow(window, null, null, true);
+ }
+
+ @Test
+ public void testWindowNativeRecreate01bSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ true /*addGLEventListenerAfterVisible*/);
+
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ window.destroy(false);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.display();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ destroyWindow(window, null, null, true);
+ }
+
+ @Test
+ public void testWindowDecor01aSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ System.out.println("Created: "+window);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window, null, null, true);
+ }
+
+ @Test
+ public void testWindowDecor01bSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ true /*addGLEventListenerAfterVisible*/);
+ System.out.println("Created: "+window);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window, null, null, true);
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window, null, null, false);
+ destroyWindow(window, null, null, true);
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ display.setDestroyWhenUnused(true);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window1 = createWindow(screen, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window1);
+
+ GLWindow window2 = createWindow(screen, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window2);
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration1: "+window1.getDuration());
+ System.out.println("duration2: "+window2.getDuration());
+
+ destroyWindow(window1, null, null, true);
+ destroyWindow(window2, null, null, true);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display1 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display1);
+ display1.setDestroyWhenUnused(true);
+ Display display2 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display2);
+ display2.setDestroyWhenUnused(true);
+ Assert.assertNotSame(display1, display2);
+
+ Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
+ Assert.assertNotNull(screen1);
+ GLWindow window1 = createWindow(screen1, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window1);
+
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ Assert.assertNotNull(screen2);
+ GLWindow window2 = createWindow(screen2, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window2);
+
+ Assert.assertEquals(2,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+
+ Assert.assertEquals(1,display2.getReferenceCount());
+ Assert.assertEquals(true,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(true,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen2.getReferenceCount());
+ Assert.assertEquals(true,screen2.isNativeValid());
+
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration1: "+window1.getDuration());
+ System.out.println("duration2: "+window2.getDuration());
+
+ // It is observed that some X11 drivers, eg ATI, fglrx 8.78.6,
+ // are quite sensitive to multiple Display connections (NEWT Display -> X11 Display).
+ // In such cases, closing displays shall happen in the same order as
+ // opening them, otherwise some driver related bug appears.
+ // You may test this, ie just reverse the destroy order below.
+ // See also native test: jogl/test/native/displayMultiple02.c
+ destroyWindow(window1, null, null, true);
+ destroyWindow(window2, null, null, true);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(false,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestGLWindows01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java
new file mode 100644
index 000000000..a6809e0bd
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java
@@ -0,0 +1,258 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.util.MiscUtils;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestGLWindows02NEWTAnimated extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ glWindow = GLWindow.create(window);
+ } else {
+ glWindow = GLWindow.create(caps);
+ }
+ Assert.assertNotNull(glWindow);
+ glWindow.setUndecorated(onscreen && undecorated);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ Assert.assertEquals(false,glWindow.isNativeValid());
+
+ glWindow.setSize(width, height);
+ Assert.assertEquals(false,glWindow.isVisible());
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+ // Assert.assertEquals(width,glWindow.getWidth());
+ // Assert.assertEquals(height,glWindow.getHeight());
+ // System.out.println("Created: "+glWindow);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ caps = glWindow.getChosenGLCapabilities();
+ Assert.assertNotNull(caps);
+ Assert.assertTrue(caps.getGreenBits()>5);
+ Assert.assertTrue(caps.getBlueBits()>5);
+ Assert.assertTrue(caps.getRedBits()>5);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow, boolean deep) {
+ if(null!=glWindow) {
+ glWindow.destroy(deep);
+ }
+ }
+
+ @Test
+ public void testWindowDecor01Simple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window, true);
+ Assert.assertEquals(false, animator.isAnimating());
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window, false);
+ destroyWindow(window, true);
+ Assert.assertEquals(false, animator.isAnimating());
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window1);
+ window1.setPosition(0, 0);
+
+ GLWindow window2 = createWindow(screen, caps, width-10, height-10, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window2);
+ window2.setPosition(screen.getWidth()-width, 0);
+
+ Animator animator1 = new Animator(window1);
+ animator1.start();
+ Animator animator2 = new Animator(window2);
+ animator2.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+
+ destroyWindow(window1, true);
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ destroyWindow(window2, true);
+ Assert.assertEquals(false, animator2.isAnimating());
+ }
+ @Test
+ public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display1 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display1);
+ Display display2 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display2);
+ Assert.assertNotSame(display1, display2);
+
+ Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
+ Assert.assertNotNull(screen1);
+ GLWindow window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window1);
+ window1.setPosition(0, 0);
+
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ Assert.assertNotNull(screen2);
+ GLWindow window2 = createWindow(screen2, caps, width-10, height-10, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window2);
+ window2.setPosition(screen2.getWidth()-width, 0);
+
+ Animator animator1 = new Animator(window1);
+ animator1.start();
+ Animator animator2 = new Animator(window2);
+ animator2.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+
+ destroyWindow(window1, true);
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ destroyWindow(window2, true);
+ Assert.assertEquals(false, animator2.isAnimating());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestGLWindows02NEWTAnimated.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java b/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java
new file mode 100644
index 000000000..39eb47ca9
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java
@@ -0,0 +1,167 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestListenerCom01AWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static boolean verbose = false;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testListenerStringPassingAndOrder() throws InterruptedException {
+ // setup NEWT GLWindow ..
+ GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("NEWT - CHILD");
+
+ System.out.println("durationPerTest "+durationPerTest);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ WindowEventCom1 wl1 = new WindowEventCom1();
+ WindowEventCom2 wl2 = new WindowEventCom2();
+ WindowEventCom3 wl3 = new WindowEventCom3();
+
+ // TraceWindowAdapter wlT = new TraceWindowAdapter();
+ // glWindow.addWindowListener(0, wlT);
+ // Assert.assertEquals(wlT, glWindow.getWindowListener(0));
+
+ glWindow.addWindowListener(0, wl3);
+ glWindow.addWindowListener(0, wl2);
+ glWindow.addWindowListener(0, wl1);
+
+ Assert.assertEquals(wl1, glWindow.getWindowListener(0));
+ Assert.assertEquals(wl2, glWindow.getWindowListener(1));
+ Assert.assertEquals(wl3, glWindow.getWindowListener(2));
+
+ // attach NEWT GLWindow to AWT Canvas
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ Frame frame = new Frame("AWT Parent Frame");
+ frame.add(newtCanvasAWT);
+ frame.setSize(width, height);
+ frame.setVisible(true);
+
+ Animator animator1 = new Animator(glWindow);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ width+=10; height+=10;
+ frame.setSize(width, height);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ verbose = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestListenerCom01AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java
new file mode 100644
index 000000000..06911e82b
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.MonitorMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.UITestCase;
+import java.util.Iterator;
+import java.util.List;
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionReadOnly;
+import javax.media.nativewindow.util.SurfaceSize;
+
+public class TestScreenMode00NEWT extends UITestCase {
+ static int width, height;
+
+ static int waitTimeShort = 4; //1 sec
+ static int waitTimeLong = 6; //6 sec
+
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testScreenModeInfo00() throws InterruptedException {
+ DimensionReadOnly res = new Dimension(640, 480);
+ SurfaceSize surfsz = new SurfaceSize(res, 32);
+ DimensionReadOnly mm = new Dimension(500, 400);
+ MonitorMode mon = new MonitorMode(surfsz, mm, 60);
+ ScreenMode sm_out = new ScreenMode(mon, 90);
+ System.err.println("00 out: "+sm_out);
+
+ int[] props = ScreenModeUtil.streamOut(sm_out);
+ ScreenMode sm_in = ScreenModeUtil.streamIn(props, 0);
+ System.err.println("00 in : "+sm_in);
+
+ Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize().getResolution(),
+ sm_out.getMonitorMode().getSurfaceSize().getResolution());
+
+ Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize(),
+ sm_out.getMonitorMode().getSurfaceSize());
+
+ Assert.assertEquals(sm_in.getMonitorMode().getScreenSizeMM(),
+ sm_out.getMonitorMode().getScreenSizeMM());
+
+ Assert.assertEquals(sm_in.getMonitorMode(), sm_out.getMonitorMode());
+
+ Assert.assertEquals(sm_in, sm_out);
+
+ Assert.assertEquals(sm_out.hashCode(), sm_in.hashCode());
+ }
+
+ @Test
+ public void testScreenModeInfo01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Window window = NewtFactory.createWindow(caps);
+ window.setSize(width, height);
+ window.setVisible(true);
+
+ Screen screen = window.getScreen();
+
+ List screenModes = screen.getScreenModes();
+ if(null != screenModes) {
+ Assert.assertTrue(screenModes.size()>0);
+ int i=0;
+ for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) {
+ System.err.println(i+": "+iter.next());
+ }
+ ScreenMode sm_o = screen.getOriginalScreenMode();
+ Assert.assertNotNull(sm_o);
+ ScreenMode sm_c = screen.getOriginalScreenMode();
+ Assert.assertNotNull(sm_c);
+ System.err.println("orig: "+sm_o);
+ System.err.println("curr: "+sm_c);
+ }
+
+ window.destroy(true);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,screen.getDisplay().isNativeValid());
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode00NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
new file mode 100644
index 000000000..fe17857ef
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
@@ -0,0 +1,293 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+public class TestScreenMode01NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 1000; // 1 sec
+ static int waitTimeLong = 5000; // 5 sec
+
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ boolean destroyWhenUnused = screen.getDestroyWhenUnused();
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new Gears());
+ Assert.assertNotNull(window);
+ Assert.assertEquals(destroyWhenUnused, window.getScreen().getDestroyWhenUnused());
+ window.setVisible(true);
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testFullscreenChange01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+
+ Thread.sleep(waitTimeShort);
+
+ window.setFullscreen(false);
+ Assert.assertEquals(false, window.isFullscreen());
+
+ Thread.sleep(waitTimeShort);
+
+ animator.stop();
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenModeChange01() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ destroyWindow(display, screen, window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ Assert.assertNotNull(smCurrent);
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ Assert.assertNotNull(smOrig);
+ Assert.assertEquals(smCurrent, smOrig);
+ System.err.println("[0] current/orig: "+smCurrent);
+
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 0);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+
+ ScreenMode sm = (ScreenMode) screenModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ screen.setCurrentScreenMode(sm);
+ Assert.assertEquals(sm, screen.getCurrentScreenMode());
+ Assert.assertNotSame(smOrig, screen.getCurrentScreenMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ destroyWindow(null, screen, window);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(true,display.isNativeValid());
+
+ screen = NewtFactory.createScreen(display, 0); // screen 0
+ screen.addReference(); // trigger native creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ destroyWindow(display, screen, null);
+
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Thread.sleep(waitTimeShort);
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Pre() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(true) ;
+ Thread.sleep(waitTimeShort);
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Post() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(false) ;
+ Thread.sleep(waitTimeShort);
+ }
+
+ protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ destroyWindow(display, screen, window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+
+ ScreenMode screenMode = (ScreenMode) screenModes.get(0);
+ Assert.assertNotNull(screenMode);
+
+ if(preFS) {
+ System.err.println("[0] set FS pre 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS pre X: "+window.isFullscreen());
+ }
+
+ System.err.println("[0] set current: "+screenMode);
+ screen.setCurrentScreenMode(screenMode);
+
+ if(!preFS) {
+ System.err.println("[0] set FS post 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS post X: "+window.isFullscreen());
+ }
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ animator.stop();
+ destroyWindow(null, screen, window);
+
+ screen = NewtFactory.createScreen(display, 0); // screen 0
+ screen.addReference(); // trigger native creation
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ destroyWindow(display, screen, null);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
new file mode 100644
index 000000000..98c8fd58c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
@@ -0,0 +1,193 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+public class TestScreenMode02NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 1000; // 1 sec
+ static int waitTimeLong = 5000; // 5 sec
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ boolean destroyWhenUnused = screen.getDestroyWhenUnused();
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new Gears());
+ Assert.assertNotNull(window);
+ Assert.assertEquals(destroyWhenUnused, window.getScreen().getDestroyWhenUnused());
+ window.setVisible(true);
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenRotationChange01() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ destroyWindow(display, screen, window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ Assert.assertNotNull(smCurrent);
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ Assert.assertNotNull(smOrig);
+ Assert.assertEquals(smCurrent, smOrig);
+ System.err.println("[0] current/orig: "+smCurrent);
+
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 90);
+ if(null==screenModes) {
+ // no rotation support ..
+ destroyWindow(display, screen, window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+
+ ScreenMode sm = (ScreenMode) screenModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ screen.setCurrentScreenMode(sm);
+ Assert.assertEquals(sm, screen.getCurrentScreenMode());
+ Assert.assertNotSame(smOrig, screen.getCurrentScreenMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ destroyWindow(null, screen, window);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(true,display.isNativeValid());
+
+ screen = NewtFactory.createScreen(display, 0); // screen 0
+ screen.addReference(); // trigger native creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ destroyWindow(display, screen, null);
+
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Thread.sleep(waitTimeShort);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode02NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java
new file mode 100644
index 000000000..88edd89ba
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java
@@ -0,0 +1,189 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.UITestCase;
+
+public class TestWindows01NEWT extends UITestCase {
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertEquals(true,window.isNativeValid());
+ // Assert.assertEquals(width,window.getWidth());
+ // Assert.assertEquals(height,window.getHeight());
+ // System.out.println("Created: "+window);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(caps);
+ Assert.assertTrue(caps.getGreenBits()>5);
+ Assert.assertTrue(caps.getBlueBits()>5);
+ Assert.assertTrue(caps.getRedBits()>5);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
+
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testWindowNativeRecreate01Simple() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ window.destroy();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ Thread.sleep(100); // 100 ms
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor01Simple() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(null, null, window);
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor03TwoWin() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Window window2 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(null, null, window2);
+ destroyWindow(display, screen, window1);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestWindows01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java b/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java
new file mode 100644
index 000000000..74b2ed176
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom1 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ e.setAttachment(new String("WindowEventCom1.windowResized: "+e));
+ }
+ public void windowMoved(WindowEvent e) {
+ e.setAttachment(new String("WindowEventCom1.windowMoved: "+e));
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/WindowEventCom2.java b/src/junit/com/jogamp/test/junit/newt/WindowEventCom2.java
new file mode 100644
index 000000000..551c84acb
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/WindowEventCom2.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom2 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ if(null==str) {
+ e.setAttachment(new String("WindowEventCom2.windowResized: "+e));
+ }
+ }
+ public void windowMoved(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ if(null==str) {
+ e.setAttachment(new String("WindowEventCom2.windowMoved: "+e));
+ }
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/WindowEventCom3.java b/src/junit/com/jogamp/test/junit/newt/WindowEventCom3.java
new file mode 100644
index 000000000..0c097fc4f
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/WindowEventCom3.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2010 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.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom3 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ System.out.println("WindowEventCom3.windowResized: "+str);
+ }
+ public void windowMoved(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ System.out.println("WindowEventCom3.windowMoved: "+str);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java b/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java
new file mode 100644
index 000000000..2459c8687
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+public class GLRunnableDummy implements GLRunnable {
+ float r=0.0f;
+ float g=0.0f;
+ float b=0.0f;
+ float d=0.001f;
+
+ public void run(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.glClearColor(r, g, b, 1f);
+ r+=d;
+ if(r>1f) {
+ r=1f;
+ d*=-1f;
+ } else if(r<0f) {
+ r=0f;
+ d*=-1f;
+ }
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java b/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java
new file mode 100644
index 000000000..4948ce9f4
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import com.jogamp.newt.event.*;
+
+class KeyAction extends KeyAdapter {
+ NEWTEventFiFo eventFifo;
+
+ public KeyAction(NEWTEventFiFo eventFifo) {
+ this.eventFifo = eventFifo;
+ }
+
+ public void keyTyped(KeyEvent e) {
+ eventFifo.put(e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java
new file mode 100644
index 000000000..91d8856f0
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java
@@ -0,0 +1,724 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01NEWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static int frameWait = 2000;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display = null;
+ Screen screen = null;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ screen = glWindow1.getScreen();
+ display = screen.getDisplay();
+ Assert.assertEquals(true,display.getDestroyWhenUnused());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps);
+ Assert.assertNotNull(glWindow2);
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen,glWindow2.getScreen());
+ Assert.assertSame(display,glWindow2.getScreen().getDisplay());
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+
+ Assert.assertEquals(true,display.getDestroyWhenUnused());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning()); // GLWindow -> invoke ..
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // visible test
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ int wait;
+ for(wait=0; wait<frameWait/100 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.setVisible(false);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ for(wait=0; wait<frameWait/100 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A2: "+glWindow1.getTotalFrames()+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ animator1.pause();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(true, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ animator2.pause();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(true, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ animator1.resume();
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ animator2.resume();
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+ for(wait=0; wait<frameWait/100 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A4: "+glWindow1.getTotalFrames()+", B4: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow2.destroy(); // can be recreated, refs are hold
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.destroy(); // can be recreated, refs are hold
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // recreation ..
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ for(wait=0; wait<frameWait/100 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // cannot be recreated, will drop Display/Screen refs
+ glWindow1.destroy(true);
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // test double destroy ..
+ glWindow2.destroy(true);
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ @Test
+ public void testWindowParenting02ReparentTop2WinReparentRecreate() throws InterruptedException {
+ testWindowParenting02ReparentTop2WinImpl(true);
+ }
+
+ @Test
+ public void testWindowParenting02ReparentTop2WinReparentNative() throws InterruptedException {
+ testWindowParenting02ReparentTop2WinImpl(false);
+ }
+
+ /**
+ * @param reparentRecreate true, if the followup reparent should utilize destroy/create, instead of native reparenting
+ */
+ protected void testWindowParenting02ReparentTop2WinImpl(boolean reparentRecreate) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display1 = null;
+ Screen screen1 = null;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testWindowParenting02ReparentTop2Win");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ screen1 = glWindow1.getScreen();
+ display1 = screen1.getDisplay();
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ GLWindow glWindow2 = GLWindow.create(glCaps);
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+ Assert.assertSame(screen1, glWindow2.getScreen());
+ Assert.assertSame(display1, glWindow2.getScreen().getDisplay());
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ glWindow1.setVisible(true);
+ int wait=0;
+ while(wait<frameWait/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) A1: "+glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow2.setVisible(true);
+ wait=0;
+ while(wait<frameWait/100 && glWindow2.getTotalFrames()<1) { Thread.sleep(100); wait++; }
+ System.err.println("Frames for setVisible(true) B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ int state = 0;
+ int reparentAction;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ // glWindow2 -- child --> glWindow1: compatible
+ Assert.assertEquals(true, glWindow2.isVisible());
+ System.err.println("Frames(1) "+glWindow2.getTotalFrames());
+ reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate);
+ System.err.println("Frames(2) "+glWindow2.getTotalFrames());
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ for(wait=0; wait<frameWait/100 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); }
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ break;
+
+ case 1:
+ // glWindow2 --> top
+ Assert.assertEquals(true, glWindow2.isVisible());
+
+ reparentAction = glWindow2.reparentWindow(null, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ for(wait=0; wait<frameWait/100 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); }
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertNull(glWindow2.getParent());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ break;
+ }
+ state++;
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ // pre-destroy check (both valid and running)
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // destroy glWindow2
+ glWindow2.destroy(true);
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // destroy glWindow1
+ glWindow1.destroy(true);
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ @Test
+ public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException {
+ testWindowParenting03ReparentWin2TopImpl(true);
+ }
+
+ @Test
+ public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException {
+ testWindowParenting03ReparentWin2TopImpl(false);
+ }
+
+ protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display1 = null;
+ Screen screen1 = null;
+ Display display2 = null;
+ Screen screen2 = null;
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ screen1 = glWindow1.getScreen();
+ display1 = screen1.getDisplay();
+ glWindow1.setTitle("testWindowParenting03ReparentWin2Top");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps);
+ screen2 = glWindow2.getScreen();
+ display2 = screen2.getDisplay();
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+
+ Assert.assertEquals(true,display2.getDestroyWhenUnused());
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(true,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ int wait;
+ for(wait=0; wait<frameWait/100 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ int state = 0;
+ int reparentAction;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ Assert.assertEquals(true, glWindow2.isVisible());
+ reparentAction = glWindow2.reparentWindow(null, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ for(wait=0; wait<frameWait/100 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); }
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertNull(glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ break;
+ case 1:
+ Assert.assertEquals(true, glWindow2.isVisible());
+ reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ for(wait=0; wait<frameWait/100 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); }
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ break;
+ }
+ state++;
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.destroy(true); // should destroy both windows, actually, since glWindow2 is a child
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(true,display1.getDestroyWhenUnused());
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(true,display2.getDestroyWhenUnused());
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(false,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow2.destroy(true);
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestParenting01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java
new file mode 100644
index 000000000..931cf2d5f
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java
@@ -0,0 +1,441 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01aAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() throws InterruptedException {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ // Thread.sleep(10000);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ frame1.add(container1, BorderLayout.CENTER);
+ frame1.setSize(width, height);
+
+ // visible test
+ frame1.setVisible(true);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame1.setVisible(false);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.setVisible(true);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.remove(newtCanvasAWT);
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.dispose();
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.destroy(true);
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting02CreateVisibleDestroy2Defered() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ frame.setSize(width, height);
+
+ // visible test
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.destroy(true);
+ }
+
+ @Test
+ public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ frame.setSize(width, height);
+
+ // visible test
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertEquals(true, animator1.isAnimating()); // !!!
+
+ frame.dispose();
+ glWindow1.destroy(true);
+ }
+
+ @Test
+ public void testWindowParenting03ReparentNewtWin2Top() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ frame.setSize(width, height);
+ frame.setLocation(640, 480);
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ glWindow1.reparentWindow(null);
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ break;
+ case 1:
+ glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.destroy(true);
+ }
+
+ @Test
+ public void testWindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ 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.setSize(width, height);
+ frame.setLocation(640, 480);
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ glWindow1.reparentWindow(null);
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ break;
+ case 1:
+ glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.destroy(true);
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01aAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java
new file mode 100644
index 000000000..9eecf31a1
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java
@@ -0,0 +1,205 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01bAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException {
+ testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(25);
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException {
+ testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(0);
+ }
+
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ GLAnimatorControl animator1;
+ if(fps>0) {
+ animator1 = new FPSAnimator(glWindow1, fps);
+ } else {
+ animator1 = new Animator(glWindow1);
+ }
+ animator1.start();
+
+ int state;
+ for(state=0; state<3; state++) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ }
+
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01bAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java
new file mode 100644
index 000000000..2dcc7af9b
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java
@@ -0,0 +1,243 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01cAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+ int i;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ frame1.add(container1, BorderLayout.CENTER);
+ frame1.setSize(width, height);
+
+ // visible test
+ frame1.setVisible(true);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ for(i=0; i*100<durationPerTest; i++) {
+ Thread.sleep(100);
+ }
+
+ frame1.setVisible(false);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.setVisible(true);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.remove(newtCanvasAWT);
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.dispose();
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.destroy(true);
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ int state;
+ for(state=0; state<3; state++) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ }
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01cAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java
new file mode 100644
index 000000000..3fc39a3f1
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java
@@ -0,0 +1,376 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Dimension;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01cSwingAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ final GLWindow _glWindow1 = glWindow1;
+ final GLRunnable _glRunnable = new GLRunnableDummy();
+ Thread disturbanceThread = new Thread(new Runnable() {
+ public void run() {
+ System.out.println("$");
+ while(true)
+ {
+ try {
+ _glWindow1.invoke(true, _glRunnable);
+ Thread.yield();
+ } catch (Throwable t) {}
+ }
+ }
+ });
+ disturbanceThread.start();
+
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(new Button("north"), BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setSize(width, height);
+ System.out.println("Demos: 1 - Visible");
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+
+ // visible test
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ System.out.println("Demos: 2 - StopAnimator");
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 3 - !Visible");
+ _jFrame1.setVisible(false);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 4 - Visible");
+ _jFrame1.setVisible(true);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 5 - X Container");
+ _jPanel1.remove(_container1);
+ } });
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.dispose();
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.destroy(true);
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ final GLWindow _glWindow1 = glWindow1;
+ final GLRunnable _glRunnable = new GLRunnableDummy();
+ Thread disturbanceThread = new Thread(new Runnable() {
+ public void run() {
+ System.out.println("$");
+ while(true)
+ {
+ try {
+ _glWindow1.invoke(true, _glRunnable);
+ Thread.yield();
+ } catch (Throwable t) {}
+ }
+ }
+ });
+ disturbanceThread.start();
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(new Button("north"), BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setLocation(0, 0);
+ jFrame1.setSize(width, height);
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+
+ JPanel jPanel2 = new JPanel();
+ jPanel2.setLayout(new BorderLayout());
+ jPanel2.add(new Button("north"), BorderLayout.NORTH);
+ jPanel2.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel2.add(new Button("east"), BorderLayout.EAST);
+ jPanel2.add(new Button("west"), BorderLayout.WEST);
+
+ JFrame jFrame2 = new JFrame("Swing Parent JFrame");
+ // jFrame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame2.setContentPane(jPanel2);
+ jFrame2.setLocation(640, 480);
+ jFrame2.setSize(width, height);
+ jFrame2.setVisible(true); // from here on, we need to run modifications on EDT
+
+ final NewtCanvasAWT _newtCanvasAWT = newtCanvasAWT;
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+ final JFrame _jFrame2 = jFrame2;
+ final JPanel _jPanel2 = jPanel2;
+
+ // visible test
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _container1.remove(_newtCanvasAWT);
+ _jPanel2.add(_newtCanvasAWT, BorderLayout.CENTER);
+ } });
+ break;
+ case 1:
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jPanel2.remove(_newtCanvasAWT);
+ _container1.add(_newtCanvasAWT, BorderLayout.CENTER);
+ } });
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.setVisible(false);
+ _jFrame2.setVisible(false);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.dispose();
+ _jFrame2.dispose();
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.destroy(true);
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest "+durationPerTest);
+ System.out.println("waitReparent "+waitReparent);
+ String tstname = TestParenting01cSwingAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java
new file mode 100644
index 000000000..3311bc691
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java
@@ -0,0 +1,267 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting02AWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static long waitReparent = 300;
+ static boolean verbose = false;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException {
+ runNewtChildOnAWTParent(true, false);
+ }
+
+ @Test
+ public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException {
+ runNewtChildOnAWTParent(true, true);
+ }
+
+ @Test
+ public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException {
+ runNewtChildOnAWTParent(false, false);
+ }
+
+ @Test
+ public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException {
+ runNewtChildOnAWTParent(false, true);
+ }
+
+ public void runNewtChildOnAWTParent(boolean useLayout, boolean deferredPeer) throws InterruptedException {
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ // setup NEWT GLWindow ..
+ GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("NEWT - CHILD");
+ glWindow.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ // attach NEWT GLWindow to AWT Canvas
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow.isVisible());
+ Assert.assertEquals(false, glWindow.isNativeValid());
+ Assert.assertNull(glWindow.getParent());
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ if(useLayout) {
+ 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);
+ if(!deferredPeer) {
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ }
+ } else {
+ if(!deferredPeer) {
+ frame.add(newtCanvasAWT);
+ }
+ }
+
+ frame.setSize(width, height);
+
+ frame.setVisible(true);
+ // X11: true, Windows: false - Assert.assertEquals(true, glWindow.isVisible());
+
+ if(deferredPeer) {
+ if(useLayout) {
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ } else {
+ frame.add(newtCanvasAWT);
+ }
+ }
+
+ // Since it is not defined when AWT's addNotify call happen
+ // we just have to wait for it in this junit test
+ // because we have assertions on the state.
+ // Regular application shall not need to do that.
+ do {
+ Thread.yield();
+ // 1st display .. creation
+ glWindow.display();
+ } while(!glWindow.isNativeValid()) ;
+
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNotNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ 1st ADDED");
+ }
+ Thread.sleep(waitReparent);
+
+ if(useLayout) {
+ // test some fancy re-layout ..
+ frame.remove(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow.isVisible());
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ REMOVED!");
+ }
+ Thread.sleep(waitReparent);
+
+ // should recreate properly ..
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ glWindow.display();
+ Assert.assertEquals(true, glWindow.isVisible());
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNotNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ 2nd ADDED");
+ }
+ Thread.sleep(waitReparent);
+ }
+
+ long duration = durationPerTest;
+ long step = 20;
+ NEWTEvent event;
+ boolean shouldQuit = false;
+
+ while (duration>0 && !shouldQuit) {
+ glWindow.display();
+ Thread.sleep(step);
+ duration -= step;
+
+ while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
+ Window source = (Window) event.getSource();
+ if(event instanceof KeyEvent) {
+ KeyEvent keyEvent = (KeyEvent) event;
+ switch(keyEvent.getKeyChar()) {
+ case 'q':
+ shouldQuit = true;
+ break;
+ case 'f':
+ source.setFullscreen(!source.isFullscreen());
+ break;
+ }
+ }
+ }
+ }
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ END");
+ }
+ Thread.sleep(waitReparent);
+
+ glWindow.destroy(true);
+ if(useLayout) {
+ frame.remove(newtCanvasAWT);
+ }
+ frame.dispose();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ verbose = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting02AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java
new file mode 100644
index 000000000..3d9efcf82
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java
@@ -0,0 +1,235 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting02NEWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps) {
+ Assert.assertNotNull(caps);
+ Window window = NewtFactory.createWindow(screen, caps) ;
+ Assert.assertNotNull(window);
+ return window;
+ }
+
+ static Window createWindow(NativeWindow parent, Capabilities caps) {
+ Assert.assertNotNull(caps);
+ Window window = NewtFactory.createWindow(parent, caps);
+ window.setUndecorated(true);
+ Assert.assertNotNull(window);
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window, GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testWindowParenting01NewtOnNewtParentChildDraw() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(null);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ int x = 1;
+ int y = 1;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ Window window1 = createWindow(screen, caps);
+ Assert.assertNotNull(window1);
+ GLWindow glWindow1 = GLWindow.create(window1);
+ Assert.assertNotNull(glWindow1);
+ glWindow1.setSize(width, height);
+ Assert.assertEquals(width,glWindow1.getWidth());
+ Assert.assertEquals(height,glWindow1.getHeight());
+ glWindow1.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - PARENT");
+ glWindow1.setPosition(x,y);
+ glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow1.addWindowListener(new TraceWindowAdapter());
+
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, window1, glWindow1, false);
+ // glWindow1.addGLEventListener(demo1);
+
+ glWindow1.setVisible(true);
+ Capabilities capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
+
+ Window window2 = createWindow(window1, caps);
+ Assert.assertNotNull(window2);
+ GLWindow glWindow2 = GLWindow.create(window2);
+ Assert.assertNotNull(glWindow2);
+ glWindow2.setSize(width/2, height/2);
+ //Assert.assertEquals(width/2,glWindow2.getWidth());
+ //Assert.assertEquals(height/2,glWindow2.getHeight());
+ glWindow2.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - CHILD");
+ glWindow2.setPosition(glWindow1.getWidth()/2, glWindow1.getHeight()/2);
+ glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
+ // glWindow2.addMouseListener(new TraceMouseAdapter());
+
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, window2, glWindow2, false);
+ // glWindow2.addGLEventListener(demo2);
+
+ glWindow2.setVisible(true);
+ capsChosen = glWindow2.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
+
+ glWindow1.addGLEventListener(demo1);
+ glWindow2.addGLEventListener(demo2);
+
+ boolean shouldQuit = false;
+ long duration = durationPerTest;
+ long step = 20;
+ NEWTEvent event;
+
+ while (duration>0 && !shouldQuit) {
+ glWindow1.display();
+ glWindow2.display();
+ Thread.sleep(step);
+ duration -= step;
+ x += 1;
+ y += 1;
+ glWindow1.setPosition(x,y);
+ glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y);
+
+ while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
+ Window source = (Window) event.getSource();
+ if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) {
+ shouldQuit = true;
+ } else if(event instanceof KeyEvent) {
+ KeyEvent keyEvent = (KeyEvent) event;
+ switch(keyEvent.getKeyChar()) {
+ case 'q':
+ shouldQuit = true;
+ break;
+ case 'f':
+ source.setFullscreen(!source.isFullscreen());
+ break;
+ }
+ }
+ }
+ }
+ destroyWindow(null, null, window2, glWindow2);
+ destroyWindow(display, screen, window1, glWindow1);
+ }
+
+ public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(window);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting02NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03AWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03AWT.java
new file mode 100644
index 000000000..5fa7dee41
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03AWT.java
@@ -0,0 +1,203 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Label;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting03AWT extends UITestCase {
+ static Dimension size;
+ static long durationPerTest = 400;
+ static long waitAdd2nd = 200;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ size = new Dimension(400,200);
+ glCaps = new GLCapabilities(null);
+ glCaps.setAlphaBits(8);
+ glCaps.setBackgroundOpaque(false);
+ }
+
+ @Test
+ public void testWindowParenting1AWTOneNewtChild01() throws InterruptedException, InvocationTargetException {
+ testWindowParenting1AWTOneNewtChild();
+ }
+
+ public void testWindowParenting1AWTOneNewtChild() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.enablePerfLog(true);
+ glWindow1.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
+ newtCanvasAWT1.setPreferredSize(size);
+
+ GLEventListener demo1 = new Gears(1);
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1;
+ final GLWindow f_glWindow1 = glWindow1;
+ glWindow1.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow1.getParent()==null) {
+ System.err.println("XXX glWin1 -> home");
+ f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin1 -> TOP");
+ f_glWindow1.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ Container cont1 = new Container();
+ cont1.setLayout(new BorderLayout());
+ cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
+ cont1.setVisible(true);
+ final Container f_cont1 = cont1;
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(cont1, BorderLayout.EAST);
+ frame1.add(new Label("center"), BorderLayout.CENTER);
+ frame1.setLocation(0, 0);
+ frame1.setSize((int)size.getWidth(), (int)size.getHeight());
+ final Frame f_frame1 = frame1;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.pack();
+ f_frame1.setVisible(true);
+ }});
+
+ Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+
+ Thread.sleep(durationPerTest);
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ frame1.dispose();
+ glWindow1.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitAdd2nd = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting03AWT.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03bAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03bAWT.java
new file mode 100644
index 000000000..b4ced6973
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03bAWT.java
@@ -0,0 +1,258 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Label;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.test.junit.util.*;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting03bAWT extends UITestCase {
+ static Dimension size;
+ static long durationPerTest = 800;
+ static long waitAdd2nd = 500;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ size = new Dimension(400,200);
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException {
+ testWindowParenting1AWTTwoNewtChilds();
+ }
+
+ public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.enablePerfLog(true);
+ glWindow1.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
+ newtCanvasAWT1.setPreferredSize(size);
+
+ GLEventListener demo1 = new Gears(1);
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1;
+ final GLWindow f_glWindow1 = glWindow1;
+ glWindow1.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow1.getParent()==null) {
+ System.err.println("XXX glWin1 -> home");
+ f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin1 -> TOP");
+ f_glWindow1.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ GLWindow glWindow2 = GLWindow.create(glCaps);
+ glWindow2.enablePerfLog(true);
+ glWindow2.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
+ newtCanvasAWT2.setPreferredSize(size);
+
+ GLEventListener demo2 = new Gears(1);
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+ final NewtCanvasAWT f_newtCanvasAWT2 = newtCanvasAWT2;
+ final GLWindow f_glWindow2 = glWindow2;
+ glWindow2.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow2.setUndecorated(!f_glWindow2.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow2.setFullscreen(!f_glWindow2.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow2.getParent()==null) {
+ System.err.println("XXX glWin2 -> home");
+ f_glWindow2.reparentWindow(f_newtCanvasAWT2.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin2 -> TOP");
+ f_glWindow2.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ Container cont1 = new Container();
+ cont1.setLayout(new BorderLayout());
+ cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
+ cont1.setVisible(true);
+ final Container f_cont1 = cont1;
+
+ Container cont2 = new Container();
+ cont2.setLayout(new BorderLayout());
+ cont2.add(newtCanvasAWT2, BorderLayout.CENTER);
+ cont2.setVisible(true);
+ final Container f_cont2 = cont2;
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(cont1, BorderLayout.EAST);
+ frame1.add(new Label("center"), BorderLayout.CENTER);
+ frame1.setLocation(0, 0);
+ frame1.setSize((int)size.getWidth()*2, (int)size.getHeight()*2);
+ final Frame f_frame1 = frame1;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.pack();
+ f_frame1.setVisible(true);
+ }});
+
+ Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
+ Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent());
+
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+
+ Thread.sleep(waitAdd2nd);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.add(f_cont2, BorderLayout.WEST);
+ f_frame1.pack();
+ }});
+
+ Thread.sleep(durationPerTest);
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ frame1.dispose();
+ glWindow1.destroy(true);
+ glWindow2.destroy(true);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitAdd2nd = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting03bAWT.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java b/src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java
new file mode 100644
index 000000000..bcfb29440
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2010 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.test.junit.newt.parenting;
+
+import com.jogamp.newt.event.*;
+
+class WindowAction extends WindowAdapter {
+ NEWTEventFiFo eventFifo;
+
+ public WindowAction(NEWTEventFiFo eventFifo) {
+ this.eventFifo = eventFifo;
+ }
+
+ public void windowDestroyNotify(WindowEvent e) {
+ eventFifo.put(e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java
new file mode 100644
index 000000000..174152639
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+public class AWTFocusAdapter implements EventCountAdapter, FocusListener {
+
+ String prefix;
+ int focusGained;
+ boolean wasTemporary;
+
+ public AWTFocusAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ /** @return the balance of focus gained/lost, ie should be 0 or 1 */
+ public int getCount() {
+ return focusGained;
+ }
+
+ public void reset() {
+ focusGained = 0;
+ wasTemporary = false;
+ }
+
+ /** @return true, if the last change was temporary */
+ public boolean getWasTemporary() {
+ return wasTemporary;
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ ++focusGained;
+ wasTemporary = e.isTemporary();
+ System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ --focusGained;
+ wasTemporary = e.isTemporary();
+ System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java
new file mode 100644
index 000000000..8e255acb6
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements EventCountAdapter {
+
+ String prefix;
+ int keyTyped;
+
+ public AWTKeyAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return keyTyped;
+ }
+
+ public void reset() {
+ keyTyped = 0;
+ }
+
+ public void keyTyped(java.awt.event.KeyEvent e) {
+ ++keyTyped;
+ System.err.println("KEY AWT TYPED ["+keyTyped+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java
new file mode 100644
index 000000000..d78b3ed61
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements EventCountAdapter {
+ String prefix;
+ int mouseClicked;
+
+ public AWTMouseAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return mouseClicked;
+ }
+
+ public void reset() {
+ mouseClicked = 0;
+ }
+
+ public void mouseClicked(java.awt.event.MouseEvent e) {
+ mouseClicked+=e.getClickCount();
+ System.err.println("MOUSE AWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
new file mode 100644
index 000000000..c49de3e1f
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
@@ -0,0 +1,338 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.awt.AWTException;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.KeyboardFocusManager;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Window;
+import java.awt.event.InputEvent;
+import javax.swing.JFrame;
+
+public class AWTRobotUtil {
+
+ public static int TIME_OUT = 1000; // 1s
+ public static int ROBOT_DELAY = 50; // ms
+ public static int POLL_DIVIDER = 20; // TO/20
+
+ public static Point getCenterLocation(Object obj, boolean frameTitlebar)
+ throws InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ int x0, y0;
+ if(null!=comp) {
+ Point p0 = comp.getLocationOnScreen();
+ Rectangle r0 = comp.getBounds();
+ if( frameTitlebar && comp instanceof JFrame ) {
+ JFrame jFrame = (JFrame) comp;
+ Container cont = jFrame.getContentPane();
+ Point p1 = cont.getLocationOnScreen();
+ int dx = (int) ( r0.getWidth() / 2.0 + .5 );
+ int dy = (int) ( ( p1.getY() - p0.getY() ) / 2.0 + .5 );
+ x0 = (int) ( p0.getX() + dx + .5 ) ;
+ y0 = (int) ( p0.getY() + dy + .5 ) ;
+ } else {
+ x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ;
+ y0 = (int) ( p0.getY() + r0.getHeight() / 2.0 + .5 ) ;
+ }
+ } else {
+ javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null);
+ p0.translate(win.getWidth()/2, win.getHeight()/2);
+ x0 = p0.getX();
+ y0 = p0.getY();
+ }
+
+ return new Point(x0, y0);
+ }
+
+ /**
+ * toFront, call setVisible(true) and toFront(),
+ * after positioning the mouse in the middle of the window via robot.
+ * If the given robot is null, a new one is created (waitForIdle=true).
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean toFront(Robot robot, Window window)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+ Point p0 = getCenterLocation(window, false);
+ System.err.println("robot pos: "+p0);
+ robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
+ robot.delay(ROBOT_DELAY);
+
+ final Window f_window = window;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_window.setVisible(true);
+ f_window.toFront();
+ f_window.requestFocus();
+ }});
+ robot.delay(ROBOT_DELAY);
+
+ KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return wait<POLL_DIVIDER;
+ }
+
+ /**
+ * centerMouse
+ */
+ public static void centerMouse(Robot robot, Object obj)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ Point p0 = getCenterLocation(obj, false);
+ System.err.println("robot pos: "+p0);
+
+ robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
+ robot.delay(ROBOT_DELAY);
+ }
+
+ /**
+ * requestFocus, if robot is valid, use mouse operation,
+ * otherwise programatic, ie call requestFocus
+ */
+ public static void requestFocus(Robot robot, Object obj)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ if(null == robot) {
+ if(null!=comp) {
+ final Component f_comp = comp;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_comp.requestFocus();
+ }});
+ } else {
+ win.requestFocus();
+ }
+ return;
+ }
+
+ centerMouse(robot, obj);
+
+ robot.delay(ROBOT_DELAY);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ robot.delay(ROBOT_DELAY);
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+ robot.delay(ROBOT_DELAY);
+ }
+
+ /**
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean waitForFocus(Object obj) throws InterruptedException {
+ int wait;
+ if(obj instanceof Component) {
+ Component comp = (Component) obj;
+ KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ for (wait=0; wait<POLL_DIVIDER && comp != kfm.getPermanentFocusOwner(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ } else if(obj instanceof com.jogamp.newt.Window) {
+ com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj;
+ for (wait=0; wait<POLL_DIVIDER && !win.hasFocus(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+ return wait<POLL_DIVIDER;
+ }
+
+ /**
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean waitForFocus(Object obj, int gainT0, EventCountAdapter gain,
+ int lostT0, EventCountAdapter lost) throws InterruptedException {
+ if(!waitForFocus(obj)) {
+ return false;
+ }
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER; wait++) {
+ int gainT1 = gain.getCount();
+ int lostT1 = (null!=lost) ? lost.getCount() : -1;
+ if(gainT1-gainT0==1 && lostT1-lostT0==-1) {
+ return true;
+ }
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return false;
+ }
+
+ public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ requestFocus(robot, requestFocus);
+ return waitForFocus(waitForFocus);
+ }
+
+ public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus,
+ EventCountAdapter gain, EventCountAdapter lost)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ int gainT0 = gain.getCount();
+ int lostT0 = (null!=lost) ? lost.getCount() : 0;
+
+ requestFocus(robot, requestFocus);
+ return waitForFocus(waitForFocus, gainT0, gain, lostT0, lost);
+ }
+
+ /**
+ * @param keyTypedCounter shall return the number of keys typed (press + release)
+ * @return True if typeCount keys within TIME_OUT has been received
+ */
+ public static int testKeyType(Robot robot, int typeCount, Object obj, EventCountAdapter keyTypedCounter)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ centerMouse(robot, obj);
+
+ int c0 = keyTypedCounter.getCount();
+
+ for(int i=0; i<typeCount; i++) {
+ robot.keyPress(java.awt.event.KeyEvent.VK_A);
+ robot.delay(ROBOT_DELAY);
+ robot.keyRelease(java.awt.event.KeyEvent.VK_A);
+ robot.delay(ROBOT_DELAY);
+ }
+
+ // Wait for the key events to be processed.
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && (keyTypedCounter.getCount()-c0)<typeCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return keyTypedCounter.getCount()-c0;
+ }
+
+ /**
+ * @param mouseButton ie InputEvent.BUTTON1_MASK
+ * @param clickCount ie 1, or 2
+ * @return True if the desired clickCount within TIME_OUT has been received
+ */
+ public static int testMouseClick(Robot robot, int mouseButton, int clickCount,
+ Object obj, EventCountAdapter mouseClickCounter)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ final int clickTO = com.jogamp.newt.event.MouseEvent.getClickTimeout();
+
+ centerMouse(robot, obj);
+
+ robot.delay(2*clickTO);
+
+ int c0 = mouseClickCounter.getCount();
+
+ for(int i=0; i<clickCount; i++) {
+ robot.mousePress(mouseButton);
+ robot.delay(clickTO/4);
+ robot.mouseRelease(mouseButton);
+ robot.delay(clickTO/4);
+ }
+
+ // Wait for the key events to be processed.
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && (mouseClickCounter.getCount()-c0)<clickCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return mouseClickCounter.getCount()-c0;
+ }
+
+ /**
+ *
+ * @return True if the EventCountAdapter became the desired value within TIME_OUT
+ */
+ public static boolean waitForCount(int desired, EventCountAdapter eca) throws InterruptedException {
+ for (int wait=0; wait<POLL_DIVIDER; wait++) {
+ if( eca.getCount() == desired ) {
+ return true;
+ }
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return false;
+ }
+
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/DumpVersion.java b/src/junit/com/jogamp/test/junit/util/DumpVersion.java
new file mode 100644
index 000000000..df07c5bcf
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/DumpVersion.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.VersionInfo;
+import com.jogamp.common.os.Platform;
+
+import java.io.IOException;
+
+public class DumpVersion implements GLEventListener {
+
+ public void init(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+
+ String prefix = Thread.currentThread().getName();
+
+ System.err.println(VersionInfo.getInfo(null, prefix, gl).toString());
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java b/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java
new file mode 100644
index 000000000..e0561218a
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+public interface EventCountAdapter {
+
+ int getCount();
+ void reset();
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java b/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java
new file mode 100644
index 000000000..40b192a01
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import java.util.List;
+import java.util.Iterator;
+
+public abstract class EventCountAdapterUtil {
+
+ public static void reset(EventCountAdapter[] adapters) {
+ for(int i=0; i<adapters.length; i++) {
+ adapters[i].reset();
+ }
+ }
+
+ public static void reset(List/*<EventCountAdapter>*/ adapters) {
+ for(Iterator i = adapters.iterator(); i.hasNext(); ) {
+ EventCountAdapter adapter = (EventCountAdapter) i.next();
+ adapter.reset();
+ }
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/MiscUtils.java b/src/junit/com/jogamp/test/junit/util/MiscUtils.java
new file mode 100644
index 000000000..672bb7de0
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/MiscUtils.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import java.lang.reflect.*;
+
+public class MiscUtils {
+ @Deprecated
+ public static int str2int(String str, int def) {
+ try {
+ return Integer.parseInt(str);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return def;
+ }
+
+ public static boolean setFieldIfExists(Object instance, String fieldName, Object value) {
+ try {
+ Field f = instance.getClass().getField(fieldName);
+ if(value instanceof Boolean || f.getType().isInstance(value)) {
+ f.set(instance, value);
+ return true;
+ } else {
+ System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType());
+ }
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex);
+ } catch (NoSuchFieldException nsfe) {
+ // OK - throw new RuntimeException(instance.getClass()+" has no '"+fieldName+"' field", nsfe);
+ }
+ return false;
+ }
+}
+
+
+
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java
new file mode 100644
index 000000000..5cbd9fd15
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+
+public class NEWTFocusAdapter extends WindowAdapter implements EventCountAdapter {
+
+ String prefix;
+ int focusGained;
+
+ public NEWTFocusAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return focusGained;
+ }
+
+ public void reset() {
+ focusGained = 0;
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent e) {
+ ++focusGained;
+ System.err.println("FOCUS NEWT GAINED ["+focusGained+"]: "+prefix+", "+e);
+ }
+
+ @Override
+ public void windowLostFocus(WindowEvent e) {
+ --focusGained;
+ System.err.println("FOCUS NEWT LOST ["+focusGained+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java
new file mode 100644
index 000000000..73caa1846
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+
+public class NEWTKeyAdapter extends KeyAdapter implements EventCountAdapter {
+
+ String prefix;
+ int keyTyped;
+
+ public NEWTKeyAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return keyTyped;
+ }
+
+ public void reset() {
+ keyTyped = 0;
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ ++keyTyped;
+ System.err.println("KEY NEWT TYPED ["+keyTyped+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java
new file mode 100644
index 000000000..fc5c653f2
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import com.jogamp.newt.event.MouseAdapter;
+import com.jogamp.newt.event.MouseEvent;
+
+public class NEWTMouseAdapter extends MouseAdapter implements EventCountAdapter {
+
+ String prefix;
+ int mouseClicked;
+
+ public NEWTMouseAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return mouseClicked;
+ }
+
+ public void reset() {
+ mouseClicked = 0;
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ mouseClicked+=e.getClickCount();
+ System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/QuitAdapter.java b/src/junit/com/jogamp/test/junit/util/QuitAdapter.java
new file mode 100644
index 000000000..258132582
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/QuitAdapter.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.event.*;
+
+public class QuitAdapter extends WindowAdapter implements WindowListener, KeyListener {
+ boolean shouldQuit = false;
+
+ public boolean shouldQuit() { return shouldQuit; }
+
+ public void windowDestroyNotify(WindowEvent e) {
+ System.out.println("QUIT Window "+Thread.currentThread());
+ shouldQuit = true;
+ }
+
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='q') {
+ System.out.println("QUIT Key "+Thread.currentThread());
+ shouldQuit = true;
+ }
+ }
+ public void keyPressed(KeyEvent e) {}
+ public void keyReleased(KeyEvent e) {}
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/SingletonInstance.java b/src/junit/com/jogamp/test/junit/util/SingletonInstance.java
new file mode 100644
index 000000000..997742cf6
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/SingletonInstance.java
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+
+public class SingletonInstance {
+
+ static final boolean DEBUG = true;
+ static final String temp_file_path;
+
+ static {
+ String s = null;
+ try {
+ File tmpFile = File.createTempFile("TEST", "tst");
+ String absTmpFile = tmpFile.getCanonicalPath();
+ tmpFile.delete();
+ s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator));
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ temp_file_path = s;
+ }
+
+ public static String getCanonicalTempPath() {
+ return temp_file_path;
+ }
+
+ public static String getCanonicalTempLockFilePath(String basename) {
+ return getCanonicalTempPath() + File.separator + basename;
+ }
+
+ public SingletonInstance(String lockFileBasename) {
+ this.file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) );
+ }
+
+ public SingletonInstance(File lockFile) {
+ this.file = lockFile ;
+ }
+
+ public synchronized void lock(long timeout_ms, long poll_ms) {
+ long i=0;
+ try {
+ do {
+ if(tryLock()) {
+ return;
+ }
+ if(DEBUG && 0==i) {
+ System.err.println("Wait for lock " + file);
+ }
+ i++;
+ Thread.sleep(poll_ms);
+ } while ( i < timeout_ms / poll_ms ) ;
+ } catch ( InterruptedException ie ) {
+ throw new RuntimeException(ie);
+ }
+ throw new RuntimeException("SingletonInstance couldn't get lock within "+timeout_ms+"ms");
+ }
+
+ public synchronized boolean tryLock() {
+ try {
+ randomAccessFile = new RandomAccessFile(file, "rw");
+ fileLock = randomAccessFile.getChannel().tryLock();
+
+ if (fileLock != null) {
+ //final File f_file = file;
+ //final RandomAccessFile f_randomAccessFile = randomAccessFile;
+ //final FileLock f_fileLock = fileLock;
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ unlock();
+ }
+ });
+ locked = true;
+ if(DEBUG) {
+ System.err.println("Locked " + file);
+ }
+ return true;
+ }
+ } catch (Exception e) {
+ System.err.println("Unable to create and/or lock file: " + file);
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public synchronized boolean unlock() {
+ if(locked) {
+ try {
+ fileLock.release();
+ randomAccessFile.close();
+ file.delete();
+ return true;
+ } catch (Exception e) {
+ System.err.println("Unable to remove lock file: " + file);
+ e.printStackTrace();
+ } finally {
+ fileLock = null;
+ randomAccessFile = null;
+ locked = false;
+ }
+ }
+ return false;
+ }
+
+ public synchronized boolean isLocked() {
+ return locked;
+ }
+
+ File file = null;
+ RandomAccessFile randomAccessFile = null;
+ FileLock fileLock = null;
+ boolean locked = false;
+}
diff --git a/src/junit/com/jogamp/test/junit/util/UITestCase.java b/src/junit/com/jogamp/test/junit/util/UITestCase.java
new file mode 100644
index 000000000..e169405b0
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/UITestCase.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2010 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.test.junit.util;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+
+import java.lang.reflect.InvocationTargetException;
+
+public abstract class UITestCase {
+
+ public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock";
+
+ static SingletonInstance singletonInstance;
+
+ protected SingletonInstance getSingletonInstance() {
+ return singletonInstance;
+ }
+
+ @BeforeClass
+ public static void oneTimeSetUp() {
+ // one-time initialization code
+ singletonInstance = new SingletonInstance(SINGLE_INSTANCE_LOCK_FILE);
+ singletonInstance.lock(3*60*1000, 100); // wait up to 3 min, poll every 100ms
+ }
+
+ @AfterClass
+ public static void oneTimeTearDown() {
+ // one-time cleanup code
+ System.gc(); // force cleanup
+ singletonInstance.unlock();
+ }
+
+ @Before
+ public void setUp() {
+ System.err.println("++++ UITestCase.setUp: "+getClass().getName());
+ }
+
+ @After
+ public void tearDown() {
+ System.err.println("++++ UITestCase.tearDown: "+getClass().getName());
+ }
+
+}
+