diff options
Diffstat (limited to 'src/test')
3 files changed, 439 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java new file mode 100644 index 000000000..655e590a3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java @@ -0,0 +1,71 @@ +/**
+ * 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.opengl.test.junit.jogl.swt;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.glu.GLU;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * A utility class to encapsulate drawing a single triangle for unit tests.
+ * @author Wade Walker
+ */
+public class OneTriangle {
+
+ public static void setup( GL2 gl, Rectangle rectangle ) {
+ gl.glMatrixMode( GL2.GL_PROJECTION );
+ gl.glLoadIdentity();
+
+ // coordinate system origin at lower left with width and height same as the window
+ GLU glu = new GLU();
+ glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );
+
+ gl.glMatrixMode( GL2.GL_MODELVIEW );
+ gl.glLoadIdentity();
+
+ gl.glViewport( 0, 0, rectangle.width, rectangle.height );
+ }
+
+ public static void render( GL2 gl, Rectangle rectangle ) {
+ gl.glClear( GL.GL_COLOR_BUFFER_BIT );
+
+ // draw a triangle filling the window
+ gl.glLoadIdentity();
+ gl.glBegin( GL.GL_TRIANGLES );
+ gl.glColor3f( 1, 0, 0 );
+ gl.glVertex2f( 0, 0 );
+ gl.glColor3f( 0, 1, 0 );
+ gl.glVertex2f( rectangle.width, 0 );
+ gl.glColor3f( 0, 0, 1 );
+ gl.glVertex2f( rectangle.width / 2, rectangle.height );
+ gl.glEnd();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java new file mode 100644 index 000000000..94231a88d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java @@ -0,0 +1,184 @@ +/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.swt;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.opengl.GLCanvas;
+import org.eclipse.swt.opengl.GLData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the SWT GL canvas.
+ * @author Wade Walker
+ */
+public class TestSWT01GLn extends UITestCase {
+
+ static final int duration = 250;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+ GLCanvas glcanvas = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.NONE );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ Assert.assertNotNull( glcanvas );
+ try {
+ glcanvas.dispose();
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ glcanvas = null;
+ }
+
+ protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ GLData gldata = new GLData();
+ gldata.doubleBuffer = true;
+ // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
+ // at the wrong times (we use glClear for this instead)
+ glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
+ Assert.assertNotNull( glcanvas );
+ glcanvas.setCurrent();
+ final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
+ Assert.assertNotNull( glcontext );
+
+ // fix the viewport when the user resizes the window
+ glcanvas.addListener( SWT.Resize, new Listener() {
+ public void handleEvent( Event event ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ glcontext.release();
+ }
+ });
+
+ // draw the triangle when the OS tells us that any part of the window needs drawing
+ glcanvas.addPaintListener( new PaintListener() {
+ public void paintControl( PaintEvent paintevent ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ glcanvas.swapBuffers();
+ glcontext.release();
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestSWT01GLn.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java new file mode 100644 index 000000000..2ab3c96ad --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java @@ -0,0 +1,184 @@ +/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.swt;
+
+import java.awt.Frame;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the AWT GL canvas with
+ * the SWT_AWT bridge.
+ * @author Wade Walker
+ */
+public class TestSWTAWT01GLn extends UITestCase {
+
+ static final int duration = 250;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+ Frame frame = null;
+ GLCanvas glcanvas = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ frame = SWT_AWT.new_Frame( composite );
+ Assert.assertNotNull( frame );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ Assert.assertNotNull( glcanvas );
+ try {
+ frame.setVisible( false );
+ frame.remove( glcanvas );
+ frame.dispose();
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ frame = null;
+ glcanvas = null;
+ }
+
+ protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ GLCapabilities glcapabilities = new GLCapabilities( glprofile );
+ glcanvas = new GLCanvas( glcapabilities );
+ Assert.assertNotNull( glcanvas );
+ frame.add( glcanvas );
+
+ glcanvas.addGLEventListener( new GLEventListener() {
+ @Override
+ public void init( GLAutoDrawable glautodrawable ) {
+ }
+
+ @Override
+ public void dispose( GLAutoDrawable glautodrawable ) {
+ }
+
+ @Override
+ public void display( GLAutoDrawable glautodrawable ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ }
+
+ @Override
+ public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main( TestSWTAWT01GLn.class.getName() );
+ }
+}
|