diff options
Diffstat (limited to 'src/junit/com/jogamp')
78 files changed, 0 insertions, 12992 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 deleted file mode 100644 index a1ca698ba..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * 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.common.GlueGenVersion; -import com.jogamp.common.util.VersionUtil; -import com.jogamp.nativewindow.NativeWindowVersion; -import com.jogamp.test.junit.util.UITestCase; -import com.jogamp.test.junit.util.DumpGLInfo; - -import org.junit.Assert; -import org.junit.Test; - -import javax.media.opengl.*; -import com.jogamp.newt.opengl.*; - -import com.jogamp.newt.*; -import com.jogamp.opengl.JoglVersion; -import java.io.IOException; - -public class TestGLProfile01NEWT extends UITestCase { - - @Test - public void test00Version() throws InterruptedException { - System.err.println(VersionUtil.getPlatformInfo()); - System.err.println(GlueGenVersion.getInstance()); - System.err.println(NativeWindowVersion.getInstance()); - System.err.println(JoglVersion.getInstance()); - System.err.println(NewtVersion.getInstance()); - } - - @Test - public void test01GLProfileDefault() throws InterruptedException { - System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); - GLProfile glp = GLProfile.getDefault(); - dumpVersion(glp); - } - - @Test - public void test02GLProfileMaxFixedFunc() throws InterruptedException { - // Assuming at least one fixed profile is available - GLProfile glp = GLProfile.getMaxFixedFunc(); - System.out.println("GLProfile 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() throws InterruptedException { - // Assuming at least one programmable profile is available - GLProfile glp = GLProfile.getMaxProgrammable(); - System.out.println("GLProfile 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() throws InterruptedException { - if(!GLProfile.isGL2ES1Available()) { - System.out.println("GLProfile GL2ES1 n/a"); - return; - } - GLProfile glp = GLProfile.getGL2ES1(); - System.out.println("GLProfile GL2ES1: "+glp); - dumpVersion(glp); - } - - @Test - public void test05GLProfileGL2ES2() throws InterruptedException { - if(!GLProfile.isGL2ES2Available()) { - System.out.println("GLProfile GL2ES2 n/a"); - return; - } - GLProfile glp = GLProfile.getGL2ES2(); - System.out.println("GLProfile GL2ES2: "+glp); - dumpVersion(glp); - } - - protected void dumpVersion(GLProfile glp) throws InterruptedException { - GLCapabilities caps = new GLCapabilities(glp); - GLWindow glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - glWindow.setTitle("TestGLProfile01NEWT"); - - glWindow.addGLEventListener(new DumpGLInfo()); - - glWindow.setSize(128, 128); - glWindow.setVisible(true); - - glWindow.display(); - Thread.sleep(100); - glWindow.invalidate(); - } - - 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/acore/TestSharedContextListAWT.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListAWT.java deleted file mode 100644 index b44158dce..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListAWT.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * 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 javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLPbuffer; -import javax.media.opengl.GLProfile; -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.BeforeClass; -import org.junit.Test; - -public class TestSharedContextListAWT extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - static int width, height; - GLPbuffer sharedDrawable; - Gears sharedGears; - - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - width = 512; - height = 512; - } - - private void initShared() { - sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null); - Assert.assertNotNull(sharedDrawable); - sharedGears = new Gears(); - Assert.assertNotNull(sharedGears); - sharedDrawable.addGLEventListener(sharedGears); - // init and render one frame, which will setup the Gears display lists - sharedDrawable.display(); - } - - private void releaseShared() { - Assert.assertNotNull(sharedDrawable); - sharedDrawable.destroy(); - } - - protected Frame runTestGL(Animator animator, int x, int y, boolean useShared) { - Frame frame = new Frame("Shared Gears AWT Test: "+x+"/"+y+" shared "+useShared); - Assert.assertNotNull(frame); - - GLCanvas glCanvas = new GLCanvas(caps, useShared ? sharedDrawable.getContext() : null); - Assert.assertNotNull(glCanvas); - frame.add(glCanvas); - frame.setSize(width, height); - frame.setLocation(x, y); - - Gears gears = new Gears(); - if(useShared) { - gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); - } - glCanvas.addGLEventListener(gears); - - animator.add(glCanvas); - - frame.setVisible(true); - - return frame; - } - - @Test - public void test01() throws InterruptedException { - initShared(); - Animator animator = new Animator(); - Frame f1 = runTestGL(animator, 0, 0, true); - Frame f2 = runTestGL(animator, width, 0, true); - Frame f3 = runTestGL(animator, 0, height, false); - animator.start(); - while(animator.isAnimating() && animator.getDuration()<duration) { - Thread.sleep(100); - } - animator.stop(); - f1.dispose(); - f2.dispose(); - f3.dispose(); - releaseShared(); - } - - 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(TestSharedContextListAWT.class.getName()); - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java deleted file mode 100644 index cccd91b4c..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * 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.newt.opengl.GLWindow; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLPbuffer; -import javax.media.opengl.GLProfile; -import com.jogamp.opengl.util.Animator; - -import com.jogamp.test.junit.util.UITestCase; -import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestSharedContextListNEWT extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - static int width, height; - GLPbuffer sharedDrawable; - Gears sharedGears; - - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - width = 512; - height = 512; - } - - private void initShared() { - sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null); - Assert.assertNotNull(sharedDrawable); - sharedGears = new Gears(); - Assert.assertNotNull(sharedGears); - sharedDrawable.addGLEventListener(sharedGears); - // init and render one frame, which will setup the Gears display lists - sharedDrawable.display(); - } - - private void releaseShared() { - Assert.assertNotNull(sharedDrawable); - sharedDrawable.destroy(); - } - - protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared) { - GLWindow glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared); - if(useShared) { - glWindow.setSharedContext(sharedDrawable.getContext()); - } - - glWindow.setSize(width, height); - glWindow.setPosition(x, y); - - Gears gears = new Gears(); - if(useShared) { - gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); - } - glWindow.addGLEventListener(gears); - - animator.add(glWindow); - - glWindow.setVisible(true); - - return glWindow; - } - - @Test - public void test01() throws InterruptedException { - initShared(); - Animator animator = new Animator(); - GLWindow f1 = runTestGL(animator, 0, 0, true); - GLWindow f2 = runTestGL(animator, width, 0, true); - GLWindow f3 = runTestGL(animator, 0, height, false); - animator.start(); - while(animator.isAnimating() && animator.getDuration()<duration) { - Thread.sleep(100); - } - animator.stop(); - f1.destroy(); - f2.destroy(); - f3.destroy(); - releaseShared(); - } - - 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(TestSharedContextListNEWT.class.getName()); - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java deleted file mode 100644 index a1c87da79..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * 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 "+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); - glCanvas.addGLEventListener(new Gears()); - frame.add(glCanvas); - - // Revalidate size/layout. - // Always validate if component added/removed. - // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created. - frame.setSize(512, 512); - frame.validate(); - - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.setVisible(true); - }}); - } catch (Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - - glCanvas.display(); // one in process display - - 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 deleted file mode 100644 index 6132f8232..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT02WindowClosing.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * 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/TestAWT03GLCanvasRecreate01.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java deleted file mode 100644 index a2f66859f..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java +++ /dev/null @@ -1,183 +0,0 @@ -/** - * 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.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 com.jogamp.test.junit.util.MiscUtils; - -import java.awt.Frame; -import java.awt.Label; - -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 TestAWT03GLCanvasRecreate01 extends UITestCase { - static long durationPerTest = 1000; // ms - - Frame frame1=null; - Frame frame2=null; - GLCanvas glCanvas=null; - Label label = null; - Animator animator = null; - - @BeforeClass - public static void startup() { - GLProfile.initSingleton(true); - System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); - } - - @Before - public void init() { - glCanvas = new GLCanvas(); - Assert.assertNotNull(glCanvas); - glCanvas.addGLEventListener(new Gears()); - - animator = new Animator(glCanvas); - animator.start(); - - label = new Label("No GLCanvas"); - - frame1 = new Frame("Frame 1"); - Assert.assertNotNull(frame1); - frame1.add(label); - frame1.setSize(512, 512); - frame1.setLocation(0, 0); - - frame2 = new Frame("Frame 2"); - Assert.assertNotNull(frame2); - frame2.add(label); - frame2.setSize(512, 512); - frame2.setLocation(512, 0); - } - - @After - public void release() { - Assert.assertNotNull(frame1); - Assert.assertNotNull(frame2); - Assert.assertNotNull(glCanvas); - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - glCanvas.destroy(); - frame1.dispose(); - frame2.dispose(); - }}); - } catch (Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - frame1=null; - frame2=null; - glCanvas=null; - - animator.stop(); - animator=null; - } - - private void addCanvas(final Frame frame) { - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.remove(label); - frame.add(glCanvas); - frame.validate(); - }}); - } catch (Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - } - - private void removeCanvas(final Frame frame) { - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.remove(glCanvas); - frame.add(label); - frame.validate(); - }}); - } catch (Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - } - - private void setVisible(final Frame frame, final boolean v) { - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.setVisible(v); - }}); - } catch (Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - } - - - @Test - public void testAddRemove3Times() throws InterruptedException { - setVisible(frame1, true); - setVisible(frame2, true); - - addCanvas(frame1); - Thread.sleep(durationPerTest/4); - - removeCanvas(frame1); - addCanvas(frame2); - Thread.sleep(durationPerTest/4); - - removeCanvas(frame2); - addCanvas(frame1); - Thread.sleep(durationPerTest/4); - - removeCanvas(frame1); - addCanvas(frame2); - Thread.sleep(durationPerTest/4); - } - - public static void main(String args[]) { - for(int i=0; i<args.length; i++) { - if(args[i].equals("-time")) { - durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); - } - } - org.junit.runner.JUnitCore.main(TestAWT03GLCanvasRecreate01.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 deleted file mode 100644 index 74ca0a3e7..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * 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 "+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]); - - // Revalidate size/layout. - // Always validate if component added/removed. - // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created. - window.setSize(512, 512); - window.validate(); - - window.setVisible(true); - glCanvas[0].display(); - } - }; - - 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/caps/MultisampleChooser01.java b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleChooser01.java deleted file mode 100644 index 7dcde18c9..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleChooser01.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 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: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.test.junit.jogl.caps; - -import javax.media.opengl.DefaultGLCapabilitiesChooser; -import javax.media.opengl.GLCapabilitiesImmutable; - -class MultisampleChooser01 extends DefaultGLCapabilitiesChooser { - - public int chooseCapabilities(GLCapabilitiesImmutable desired, GLCapabilitiesImmutable[] available, int windowSystemRecommendedChoice) { - boolean anyHaveSampleBuffers = false; - for (int i = 0; i < available.length; i++) { - GLCapabilitiesImmutable caps = available[i]; - if (caps != null && caps.getSampleBuffers()) { - anyHaveSampleBuffers = true; - break; - } - } - int selection = super.chooseCapabilities(desired, available, windowSystemRecommendedChoice); - if (!anyHaveSampleBuffers) { - System.err.println("WARNING: antialiasing will be disabled because none of the available pixel formats had it to offer"); - } else { - if (!available[selection].getSampleBuffers()) { - System.err.println("WARNING: antialiasing will be disabled because the DefaultGLCapabilitiesChooser didn't supply it"); - } - } - return selection; - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java deleted file mode 100644 index e399de0bc..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 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: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.test.junit.jogl.caps; - -import com.jogamp.opengl.impl.x11.glx.GLX; -import com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfiguration; -import javax.media.nativewindow.AbstractGraphicsConfiguration; -import javax.media.nativewindow.NativeWindowFactory; -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLPipelineFactory; - -class MultisampleDemo01 implements GLEventListener { - - static boolean glDebug = false; - static boolean glTrace = false; - - boolean multisample; - - public MultisampleDemo01(boolean multisample) { - this.multisample = multisample; - } - - public void init(GLAutoDrawable drawable) { - AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - System.err.println(); - System.err.println("Info: " + config); - System.err.println(); - if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(false))) { - X11GLXGraphicsConfiguration x11config = (X11GLXGraphicsConfiguration) config; - long display = drawable.getNativeSurface().getDisplayHandle(); - int[] foo = new int[1]; - GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLES, foo, 0); - System.out.println("GLX_SAMPLES " + foo[0]); - GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLE_BUFFERS, foo, 0); - System.out.println("GLX_SAMPLE_BUFFERS " + foo[0]); - } - GL _gl = drawable.getGL(); - if (glDebug) { - try { - // Debug .. - _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Debug", GL2.class, _gl, null)); - if (glTrace) { - // Trace .. - _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Trace", GL2.class, _gl, new Object[]{System.err})); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - GL2 gl = _gl.getGL2(); - if (multisample) { - gl.glEnable(GL.GL_MULTISAMPLE); - } - gl.glClearColor(0, 0, 0, 0); - // gl.glEnable(GL.GL_DEPTH_TEST); - // gl.glDepthFunc(GL.GL_LESS); - gl.glMatrixMode(GL2ES1.GL_MODELVIEW); - gl.glLoadIdentity(); - gl.glMatrixMode(GL2ES1.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glOrtho(-1, 1, -1, 1, -1, 1); - if (multisample) { - gl.glDisable(GL.GL_MULTISAMPLE); - } - } - - public void dispose(GLAutoDrawable drawable) { - } - - public void display(GLAutoDrawable drawable) { - GL2 gl = drawable.getGL().getGL2(); - if (multisample) { - gl.glEnable(GL.GL_MULTISAMPLE); - } - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - int numSteps = 20; - double increment = Math.PI / numSteps; - double radius = 1; - gl.glBegin(GL.GL_LINES); - for (int i = numSteps - 1; i >= 0; i--) { - gl.glVertex3d(radius * Math.cos(i * increment), radius * Math.sin(i * increment), 0); - gl.glVertex3d(-1.0 * radius * Math.cos(i * increment), -1.0 * radius * Math.sin(i * increment), 0); - } - gl.glEnd(); - if (multisample) { - gl.glDisable(GL.GL_MULTISAMPLE); - } - } - - // Unused routines - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - } - - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java deleted file mode 100755 index c6e7f08fa..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 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: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.test.junit.jogl.caps; - -import com.jogamp.test.junit.util.MiscUtils; -import java.awt.*; -import javax.media.opengl.*; -import javax.media.opengl.awt.GLCanvas; -import com.jogamp.test.junit.util.UITestCase; -import javax.media.nativewindow.AbstractGraphicsDevice; -import javax.media.nativewindow.AbstractGraphicsScreen; -import javax.media.nativewindow.GraphicsConfigurationFactory; -import javax.media.nativewindow.awt.AWTGraphicsConfiguration; -import javax.media.nativewindow.awt.AWTGraphicsDevice; -import javax.media.nativewindow.awt.AWTGraphicsScreen; -import org.junit.Test; - - -public class TestMultisampleAWT extends UITestCase { - static long durationPerTest = 500; // ms - private GLCanvas canvas; - - public static void main(String[] args) { - for(int i=0; i<args.length; i++) { - if(args[i].equals("-time")) { - durationPerTest = MiscUtils.atoi(args[++i], 500); - } - } - System.out.println("durationPerTest: "+durationPerTest); - String tstname = TestMultisampleAWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - - @Test - public void testMultiSampleAA4() throws InterruptedException { - testMultiSampleAAImpl(4); - } - - // @Test - public void testMultiSampleNone() throws InterruptedException { - testMultiSampleAAImpl(0); - } - - private void testMultiSampleAAImpl(int samples) throws InterruptedException { - GLCapabilities caps = new GLCapabilities(null); - GLCapabilitiesChooser chooser = new MultisampleChooser01(); - - if(samples>0) { - caps.setSampleBuffers(true); - caps.setNumSamples(samples); - } - // turns out we need to have alpha, - // otherwise no AA will be visible. - caps.setAlphaBits(1); - - /** - * whatever I tried here (passing and preconfig GraphicsConfiguration) - * either it just didn't picked up .. or the context couldn't be made current. - * - GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); - GraphicsConfiguration gc = AWTGraphicsConfiguration.getAWTGraphicsConfiguration(caps, gd); - - AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(gd, AbstractGraphicsDevice.DEFAULT_UNIT); - AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(caps, caps, - chooser, aScreen); - canvas = new GLCanvas(caps, chooser, null, gd, config.getGraphicsConfiguration(), config); */ - canvas = new GLCanvas(caps, chooser, null, null); - canvas.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); - - Frame frame = new Frame("Multi Samples "+samples); - frame.setLayout(new BorderLayout()); - canvas.setSize(512, 512); - frame.add(canvas, BorderLayout.CENTER); - frame.pack(); - frame.setVisible(true); - frame.setLocation(0, 0); - canvas.requestFocus(); - - Thread.sleep(durationPerTest); - - frame.dispose(); - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java deleted file mode 100755 index c060828ec..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 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: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.test.junit.jogl.caps; - -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.test.junit.util.MiscUtils; -import javax.media.opengl.*; -import org.junit.Test; - -public class TestMultisampleNEWT { - static long durationPerTest = 500; // ms - private GLWindow window; - - public static void main(String[] args) { - for(int i=0; i<args.length; i++) { - if(args[i].equals("-time")) { - durationPerTest = MiscUtils.atoi(args[++i], 500); - } - } - System.out.println("durationPerTest: "+durationPerTest); - String tstname = TestMultisampleNEWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - - @Test - public void testMultiSampleAA4() throws InterruptedException { - testMultiSampleAAImpl(4); - } - - // @Test - public void testMultiSampleNone() throws InterruptedException { - testMultiSampleAAImpl(0); - } - - private void testMultiSampleAAImpl(int samples) throws InterruptedException { - GLCapabilities caps = new GLCapabilities(null); - GLCapabilitiesChooser chooser = new MultisampleChooser01(); - - if(samples>0) { - caps.setSampleBuffers(true); - caps.setNumSamples(4); - } - // turns out we need to have alpha, - // otherwise no AA will be visible. - caps.setAlphaBits(1); - - window = GLWindow.create(caps); - window.setCapabilitiesChooser(chooser); - window.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); - window.setSize(512, 512); - window.setVisible(true); - window.setPosition(0, 0); - window.requestFocus(); - - GLCapabilitiesImmutable capsChosen0 = window.getChosenGLCapabilities(); - - Thread.sleep(durationPerTest); - - window.destroy(); - } - -} 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 deleted file mode 100644 index be416f01d..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java +++ /dev/null @@ -1,169 +0,0 @@ -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/es2/RedSquare0.java b/src/junit/com/jogamp/test/junit/jogl/demos/es2/RedSquare0.java deleted file mode 100644 index 229635ae5..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/es2/RedSquare0.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * 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.es2; - -import com.jogamp.common.nio.Buffers; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.GLArrayDataWrapper; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.test.junit.jogl.demos.es2.shader.RedSquareShader; -import com.jogamp.test.junit.util.GLSLSimpleProgram; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.nio.FloatBuffer; -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLContext; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLUniformData; -import org.junit.Assert; - -public class RedSquare0 implements GLEventListener { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream pbaos = new PrintStream(baos); - GLSLSimpleProgram myShader; - PMVMatrix pmvMatrix; - int mgl_PMVMatrix; - GLUniformData pmvMatrixUniform; - int mgl_Vertex; - int mgl_Color; - long t0; - - public void init(GLAutoDrawable glad) { - GLContext context = glad.getContext(); - context.makeCurrent(); - GL2ES2 gl = context.getGL().getGL2ES2(); - myShader = GLSLSimpleProgram.create(gl, RedSquareShader.VERTEX_SHADER_TEXT, RedSquareShader.FRAGMENT_SHADER_TEXT, true); - gl.glUseProgram(myShader.getShaderProgram()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // setup mgl_PMVMatrix - pmvMatrix = new PMVMatrix(); - pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - mgl_PMVMatrix = gl.glGetUniformLocation(myShader.getShaderProgram(), "mgl_PMVMatrix"); - Assert.assertTrue(0 <= mgl_PMVMatrix); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); - pmvMatrixUniform.setLocation(mgl_PMVMatrix); - gl.glUniform(pmvMatrixUniform); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // Allocate Vertex Array - int components = 3; - int numElements = 4; - mgl_Vertex = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Vertex"); - Assert.assertTrue(0 <= mgl_Vertex); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components); - GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0); - { - // Fill them up - FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer(); - verticeb.put(-2); - verticeb.put(2); - verticeb.put(0); - verticeb.put(2); - verticeb.put(2); - verticeb.put(0); - verticeb.put(-2); - verticeb.put(-2); - verticeb.put(0); - verticeb.put(2); - verticeb.put(-2); - verticeb.put(0); - } - buffer.flip(); - vertices.setLocation(mgl_Vertex); - gl.glEnableVertexAttribArray(mgl_Vertex); - gl.glVertexAttribPointer(vertices); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // Allocate Color Array - components = 4; - numElements = 4; - mgl_Color = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Color"); - Assert.assertTrue(0 <= mgl_Color); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - buffer = Buffers.newDirectFloatBuffer(numElements * components); - GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0); - { - // Fill them up - FloatBuffer colorb = (FloatBuffer) colors.getBuffer(); - colorb.put(1); - colorb.put(0); - colorb.put(0); - colorb.put(1); - colorb.put(0); - colorb.put(0); - colorb.put(1); - colorb.put(1); - colorb.put(1); - colorb.put(0); - colorb.put(0); - colorb.put(1); - colorb.put(1); - colorb.put(0); - colorb.put(0); - colorb.put(1); - } - buffer.flip(); - colors.setLocation(mgl_Color); - gl.glEnableVertexAttribArray(mgl_Color); - gl.glVertexAttribPointer(colors); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // OpenGL Render Settings - gl.glClearColor(0, 0, 0, 1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - gl.glUseProgram(0); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - t0 = System.currentTimeMillis(); - } - - public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { - GL2ES2 gl = glad.getGL().getGL2ES2(); - gl.glUseProgram(myShader.getShaderProgram()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // 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); - //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); - gl.glUniform(pmvMatrixUniform); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glUseProgram(0); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - } - - public void display(GLAutoDrawable glad) { - long t1 = System.currentTimeMillis(); - - GL2ES2 gl = glad.getGL().getGL2ES2(); - gl.glUseProgram(myShader.getShaderProgram()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // One rotation every four seconds - pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glTranslatef(0, 0, -10); - float ang = ((float) (t1 - t0) * 360.0F) / 4000.0F; - pmvMatrix.glRotatef(ang, 0, 0, 1); - pmvMatrix.glRotatef(ang, 0, 1, 0); - gl.glUniform(pmvMatrixUniform); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // Draw a square - gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glUseProgram(0); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - } - - public void dispose(GLAutoDrawable glad) { - GL2ES2 gl = glad.getGL().getGL2ES2(); - gl.glDisableVertexAttribArray(mgl_Vertex); - gl.glDisableVertexAttribArray(mgl_Color); - myShader.release(gl); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - pmvMatrix.destroy(); - pmvMatrix = null; - System.err.println("dispose done"); - } -} diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/es2/shader/RedSquareShader.java b/src/junit/com/jogamp/test/junit/jogl/demos/es2/shader/RedSquareShader.java deleted file mode 100644 index 5a365be11..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/es2/shader/RedSquareShader.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.es2.shader; - -public class RedSquareShader { - public static String VERTEX_SHADER_TEXT = - " #ifdef GL_ES\n" + - " #define MEDIUMP mediump\n" + - " #define HIGHP highp\n" + - "#else\n" + - " #define MEDIUMP\n" + - " #define HIGHP\n" + - "#endif\n" + - "\n" + - "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n" + - "attribute HIGHP vec4 mgl_Vertex;\n" + - "attribute HIGHP vec4 mgl_Color;\n" + - "varying HIGHP vec4 frontColor;\n" + - "\n" + - "void main(void)\n" + - "{\n" + - " frontColor=mgl_Color;\n" + - " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n" + - "}\n" ; - - public static String FRAGMENT_SHADER_TEXT = - "#ifdef GL_ES\n" + - " #define MEDIUMP mediump\n" + - " #define HIGHP highp\n" + - "#else\n" + - " #define MEDIUMP\n" + - " #define HIGHP\n" + - "#endif\n" + - "\n" + - "varying HIGHP vec4 frontColor;\n" + - "\n" + - "void main (void)\n" + - "{\n" + - " gl_FragColor = frontColor;\n" + - "}\n" ; - -} 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 deleted file mode 100644 index 432bedbb9..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java +++ /dev/null @@ -1,353 +0,0 @@ - -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=0, gear2=0, gear3=0; - 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 setGears(int g1, int g2, int g3) { - gear1 = g1; - gear2 = g2; - gear3 = g3; - } - - /** - * @return display list gear1 - */ - public int getGear1() { return gear1; } - - /** - * @return display list gear2 - */ - public int getGear2() { return gear2; } - - /** - * @return display list gear3 - */ - public int getGear3() { return gear3; } - - 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 */ - if(0>=gear1) { - 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(); - System.err.println("gear1 list created: "+gear1); - } else { - System.err.println("gear1 list reused: "+gear1); - } - - if(0>=gear2) { - 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(); - System.err.println("gear2 list created: "+gear2); - } else { - System.err.println("gear2 list reused: "+gear2); - } - - if(0>=gear3) { - 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(); - System.err.println("gear3 list created: "+gear3); - } else { - System.err.println("gear3 list reused: "+gear3); - } - - 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"); - setGears(0, 0, 0); - } - - 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 deleted file mode 100644 index 3e7e5988b..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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 java.awt.Frame; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.AfterClass; -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/TestGearsGLJPanelAWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java deleted file mode 100644 index dfb70f61f..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * 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.FPSAnimator; -import javax.media.opengl.awt.GLJPanel; - -import com.jogamp.test.junit.util.UITestCase; -import java.awt.AWTException; -import java.awt.BorderLayout; -import java.lang.reflect.InvocationTargetException; -import javax.swing.JFrame; -import javax.swing.SwingUtilities; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; - -public class TestGearsGLJPanelAWT extends UITestCase { - static GLProfile glp; - static int width, height; - - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(false); - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - width = 512; - height = 512; - } - - @AfterClass - public static void releaseClass() { - } - - protected void runTestGL(GLCapabilities caps) - throws AWTException, InterruptedException, InvocationTargetException - { - JFrame frame = new JFrame("Swing GLJPanel"); - Assert.assertNotNull(frame); - - GLJPanel glJPanel = new GLJPanel(caps); - Assert.assertNotNull(glJPanel); - glJPanel.addGLEventListener(new Gears()); - - FPSAnimator animator = new FPSAnimator(glJPanel, 60); - - final JFrame _frame = frame; - final GLJPanel _glJPanel = glJPanel; - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - _frame.getContentPane().add(_glJPanel, BorderLayout.CENTER); - _frame.setSize(512, 512); - _frame.setVisible(true); - } } ) ; - - animator.start(); - Assert.assertEquals(true, animator.isAnimating()); - - while(animator.isAnimating() && animator.getDuration()<duration) { - Thread.sleep(100); - } - - Assert.assertNotNull(frame); - Assert.assertNotNull(glJPanel); - Assert.assertNotNull(animator); - - animator.stop(); - Assert.assertEquals(false, animator.isAnimating()); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - _frame.setVisible(false); - _frame.getContentPane().remove(_glJPanel); - _frame.remove(_glJPanel); - _glJPanel.destroy(); - _frame.dispose(); - } } ); - } - - @Test - public void test01() - throws AWTException, InterruptedException, InvocationTargetException - { - 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(TestGearsGLJPanelAWT.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 deleted file mode 100644 index d83deea4b..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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.invalidate(); - } - - @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 deleted file mode 100644 index d0b8cc7de..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * 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(GLCapabilitiesImmutable 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.invalidate(); - } - - @Test - public void test01() throws InterruptedException { - GLCapabilitiesImmutable 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 deleted file mode 100644 index 9b6194ca6..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * 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.invalidate(); - - 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/TestGLSLSimple01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java deleted file mode 100644 index f1b4297e2..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * 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.glsl; - -import com.jogamp.test.junit.jogl.demos.es2.RedSquare0; -import com.jogamp.test.junit.util.GLSLSimpleProgram; -import com.jogamp.test.junit.util.UITestCase; - - -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLContext; -import javax.media.opengl.GLProfile; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.Animator; -import com.jogamp.test.junit.jogl.demos.es2.shader.RedSquareShader; -import com.jogamp.test.junit.util.MiscUtils; - -import java.io.IOException; -import javax.media.opengl.GL2ES2; -import org.junit.AfterClass; - -public class TestGLSLSimple01NEWT extends UITestCase { - static long durationPerTest = 100; // ms - - @BeforeClass - public static void initClass() { - System.err.println("class init"); - GLProfile.initSingleton(true); - } - - @AfterClass - public static void tearDownClass() { - System.err.println("class tear down .."); - GLProfile.shutdown(); - System.err.println("class tear down end"); - } - - @Test(timeout=60000) - public void testGLSLCompilation01() { - GLProfile glp = GLProfile.get(GLProfile.GL2ES2); - Assert.assertNotNull(glp); - GLCapabilities caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - - GLWindow window = GLWindow.create(caps); - Assert.assertNotNull(window); - window.setSize(800, 600); - window.setVisible(true); - Assert.assertTrue(window.isNativeValid()); - - GLContext context = window.getContext(); - context.setSynchronized(true); - - // trigger native creation of drawable/context - window.display(); - Assert.assertTrue(window.isRealized()); - Assert.assertTrue(window.getContext().isCreated()); - - context.makeCurrent(); - - // given - - GL2ES2 gl = context.getGL().getGL2ES2(); - GLSLSimpleProgram myShader = GLSLSimpleProgram.create(gl, - RedSquareShader.VERTEX_SHADER_TEXT, - RedSquareShader.FRAGMENT_SHADER_TEXT, - true); - - myShader.release(gl); - context.release(); - window.destroy(); - } - - @Test(timeout=60000) - public void testGLSLUse01() throws InterruptedException { - GLProfile glp = GLProfile.get(GLProfile.GL2ES2); - Assert.assertNotNull(glp); - GLCapabilities caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - - GLWindow window = GLWindow.create(caps); - Assert.assertNotNull(window); - window.setSize(800, 600); - window.setVisible(true); - Assert.assertTrue(window.isNativeValid()); - window.addGLEventListener(new RedSquare0()); - - Animator animator = new Animator(window); - animator.start(); - Assert.assertEquals(true, animator.isAnimating()); - while(animator.isAnimating() && animator.getDuration()<durationPerTest) { - Thread.sleep(100); - } - Assert.assertEquals(true, animator.isAnimating()); - - window.destroy(); - animator.stop(); - } - - public static void main(String args[]) throws IOException { - System.err.println("main - start"); - for(int i=0; i<args.length; i++) { - if(args[i].equals("-time")) { - durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); - } - } - String tstname = TestGLSLSimple01NEWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - System.err.println("main - end"); - } - -} diff --git a/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java b/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java deleted file mode 100644 index 8da48dccd..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java +++ /dev/null @@ -1,231 +0,0 @@ -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.GLProfile; - -import org.junit.Assert; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.glsl.ShaderUtil; - -import java.io.IOException; -import org.junit.AfterClass; - -/** - * Bug 'Function glTransformFeedbackVaryings incorrectly passes argument' - * http://jogamp.org/bugzilla/show_bug.cgi?id=407 - */ -public class TestTransformFeedbackVaryingsBug407NEWT extends UITestCase { - - private String VERTEX_SHADER_TEXT; - - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - - @AfterClass - public static void tearDownClass() { - GLProfile.shutdown(); - } - - class MyShader { - int shaderProgram; - int vertShader; - - MyShader(int shaderProgram, int vertShader) { - this.shaderProgram = shaderProgram; - this.vertShader = vertShader; - } - } - - private MyShader 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 new MyShader(shaderProgram, vertShader); - } - - private void releaseShader(GL3 gl, MyShader myShader) { - if(null!=myShader) { - gl.glDetachShader(myShader.shaderProgram, myShader.vertShader); - gl.glDeleteShader(myShader.vertShader); - gl.glDeleteProgram(myShader.shaderProgram); - } - } - - - private GLWindow prepareTest() { - if(!GLProfile.isGL3Available()) { - System.err.println("GL3 not available"); - System.err.println(GLProfile.glAvailabilityToString()); - return null; - } - 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; - - 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); - - GLWindow window = GLWindow.create(caps); - Assert.assertNotNull(window); - window.setUndecorated(true); - window.setSize(800, 600); - window.setVisible(true); - Assert.assertTrue(window.isNativeValid()); - - window.getContext().setSynchronized(true); - - // trigger native creation of drawable/context - window.display(); - Assert.assertTrue(window.isRealized()); - Assert.assertTrue(window.getContext().isCreated()); - - return window; - } - - private void cleanupTest(GLWindow window) { - if(null!=window) { - window.destroy(); - } - } - - @Test(timeout=60000) - public void testGlTransformFeedbackVaryings_WhenVarNameOK() { - if(!GLProfile.isGL3Available()) { - return; - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream pbaos = new PrintStream(baos); - - GLWindow window = prepareTest(); - GLContext context = window.getContext(); - context.makeCurrent(); - - // given - - GL3 gl = context.getGL().getGL3(); - MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER); - String[] vars = new String[]{"Position"}; - - // when - - gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS); - gl.glLinkProgram(myShader.shaderProgram); - - // then - - boolean error = false; - - if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) { - System.out.println("Error (unexpected link error) - testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString()); - error = true; - } - pbaos.flush(); baos.reset(); - - Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError()); - - releaseShader(gl, myShader); - context.release(); - cleanupTest(window); - - Assert.assertFalse(error); - } - - @Test(timeout=60000) - public void testGlTransformFeedbackVaryings_WhenVarNameWrong() { - if(!GLProfile.isGL3Available()) { - return; - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream pbaos = new PrintStream(baos); - - GLWindow window = prepareTest(); - GLContext context = window.getContext(); - context.makeCurrent(); - - // given - - GL3 gl = context.getGL().getGL3(); - MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER); - String[] vars = new String[]{"PPPosition"}; - - // when - - gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS); - gl.glLinkProgram(myShader.shaderProgram); - - // then - - boolean error = false; - - if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) { - System.out.println("GOOD (expected link error) - testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString()); - // should be invalid, due to wrong var name - } else { - // oops - System.out.println("Error (unexpected link success) - testGlTransformFeedbackVaryings_WhenVarNameWrong link worked, but it should not"); - error = true; - } - 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)")); - - releaseShader(gl, myShader); - context.release(); - cleanupTest(window); - - Assert.assertFalse(error); - } - - public static void main(String args[]) throws IOException { - String tstname = TestTransformFeedbackVaryingsBug407NEWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java deleted file mode 100644 index fef0e5ad6..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java +++ /dev/null @@ -1,333 +0,0 @@ -/** - * 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 anim = new Animator(win0); - anim.start(); - - GLWindow win1 = GLWindow.create(caps); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(win1); - anim.add(win1); - runTestGL(newtCanvasAWT, win1); - - win0.destroy(); - Assert.assertEquals(true, anim.isAnimating()); - - newtCanvasAWT.destroy(); - - win0.invalidate(); - Assert.assertEquals(true, anim.isAnimating()); - win1.invalidate(); - Assert.assertEquals(false, anim.isAnimating()); - - anim.stop(); - - 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); - - Animator anim = new Animator(); - anim.start(); - - /** - * 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()); - anim.add(win0); - */ - - GLCanvas glCanvas = new GLCanvas(caps); - anim.add(glCanvas); - runTestGL(glCanvas, glCanvas); - - /** - win0.destroy(); - Assert.assertEquals(true, anim.isAnimating()); - */ - anim.stop(); - 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 deleted file mode 100644 index b09d27702..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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 deleted file mode 100644 index 5d414c708..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * 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 deleted file mode 100644 index 63215223a..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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().setGLReadDrawable(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 deleted file mode 100644 index f10a60a45..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * 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 deleted file mode 100644 index c5d770bb8..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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 deleted file mode 100644 index a57ea5777..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ /dev/null @@ -1,489 +0,0 @@ -/** - * 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.newt.Display; -import com.jogamp.newt.NewtFactory; -import com.jogamp.newt.Screen; -import com.jogamp.newt.Window; -import com.jogamp.newt.event.MouseListener; -import com.jogamp.newt.event.WindowListener; -import com.jogamp.newt.opengl.GLWindow; -import org.junit.AfterClass; -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.test.junit.util.UITestCase; -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 deleted file mode 100644 index cfe956c61..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * 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.cloneMutable(); - 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 deleted file mode 100644 index 2eb66663c..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * 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 deleted file mode 100644 index a0c0fc7f6..000000000 --- a/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * 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/TestCloseNewtAWT.java b/src/junit/com/jogamp/test/junit/newt/TestCloseNewtAWT.java deleted file mode 100644 index 1899a6b81..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestCloseNewtAWT.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * 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.Test; - -import java.lang.reflect.InvocationTargetException; -import java.awt.EventQueue; -import java.awt.Toolkit; -import javax.swing.JFrame; -import javax.swing.SwingUtilities; - -import javax.media.nativewindow.NativeWindow; -import javax.media.nativewindow.util.Point; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import com.jogamp.newt.Window; -import com.jogamp.newt.awt.NewtCanvasAWT; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.test.junit.util.UITestCase; - -public class TestCloseNewtAWT extends UITestCase { - - GLWindow newtWindow = null; - NewtCanvasAWT newtCanvas = null; - JFrame frame = null; - - class MyCanvas extends NewtCanvasAWT { - public MyCanvas(Window window) { - super(window); - } - - public void addNotify() { - System.err.println("MyCanvas START add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); - super.addNotify(); - System.err.println("MyCanvas END add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); - } - - public void removeNotify() { - System.err.println("MyCanvas START remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); - - // trigger critical situation around the AWT TreeLock - newtWindow.runOnEDTIfAvail(true, new Runnable() { - public void run() { - // NEWT EDT while AWT is locked - System.err.println("MyCanvas On NEWT-EDT From AWT-EDT: "+Thread.currentThread()+ - ", holds AWTTreeLock: "+Thread.holdsLock(MyCanvas.this.getTreeLock())); - - // Critical: Within NEWT EDT, while AWT is locked - NativeWindow nw = MyCanvas.this.getNativeWindow(); - if(null != nw) { - Point p = nw.getLocationOnScreen(null); - System.err.println("MyCanvas On NEWT-EDT: position: "+p); - } else { - System.err.println("MyCanvas On NEWT-EDT: position n/a, null NativeWindow"); - } - } - }); - System.err.println("MyCanvas passed critical: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); - - super.removeNotify(); - - System.err.println("MyCanvas END remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); - } - } - - class NEWTWindowClosingAdapter extends WindowAdapter { - public void windowDestroyNotify(WindowEvent e) { - System.err.println("Destroy NEWT: windowDestroyNotify "+Thread.currentThread() + ", "+ e); - } - } - - class AWTClosingWindowAdapter extends java.awt.event.WindowAdapter { - public void windowClosing(WindowEvent ev) { - System.err.println("Destroy AWT: windowClosing "+Thread.currentThread() + ", "+ ev); - } - } - - - @Test - public void testCloseNewtAWT() throws InterruptedException, InvocationTargetException { - newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); - newtWindow.addWindowListener(new NEWTWindowClosingAdapter()); - newtCanvas = new MyCanvas(newtWindow); - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - frame = new JFrame("NEWT Close Test"); - frame.addWindowListener(new AWTClosingWindowAdapter()); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - frame.getContentPane().add(newtCanvas); - frame.pack(); - frame.setSize(800, 600); - frame.setVisible(true); - } - }); - Thread.sleep(1000); - - // programatically issue windowClosing - Toolkit tk = Toolkit.getDefaultToolkit(); - EventQueue evtQ = tk.getSystemEventQueue(); - evtQ.postEvent(new java.awt.event.WindowEvent(frame, java.awt.event.WindowEvent.WINDOW_CLOSING)); - Thread.sleep(200); - - GLProfile.shutdown(); - } - - public static void main(String[] args) { - String tstname = TestCloseNewtAWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java deleted file mode 100644 index 94f915834..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java +++ /dev/null @@ -1,264 +0,0 @@ -/** - * 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) 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()); - - // 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.assertNotNull(window.getScreen()); - Assert.assertEquals(true,window.isValid()); - 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); - - 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()); - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - 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); - Assert.assertEquals(true,window.isNativeValid()); - Assert.assertEquals(true,window.isVisible()); - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - while(window.getDuration()<2*durationPerTest) { - window.display(); - Thread.sleep(100); - } - System.err.println("duration: "+window.getDuration()); - - // destruction .. - window.destroy(); - Assert.assertEquals(screen,window.getScreen()); - 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(true, window.isValid()); - 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); - - 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()); - System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - while(window.getDuration()<1*durationPerTest) { - window.display(); - Thread.sleep(100); - } - System.err.println("duration: "+window.getDuration()); - - // destruction .. - window.destroy(); - 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.getReferenceCount()); - Assert.assertEquals(false,screen.isNativeValid()); - - Assert.assertNotNull(window.getScreen()); - Assert.assertEquals(true,window.isValid()); - Assert.assertEquals(false,window.isNativeValid()); - Assert.assertEquals(false,window.isVisible()); - } - - @Test - public void testDisplayCreate01_AutoDestroyLifecycle() 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); - testDisplayCreate01(display, screen); - - 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.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java deleted file mode 100644 index 9fc6e3bc9..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java +++ /dev/null @@ -1,386 +0,0 @@ -/** - * 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(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); - - 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()); - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - 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); - Assert.assertEquals(true,window.isNativeValid()); - Assert.assertEquals(true,window.isVisible()); - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - while(window.getDuration()<2*durationPerTest) { - window.display(); - Thread.sleep(100); - } - System.err.println("duration: "+window.getDuration()); - - // destruction.. ref count down, but keep all - window.destroy(); - Assert.assertEquals(screen,window.getScreen()); - 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()); - Assert.assertNotNull(window.getScreen()); - Assert.assertEquals(true,window.isValid()); - 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); - - Assert.assertEquals(screen,window.getScreen()); - Assert.assertEquals(1,Display.getActiveDisplayNumber()); - Assert.assertEquals(1,display.getReferenceCount()); - Assert.assertEquals(true,window.isValid()); - 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()); - System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); - - while(window.getDuration()<1*durationPerTest) { - window.display(); - Thread.sleep(100); - } - System.err.println("duration: "+window.getDuration()); - - // destruction + invalidate, ie Display/Screen will be unreferenced - window.invalidate(); - Assert.assertNull(window.getScreen()); - Assert.assertEquals(false,window.isValid()); - 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(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); - - 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()); - System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames()); - Assert.assertTrue(0 < window1.getTotalFrames()); - - Assert.assertEquals(0, window2.getTotalFrames()); - window2.setVisible(true); - - 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()); - System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames()); - Assert.assertTrue(0 < window2.getTotalFrames()); - - 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()); - - // destruction ... - window1.destroy(); - Assert.assertNotNull(window1.getScreen()); - Assert.assertEquals(true,window1.isValid()); - 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()); - - // destruction - window2.destroy(); - Assert.assertNotNull(window2.getScreen()); - Assert.assertEquals(true,window2.isValid()); - 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()); - - // invalidate .. remove all refs - window1.invalidate(); - Assert.assertNull(window1.getScreen()); - Assert.assertEquals(false,window1.isValid()); - Assert.assertEquals(false,window1.isNativeValid()); - Assert.assertEquals(false,window1.isVisible()); - - // invalidate .. remove all refs - window2.invalidate(); - Assert.assertNull(window2.getScreen()); - Assert.assertEquals(false,window2.isValid()); - Assert.assertEquals(false,window2.isNativeValid()); - Assert.assertEquals(false,window2.isVisible()); - - } - - @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.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java b/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java deleted file mode 100644 index ff791b03a..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestEventSourceNotAWTBug.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * 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.invalidate(); - } - - 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 deleted file mode 100644 index d597af889..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * 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.AfterClass; - -import java.awt.AWTException; -import java.awt.BorderLayout; -import java.awt.Button; -import java.awt.Robot; -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.io.IOException; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.jogamp.newt.awt.NewtCanvasAWT; -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 long awtWaitTimeout = 1000; - - 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<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; } - System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); - Assert.assertTrue(glWindow1.isVisible()); - 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.invalidate(); - } - - 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 deleted file mode 100644 index b96279cac..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * 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 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 awtWaitTimeout = 1000; - 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<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; } - System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); - Assert.assertTrue(glWindow1.isVisible()); - 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.invalidate(); - } - - @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/TestGLWindows00NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows00NEWT.java deleted file mode 100644 index 2769dc550..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows00NEWT.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * 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; -import javax.media.nativewindow.AbstractGraphicsDevice; - -public class TestGLWindows00NEWT 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, GLCapabilitiesImmutable caps) - throws InterruptedException - { - Assert.assertNotNull(caps); - // - // Create native windowing resources .. X11/Win/OSX - // - GLWindow glWindow; - if(null!=screen) { - glWindow = GLWindow.create(screen, caps); - Assert.assertNotNull(glWindow); - } else { - glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - } - - GLEventListener demo = new Gears(); - glWindow.addGLEventListener(demo); - - glWindow.setSize(512, 512); - glWindow.setVisible(true); - Assert.assertEquals(true,glWindow.isVisible()); - Assert.assertEquals(true,glWindow.isNativeValid()); - - return glWindow; - } - - static void destroyWindow(GLWindow glWindow) { - if(null!=glWindow) { - glWindow.invalidate(); - Assert.assertEquals(false,glWindow.isNativeValid()); - Assert.assertEquals(false,glWindow.isValid()); - } - } - - @Test - public void testWindow00() throws InterruptedException { - GLCapabilities caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - GLWindow window1 = createWindow(null, caps); // local - Assert.assertEquals(true,window1.isNativeValid()); - Assert.assertEquals(true,window1.isVisible()); - AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); - - System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); - - for(int state=0; state*100<durationPerTest; state++) { - Thread.sleep(100); - } - - destroyWindow(window1); - } - - 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 = TestGLWindows00NEWT.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 deleted file mode 100644 index e2c65adb8..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java +++ /dev/null @@ -1,384 +0,0 @@ -/** - * 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) { - glWindow = GLWindow.create(screen, caps); - Assert.assertNotNull(glWindow); - } else { - glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - } - - 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()); - 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) - // - GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities(); - Assert.assertNotNull(caps2); - Assert.assertTrue(caps2.getGreenBits()>=5); - Assert.assertTrue(caps2.getBlueBits()>=5); - Assert.assertTrue(caps2.getRedBits()>=5); - Assert.assertEquals(caps2.isOnscreen(),onscreen); - - if(addGLEventListenerAfterVisible) { - glWindow.addGLEventListener(demo); - glWindow.display(); - } - - return glWindow; - } - - static void destroyWindow(GLWindow glWindow) { - if(null!=glWindow) { - glWindow.invalidate(); - Assert.assertEquals(false,glWindow.isNativeValid()); - Assert.assertEquals(false,glWindow.isValid()); - } - } - - @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(); - 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); - } - - @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(); - 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); - } - - @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); - } - - @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); - } - - @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); - } - - @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 */, - 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); - destroyWindow(window2); - - 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); - 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 */, - 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); - destroyWindow(window2); - - 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.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java deleted file mode 100644 index e73181604..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ /dev/null @@ -1,303 +0,0 @@ -/** - * 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.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) - // - GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities(); - Assert.assertNotNull(caps2); - Assert.assertTrue(caps2.getGreenBits()>=5); - Assert.assertTrue(caps2.getBlueBits()>=5); - Assert.assertTrue(caps2.getRedBits()>=5); - Assert.assertEquals(caps2.isOnscreen(),onscreen); - - return glWindow; - } - - static void destroyWindow(GLWindow glWindow) { - if(null!=glWindow) { - glWindow.destroy(); - } - } - - @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); - Assert.assertTrue(animator.start()); - while(animator.isAnimating() && animator.getDuration()<durationPerTest) { - Thread.sleep(100); - } - destroyWindow(window); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertTrue(animator.stop()); - } - - @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); - Assert.assertTrue(animator.start()); - while(animator.isAnimating() && animator.getDuration()<durationPerTest) { - Thread.sleep(100); - } - destroyWindow(window); - destroyWindow(window); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertTrue(animator.stop()); - } - - @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 animator = new Animator(); - Assert.assertEquals(false, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - Assert.assertTrue(animator.start()); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - animator.add(window1); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - animator.add(window2); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - while(animator.isAnimating() && animator.getDuration()<durationPerTest) { - Thread.sleep(100); - } - window1.invalidate(); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { - Thread.sleep(100); - } - window2.invalidate(); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - Assert.assertTrue(animator.stop()); - } - - @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 animator = new Animator(); - Assert.assertEquals(false, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - Assert.assertTrue(animator.start()); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - animator.add(window1); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - animator.add(window2); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - while(animator.isAnimating() && animator.getDuration()<durationPerTest) { - Thread.sleep(100); - } - destroyWindow(window1); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { - Thread.sleep(100); - } - destroyWindow(window2); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - Assert.assertEquals(true, animator.pause()); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(true, animator.isPaused()); - - Assert.assertEquals(true, animator.resume()); - Assert.assertEquals(true, animator.isStarted()); - Assert.assertEquals(true, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - - Assert.assertTrue(animator.stop()); - Assert.assertEquals(false, animator.isStarted()); - Assert.assertEquals(false, animator.isAnimating()); - Assert.assertEquals(false, animator.isPaused()); - } - - 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.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java b/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java deleted file mode 100644 index 4407ffef1..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * 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.invalidate(); - } - - 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/TestRemoteGLWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestRemoteGLWindows01NEWT.java deleted file mode 100644 index fc5327c9d..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestRemoteGLWindows01NEWT.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * 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.Assume; -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.opengl.*; -import java.io.IOException; - -import com.jogamp.test.junit.util.UITestCase; -import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; -import javax.media.nativewindow.AbstractGraphicsDevice; -import javax.media.nativewindow.NativeWindowException; - -public class TestRemoteGLWindows01NEWT 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) - throws InterruptedException - { - Assert.assertNotNull(caps); - // - // Create native windowing resources .. X11/Win/OSX - // - GLWindow glWindow; - if(null!=screen) { - glWindow = GLWindow.create(screen, caps); - Assert.assertNotNull(glWindow); - } else { - glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - } - - GLEventListener demo = new Gears(); - glWindow.addGLEventListener(demo); - - glWindow.setSize(512, 512); - glWindow.setVisible(true); - Assert.assertEquals(true,glWindow.isVisible()); - Assert.assertEquals(true,glWindow.isNativeValid()); - - return glWindow; - } - - static void destroyWindow(GLWindow glWindow) { - if(null!=glWindow) { - glWindow.invalidate(); - Assert.assertEquals(false,glWindow.isNativeValid()); - Assert.assertEquals(false,glWindow.isValid()); - } - } - - @Test - public void testRemoteWindow01() throws InterruptedException { - GLCapabilities caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - GLWindow window1 = createWindow(null, caps); // local - Assert.assertEquals(true,window1.isNativeValid()); - Assert.assertEquals(true,window1.isVisible()); - AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); - - System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); - - Animator animator1 = new Animator(window1); - animator1.start(); - - // Eager initialization of NEWT Display -> AbstractGraphicsDevice -> GLProfile (device) - Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display - try { - display2.createNative(); - } catch (NativeWindowException nwe) { - System.err.println(nwe); - Assume.assumeNoException(nwe); - destroyWindow(window1); - return; - } - AbstractGraphicsDevice device2 = display2.getGraphicsDevice(); - GLProfile.initProfiles(device2); // just to make sure - System.err.println(""); - System.err.println("GLProfiles window2: "+device2.getConnection()+": "+GLProfile.glAvailabilityToString(device2)); - - Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 - GLWindow window2 = createWindow(screen2, caps); // remote - Assert.assertEquals(true,window2.isNativeValid()); - Assert.assertEquals(true,window2.isVisible()); - - Animator animator2 = new Animator(window2); - animator2.start(); - - for(int state=0; state*100<durationPerTest; state++) { - Thread.sleep(100); - } - - destroyWindow(window1); - destroyWindow(window2); - } - - 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 = TestRemoteGLWindows01NEWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java deleted file mode 100644 index bfb012e3c..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * 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.Assume; -import org.junit.BeforeClass; -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 TestRemoteWindow01NEWT 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) - // - CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - Assert.assertNotNull(chosenCapabilities); - Assert.assertTrue(chosenCapabilities.getGreenBits()>5); - Assert.assertTrue(chosenCapabilities.getBlueBits()>5); - Assert.assertTrue(chosenCapabilities.getRedBits()>5); - Assert.assertEquals(chosenCapabilities.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 testRemoteWindow01() throws InterruptedException { - Capabilities caps = new Capabilities(); - Display display1 = NewtFactory.createDisplay(null); // local display - Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 - Window window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */); - window1.setVisible(true); - - Assert.assertEquals(true,window1.isNativeValid()); - Assert.assertEquals(true,window1.isVisible()); - - Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display - try { - display2.createNative(); - } catch (NativeWindowException nwe) { - System.err.println(nwe); - Assume.assumeNoException(nwe); - destroyWindow(display1, screen1, window1); - return; - } - Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 - Window window2 = createWindow(screen2, caps, width, height, true /* onscreen */, false /* undecorated */); - window2.setVisible(true); - - Assert.assertEquals(true,window2.isNativeValid()); - Assert.assertEquals(true,window2.isVisible()); - - Thread.sleep(500); // 500 ms - - destroyWindow(display1, screen1, window1); - destroyWindow(display2, screen2, window2); - } - - public static void main(String args[]) throws IOException { - String tstname = TestRemoteWindow01NEWT.class.getName(); - org.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java deleted file mode 100644 index 9f39274c5..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestScreenMode00NEWT.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * 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); - } else { - // no support .. - System.err.println("Your platform has no ScreenMode change support, sorry"); - } - - window.invalidate(); - - 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 deleted file mode 100644 index de4def2fa..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java +++ /dev/null @@ -1,284 +0,0 @@ -/** - * 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); - - GLWindow window = GLWindow.create(screen, caps); - window.setSize(width, height); - window.addGLEventListener(new Gears()); - Assert.assertNotNull(window); - window.setVisible(true); - return window; - } - - static void destroyWindow(Window window) { - if(null!=window) { - window.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(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 .. - System.err.println("Your platform has no ScreenMode change support, sorry"); - destroyWindow(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(window); - - Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(false,window.isNativeValid()); - Assert.assertEquals(false,screen.isNativeValid()); - Assert.assertEquals(false,display.isNativeValid()); - - screen.createNative(); // trigger native re-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); - - screen.destroy(); - - 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(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(window); - - screen.createNative(); // trigger native re-creation - - ScreenMode smCurrent = screen.getCurrentScreenMode(); - System.err.println("[1] current/orig: "+smCurrent); - - Assert.assertNotNull(smCurrent); - Assert.assertEquals(saveOrigMode, smOrig); - - screen.destroy(); - } - - 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 deleted file mode 100644 index 011af6330..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * 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); - - GLWindow window = GLWindow.create(screen, caps); - window.setSize(width, height); - window.addGLEventListener(new Gears()); - Assert.assertNotNull(window); - window.setVisible(true); - Assert.assertTrue(window.isVisible()); - return window; - } - - static void destroyWindow(Window window) { - if(null!=window) { - window.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 .. - System.err.println("Your platform has no ScreenMode change support, sorry"); - destroyWindow(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 .. - System.err.println("Your platform has no rotation support, sorry"); - destroyWindow(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(window); - - Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(false,window.isNativeValid()); - Assert.assertEquals(false,screen.isNativeValid()); - Assert.assertEquals(false,display.isNativeValid()); - - screen.createNative(); // trigger native re-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); - - screen.destroy(); - - 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 deleted file mode 100644 index 033542bea..000000000 --- a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * 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) - // - CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - Assert.assertNotNull(chosenCapabilities); - Assert.assertTrue(chosenCapabilities.getGreenBits()>5); - Assert.assertTrue(chosenCapabilities.getBlueBits()>5); - Assert.assertTrue(chosenCapabilities.getRedBits()>5); - Assert.assertEquals(chosenCapabilities.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.junit.runner.JUnitCore.main(tstname); - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java b/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java deleted file mode 100644 index 74b2ed176..000000000 --- a/src/junit/com/jogamp/test/junit/newt/WindowEventCom1.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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 deleted file mode 100644 index 551c84acb..000000000 --- a/src/junit/com/jogamp/test/junit/newt/WindowEventCom2.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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 deleted file mode 100644 index 0c097fc4f..000000000 --- a/src/junit/com/jogamp/test/junit/newt/WindowEventCom3.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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 deleted file mode 100644 index 2459c8687..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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 deleted file mode 100644 index 4948ce9f4..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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 deleted file mode 100644 index 21c0a479c..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ /dev/null @@ -1,716 +0,0 @@ -/** - * 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 long waitAbout10FramesAt30fps = 10*34; // 10 frames @ 30fps - 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(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(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); - 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()); - - glWindow1.resetCounter(); - glWindow2.resetCounter(); - Assert.assertEquals(0, glWindow1.getTotalFrames()); - Assert.assertEquals(0, glWindow2.getTotalFrames()); - glWindow1.setVisible(true); - 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()); - - Assert.assertEquals(true, animator1.pause()); - Assert.assertEquals(false, animator1.isAnimating()); - Assert.assertEquals(true, animator1.isPaused()); - Assert.assertNotNull(animator1.getThread()); - Assert.assertEquals(true, animator2.pause()); - Assert.assertEquals(false, animator2.isAnimating()); - Assert.assertEquals(true, animator2.isPaused()); - Assert.assertNotNull(animator2.getThread()); - - glWindow1.resetCounter(); - glWindow2.resetCounter(); - Assert.assertEquals(true, animator1.resume()); - Assert.assertEquals(true, animator1.isAnimating()); - Assert.assertEquals(false, animator1.isPaused()); - Assert.assertNotNull(animator1.getThread()); - Assert.assertEquals(true, animator2.resume()); - Assert.assertEquals(true, animator2.isAnimating()); - Assert.assertEquals(false, animator2.isPaused()); - Assert.assertNotNull(animator2.getThread()); - Thread.sleep(waitAbout10FramesAt30fps); - 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(1,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(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()); - - // recreation .. - glWindow1.resetCounter(); - glWindow2.resetCounter(); - Assert.assertEquals(0, glWindow1.getTotalFrames()); - Assert.assertEquals(0, glWindow2.getTotalFrames()); - glWindow1.setVisible(true); - Assert.assertEquals(true, glWindow1.isVisible()); - Assert.assertEquals(true, glWindow1.isNativeValid()); - Assert.assertEquals(true, glWindow2.isVisible()); - Assert.assertEquals(true, glWindow2.isNativeValid()); - - 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(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()); - - // chain glwindow1 -> glwindow2 ; can be recreated .. - glWindow1.destroy(); - Assert.assertEquals(true, glWindow1.isValid()); - Assert.assertEquals(false, glWindow1.isNativeValid()); - Assert.assertEquals(true, 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()); - - glWindow1.invalidate(); - Assert.assertEquals(false, glWindow1.isValid()); - Assert.assertEquals(false, glWindow2.isValid()); - - // test double destroy/invalidate .. - glWindow2.invalidate(); - 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(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(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); - 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(true, glWindow1.isVisible()); - System.err.println("Frames for setVisible(true) A1: "+glWindow1.getTotalFrames()); - Assert.assertTrue(0 < glWindow1.getTotalFrames()); - - Assert.assertEquals(0, glWindow2.getTotalFrames()); - glWindow2.setVisible(true); - - 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()); - Assert.assertEquals(true, glWindow2.isVisible()); - System.err.println("Frames for setVisible(true) B1: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow1.getTotalFrames()); - - 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); - Assert.assertEquals(true, glWindow2.isVisible()); - Assert.assertEquals(true, glWindow2.isNativeValid()); - Assert.assertSame(glWindow1,glWindow2.getParent()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); - - 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); - Assert.assertEquals(true, glWindow2.isVisible()); - Assert.assertEquals(true, glWindow2.isNativeValid()); - Assert.assertNull(glWindow2.getParent()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); - - 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++; - } - // - // both windows are now top level - // - - 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(); - Assert.assertEquals(true, glWindow1.isValid()); - Assert.assertEquals(true, glWindow1.isNativeValid()); - Assert.assertEquals(true, glWindow1.isVisible()); - Assert.assertEquals(true, glWindow2.isValid()); - Assert.assertEquals(false, glWindow2.isNativeValid()); - Assert.assertEquals(false, glWindow2.isVisible()); - - 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(); - Assert.assertEquals(true, glWindow1.isValid()); - Assert.assertEquals(false, glWindow1.isNativeValid()); - Assert.assertEquals(false, glWindow1.isVisible()); - Assert.assertEquals(true, glWindow2.isValid()); - Assert.assertEquals(false, glWindow2.isNativeValid()); - Assert.assertEquals(false, glWindow2.isVisible()); - - 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()); - - glWindow1.invalidate(); - Assert.assertEquals(false, glWindow1.isValid()); - Assert.assertEquals(true, glWindow2.isValid()); - - glWindow2.invalidate(); - Assert.assertEquals(false, glWindow2.isValid()); - } - - @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(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(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); - System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < 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.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); - Assert.assertEquals(true, glWindow2.isVisible()); - Assert.assertEquals(true, glWindow2.isNativeValid()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); - 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); - Assert.assertEquals(true, glWindow2.isVisible()); - Assert.assertEquals(true, glWindow2.isNativeValid()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); - Assert.assertSame(glWindow1,glWindow2.getParent()); - Assert.assertSame(screen1,glWindow2.getScreen()); - Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); - Assert.assertEquals(1,Display.getActiveDisplayNumber()); - break; - } - state++; - } - // - // glwindow2 is child of glwindow1 - // - - 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,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(); // should destroy both windows, actually, since glWindow2 is a child - Assert.assertEquals(true, glWindow1.isValid()); - Assert.assertEquals(false, glWindow1.isNativeValid()); - Assert.assertEquals(false, glWindow1.isVisible()); - Assert.assertEquals(true, glWindow2.isValid()); - Assert.assertEquals(false, glWindow2.isNativeValid()); - Assert.assertEquals(false, glWindow2.isVisible()); - - 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()); - - Assert.assertEquals(0,Display.getActiveDisplayNumber()); - - glWindow2.destroy(); // dbl destroy check .. - Assert.assertEquals(false, glWindow1.isNativeValid()); - Assert.assertEquals(false, glWindow2.isNativeValid()); - - glWindow1.invalidate(); // parent -> child - 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.junit.runner.JUnitCore.main(tstname); - } - -} - diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java deleted file mode 100644 index fd52c86a1..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java +++ /dev/null @@ -1,443 +0,0 @@ -/** - * 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.invalidate(); - //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.invalidate(); - } - - @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(); - Assert.assertEquals(true, animator1.isStarted()); - Assert.assertEquals(true, animator1.isAnimating()); - while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { - Thread.sleep(100); - } - - Assert.assertEquals(true, animator1.isAnimating()); // !!! - - frame.dispose(); - glWindow1.invalidate(); - } - - @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.invalidate(); - } - - @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.invalidate(); - } - - @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.invalidate(); - } - - 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 deleted file mode 100644 index 89cefa8b1..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * 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.invalidate(); - } - - 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 deleted file mode 100644 index b79f4c57c..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java +++ /dev/null @@ -1,243 +0,0 @@ -/** - * 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.invalidate(); - //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.invalidate(); - } - - 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 deleted file mode 100644 index fb2c74455..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ /dev/null @@ -1,365 +0,0 @@ -/** - * 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 org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.awt.Button; -import java.awt.BorderLayout; -import java.awt.Container; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -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 com.jogamp.newt.awt.NewtCanvasAWT; - -import java.io.IOException; - -import com.jogamp.test.junit.util.*; -import com.jogamp.test.junit.jogl.demos.es1.RedSquare; - -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.invalidate(); - //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.invalidate(); - //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 deleted file mode 100644 index 6c9e5b2b2..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * 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.invalidate(); - 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 deleted file mode 100644 index 23e3e1c44..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * 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); - CapabilitiesImmutable 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 deleted file mode 100644 index 00a78a14f..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03AWT.java +++ /dev/null @@ -1,203 +0,0 @@ -/** - * 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 to home"); - f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow()); - } else { - System.err.println("XXX glWin1 to 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.invalidate(); - } - - 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 deleted file mode 100644 index 5f42d9f7e..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting03bAWT.java +++ /dev/null @@ -1,258 +0,0 @@ -/** - * 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 to home"); - f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow()); - } else { - System.err.println("XXX glWin1 to 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 to home"); - f_glWindow2.reparentWindow(f_newtCanvasAWT2.getNativeWindow()); - } else { - System.err.println("XXX glWin2 to 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.invalidate(); - glWindow2.invalidate(); - } - - 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 deleted file mode 100644 index bcfb29440..000000000 --- a/src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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 deleted file mode 100644 index 174152639..000000000 --- a/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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 deleted file mode 100644 index 8e255acb6..000000000 --- a/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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 deleted file mode 100644 index d78b3ed61..000000000 --- a/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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 deleted file mode 100644 index c49de3e1f..000000000 --- a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java +++ /dev/null @@ -1,338 +0,0 @@ -/** - * 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/DumpGLInfo.java b/src/junit/com/jogamp/test/junit/util/DumpGLInfo.java deleted file mode 100644 index fd7844f67..000000000 --- a/src/junit/com/jogamp/test/junit/util/DumpGLInfo.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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 javax.media.opengl.*; -import com.jogamp.opengl.JoglVersion; - - -public class DumpGLInfo implements GLEventListener { - - public void init(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - System.err.println(JoglVersion.getInstance().getGLInfo(gl, null)); - } - - 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 deleted file mode 100644 index e0561218a..000000000 --- a/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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 deleted file mode 100644 index 40b192a01..000000000 --- a/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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/GLSLSimpleProgram.java b/src/junit/com/jogamp/test/junit/util/GLSLSimpleProgram.java deleted file mode 100644 index 82be0eb45..000000000 --- a/src/junit/com/jogamp/test/junit/util/GLSLSimpleProgram.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * 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.glsl.ShaderUtil; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import org.junit.Assert; - -public class GLSLSimpleProgram { - private int shaderProgram; - private int vertShader; - private int fragShader; - - private GLSLSimpleProgram(int shaderProgram, int vertShader, int fragShader) { - this.shaderProgram = shaderProgram; - this.vertShader = vertShader; - this.fragShader = fragShader; - } - - public static GLSLSimpleProgram create(GL2ES2 gl, String vertShaderCode, String fragShaderCode, boolean link) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream pbaos = new PrintStream(baos); - - int vertShader = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - int fragShader = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - String[] vlines = new String[] { vertShaderCode }; - int[] vlengths = new int[] { vlines[0].length() }; - gl.glShaderSource(vertShader, vlines.length, vlines, vlengths, 0); - gl.glCompileShader(vertShader); - if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) { - System.out.println("getShader:postCompile vertShader: "+baos.toString()); - Assert.assertTrue(false); - } - pbaos.flush(); baos.reset(); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - - String[] flines = new String[] { fragShaderCode }; - int[] flengths = new int[] { flines[0].length() }; - gl.glShaderSource(fragShader, flines.length, flines, flengths, 0); - gl.glCompileShader(fragShader); - if(!ShaderUtil.isShaderStatusValid(gl, fragShader, gl.GL_COMPILE_STATUS, pbaos)) { - System.out.println("getShader:postCompile fragShader: "+baos.toString()); - Assert.assertTrue(false); - } - pbaos.flush(); baos.reset(); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - int shaderProgram = gl.glCreateProgram(); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glAttachShader(shaderProgram, vertShader); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glAttachShader(shaderProgram, fragShader); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - if(link) { - gl.glLinkProgram(shaderProgram); - if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) { - System.out.println("Error (GLSL link error): "+baos.toString()); - Assert.assertTrue(false); - } - } - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - GLSLSimpleProgram res = new GLSLSimpleProgram(shaderProgram, vertShader, fragShader); - return res; - } - - public void release(GL2ES2 gl) { - gl.glUseProgram(0); - gl.glDetachShader(shaderProgram, vertShader); - gl.glDeleteShader(vertShader); - gl.glDetachShader(shaderProgram, fragShader); - gl.glDeleteShader(fragShader); - gl.glDeleteProgram(shaderProgram); - } - - public int getFragShader() { - return fragShader; - } - - public int getShaderProgram() { - return shaderProgram; - } - - public int getVertShader() { - return vertShader; - } -} diff --git a/src/junit/com/jogamp/test/junit/util/MiscUtils.java b/src/junit/com/jogamp/test/junit/util/MiscUtils.java deleted file mode 100644 index bb2abcd87..000000000 --- a/src/junit/com/jogamp/test/junit/util/MiscUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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 { - public static int atoi(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 deleted file mode 100644 index 5cbd9fd15..000000000 --- a/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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 deleted file mode 100644 index 73caa1846..000000000 --- a/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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 deleted file mode 100644 index fc5c653f2..000000000 --- a/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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 deleted file mode 100644 index 174412295..000000000 --- a/src/junit/com/jogamp/test/junit/util/QuitAdapter.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.*; - -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 deleted file mode 100644 index 997742cf6..000000000 --- a/src/junit/com/jogamp/test/junit/util/SingletonInstance.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * 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 deleted file mode 100644 index 8baa716b7..000000000 --- a/src/junit/com/jogamp/test/junit/util/UITestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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; - - -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()); - } - -} - |