From f8b21903cf0db85fdc16c8e1892003702a05a33f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 25 Oct 2013 00:01:34 +0200 Subject: Use org.junit.Assert instead of deprecated junit.framework.Assert --- .../test/junit/jogl/acore/TestBug692GL3VAO.java | 105 ++++++++-------- .../opengl/test/junit/jogl/awt/TestBug572AWT.java | 51 ++++---- .../jogl/awt/TestBug675BeansInDesignTimeAWT.java | 33 +++-- .../junit/jogl/caps/TestBug605FlippedImageAWT.java | 83 +++++++------ .../jogl/caps/TestBug605FlippedImageNEWT.java | 87 +++++++------ .../TestNewtCanvasSWTBug628ResizeDeadlockAWT.java | 136 ++++++++++----------- .../junit/jogl/swt/TestSWTBug643AsyncExec.java | 109 +++++++++-------- 7 files changed, 300 insertions(+), 304 deletions(-) (limited to 'src/test/com/jogamp/opengl') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java index 55328f1e6..29b48fecd 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java @@ -41,8 +41,7 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -67,7 +66,7 @@ import com.jogamp.opengl.util.GLBuffers; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestBug692GL3VAO extends UITestCase { static long duration = 500; // ms - + static class GL3VAODemo implements GLEventListener { /** Different modes of displaying the geometry */ public enum Mode { @@ -78,7 +77,7 @@ public class TestBug692GL3VAO extends UITestCase { t.displayNonVAO(gl); } }, - + /** Using VAOs throws [incorrectly as of JOGL 2.0rc11] a GLException */ VAO_NORMAL { @Override @@ -86,34 +85,34 @@ public class TestBug692GL3VAO extends UITestCase { t.displayVAONormal(gl); } }; - + abstract void display(GL3VAODemo t, GL3 gl); } - + private final Mode[] allModes; private Mode currentMode; - private int currentModeIdx; - + private int currentModeIdx; + public GL3VAODemo(Mode[] modes) { allModes = modes; currentMode = allModes[0]; currentModeIdx = 0; } - + private final static float[] vertexData = new float[]{ 0.0f, 0.75f, 0.0f, 1,0,0, -0.5f, -0.75f, 0.0f, 0,1,0, 0.9f, -0.75f, 0.0f, 0,0,1 }; - + private int ibo = -1; private int vbo = -1; private int vertID = -1; private int fragID = -1; private int progID = -1; - + private int vaoNormal = -1; - + private static int createShader(final GL3 gl, int type, final String[] srcLines){ int shaderID = gl.glCreateShader(type); @@ -126,14 +125,14 @@ public class TestBug692GL3VAO extends UITestCase { gl.glCompileShader(shaderID); return shaderID; } - + private void initBuffers(GL3 gl) { // IDs for 2 buffers int[] buffArray = new int[2]; gl.glGenBuffers(buffArray.length, buffArray, 0); vbo = buffArray[0]; assert vbo > 0; - + // Bind buffer and upload data gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo); FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(vertexData); @@ -141,7 +140,7 @@ public class TestBug692GL3VAO extends UITestCase { gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertexData.length * Buffers.SIZEOF_FLOAT, buffer, GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0); - + // Buffer with the 3 indices required for one triangle ibo = buffArray[1]; assert ibo > 0; @@ -165,7 +164,7 @@ public class TestBug692GL3VAO extends UITestCase { "}\n" }; vertID = createShader(gl, GL3.GL_VERTEX_SHADER, vertSrc); - + final String[] fragSrc = new String[]{ "#version 150\n", "in vec4 pColor;\n", @@ -174,10 +173,10 @@ public class TestBug692GL3VAO extends UITestCase { "}\n" }; fragID = createShader(gl, GL3.GL_FRAGMENT_SHADER, fragSrc); - + // We're done with the compiler gl.glReleaseShaderCompiler(); - + progID = gl.glCreateProgram(); assert progID > 0; gl.glAttachShader(progID, vertID); @@ -185,50 +184,50 @@ public class TestBug692GL3VAO extends UITestCase { gl.glLinkProgram(progID); gl.glValidateProgram(progID); } - + private int initVAO(GL3 gl) { int[] buff = new int[1]; gl.glGenVertexArrays(1, buff, 0); int vao = buff[0]; Assert.assertTrue("Invalid VAO: "+vao, vao > 0); - - + + gl.glUseProgram(progID); final int posLoc = gl.glGetAttribLocation(progID, "vPosition"); final int colorLoc = gl.glGetAttribLocation(progID, "vColor"); gl.glUseProgram(0); - + gl.glBindVertexArray(vao); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo); gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo); - + gl.glEnableVertexAttribArray(posLoc); gl.glEnableVertexAttribArray(colorLoc); - + final int stride = 6 * Buffers.SIZEOF_FLOAT; final int cOff = 3 * Buffers.SIZEOF_FLOAT; gl.glVertexAttribPointer(posLoc, 3, GL3.GL_FLOAT, false, stride, 0L); gl.glVertexAttribPointer(colorLoc,3, GL3.GL_FLOAT, false, stride, cOff); - + gl.glBindVertexArray(0); return vao; } - + @Override public void init(GLAutoDrawable drawable) { drawable.setGL(new DebugGL3(drawable.getGL().getGL3())); - + final GL3 gl = drawable.getGL().getGL3(); gl.glEnable(GL3.GL_DEPTH_TEST); gl.glDisable(GL3.GL_CULL_FACE); initBuffers(gl); initShaders(gl); - + vaoNormal = initVAO(gl); - + gl.setSwapInterval(1); } - + @Override public void dispose(GLAutoDrawable drawable) { final GL3 gl = drawable.getGL().getGL3(); @@ -239,13 +238,13 @@ public class TestBug692GL3VAO extends UITestCase { gl.glDeleteShader(fragID); gl.glDeleteShader(vertID); } - + private void displayNonVAO(final GL3 gl) { final int posLoc = gl.glGetAttribLocation(progID, "vPosition"); final int colorLoc = gl.glGetAttribLocation(progID, "vColor"); gl.glEnableVertexAttribArray(posLoc); gl.glEnableVertexAttribArray(colorLoc); - + gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo); final int stride = 6 * Buffers.SIZEOF_FLOAT; final int cOff = 3 * Buffers.SIZEOF_FLOAT; @@ -253,13 +252,13 @@ public class TestBug692GL3VAO extends UITestCase { gl.glVertexAttribPointer(colorLoc,3, GL3.GL_FLOAT, false, stride, cOff); gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo); gl.glDrawElements(GL3.GL_TRIANGLES, 3, GL3.GL_UNSIGNED_SHORT, 0L); - + gl.glDisableVertexAttribArray(posLoc); gl.glDisableVertexAttribArray(colorLoc); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0); gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, 0); } - + private void displayVAONormal(final GL3 gl) { try { gl.glBindVertexArray(vaoNormal); @@ -269,7 +268,7 @@ public class TestBug692GL3VAO extends UITestCase { Logger.getLogger(TestBug692GL3VAO.class.getName()).log(Level.SEVERE,null,ex); } } - + @Override public void display(GLAutoDrawable drawable) { final GL3 gl = drawable.getGL().getGL3(); @@ -279,7 +278,7 @@ public class TestBug692GL3VAO extends UITestCase { gl.glUseProgram(progID); final Mode newMode; { - currentModeIdx = ( currentModeIdx + 1 ) % allModes.length; + currentModeIdx = ( currentModeIdx + 1 ) % allModes.length; newMode = allModes[ currentModeIdx ]; } if (newMode != currentMode) { @@ -289,59 +288,59 @@ public class TestBug692GL3VAO extends UITestCase { currentMode.display(this, gl); gl.glUseProgram(0); } - + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { - } + } } - + private void testImpl(GLProfile profile, GL3VAODemo.Mode[] modes) throws InterruptedException { final GLCapabilities capabilities = new GLCapabilities(profile); final GLWindow glWindow = GLWindow.create(capabilities); glWindow.setSize(512, 512); - + Animator anim = new Animator(glWindow); - + QuitAdapter quitAdapter = new QuitAdapter(); glWindow.addKeyListener(quitAdapter); glWindow.addWindowListener(quitAdapter); - + final GL3VAODemo vaoTest = new GL3VAODemo(modes); glWindow.addGLEventListener(vaoTest); glWindow.setVisible(true); anim.start(); - + final long t0 = System.currentTimeMillis(); long t1 = t0; while(!quitAdapter.shouldQuit() && t1-t00); Assert.assertTrue("GLCanvas didn't display", snapshooter.getDisplayCount()>0); - + Thread.sleep(durationPerTest); - + // After initial 'setVisible(true)' all AWT manipulation needs to be done // via the AWT EDT, according to the AWT spec. // AWT / Swing on EDT.. SwingUtilities.invokeAndWait(new Cleanup(window)); } - + @Test(timeout = 10000) // 10s timeout public void test01RealizeGLCanvasOnAWTEDTUseFrameSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(true, true); @@ -154,7 +153,7 @@ public class TestBug572AWT extends UITestCase { public void test02RealizeGLCanvasOnAWTEDTUseGLCanvasSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(true, false); } - + @Test(timeout = 10000) // 10s timeout public void test11RealizeGLCanvasOnMainTUseFrameSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(false, true); @@ -164,7 +163,7 @@ public class TestBug572AWT extends UITestCase { public void test12RealizeGLCanvasOnMainTUseGLCanvasSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(false, false); } - + public static void main(String args[]) { org.junit.runner.JUnitCore.main(TestBug572AWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java index 05f0c1ce3..3363fdd52 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.awt; import java.awt.BorderLayout; @@ -40,8 +40,7 @@ import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -54,24 +53,24 @@ import com.jogamp.opengl.test.junit.util.UITestCase; public class TestBug675BeansInDesignTimeAWT extends UITestCase { static boolean waitForKey = false; static long durationPerTest = 200; - + @Test public void test01() throws InterruptedException, InvocationTargetException { Beans.setDesignTime(true); - - final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); + + final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); final GLCanvas glCanvas = new GLCanvas(caps); final Dimension preferredGLSize = new Dimension(400,200); glCanvas.setPreferredSize(preferredGLSize); glCanvas.setMinimumSize(preferredGLSize); glCanvas.setSize(preferredGLSize); - + glCanvas.addGLEventListener(new GearsES2()); final Window window = new JFrame(this.getSimpleTestName(" - ")); window.setLayout(new BorderLayout()); window.add(glCanvas, BorderLayout.CENTER); - + // trigger realization on AWT-EDT, otherwise it won't immediatly .. SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -79,22 +78,22 @@ public class TestBug675BeansInDesignTimeAWT extends UITestCase { window.pack(); window.validate(); window.setVisible(true); - } + } } ); - + // Immediately displayable after issuing initial setVisible(true) on AWT-EDT! Assert.assertTrue("GLCanvas didn't become displayable", glCanvas.isDisplayable()); if( !Beans.isDesignTime() ) { Assert.assertTrue("GLCanvas didn't become realized", glCanvas.isRealized()); } - + Thread.sleep(durationPerTest); - + SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { window.dispose(); - } + } } ); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java index 0b317eb84..89470a922 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -45,8 +45,7 @@ import com.jogamp.opengl.util.texture.TextureIO; import java.awt.image.BufferedImage; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -58,19 +57,19 @@ public class TestBug605FlippedImageAWT extends UITestCase { class FlippedImageTest implements GLEventListener { public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); - + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT | GL2.GL_ACCUM_BUFFER_BIT ); - + gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); - + // red below gl.glColor3f(1, 0, 0); gl.glRectf(-1, -1, 1, 0); - + // green above gl.glColor3f(0, 1, 0); gl.glRectf(-1, 0, 1, 1); @@ -80,12 +79,12 @@ public class TestBug605FlippedImageAWT extends UITestCase { if(caps.getAccumGreenBits() > 0) { gl.glAccum(GL2.GL_ACCUM, 1.0f); gl.glAccum(GL2.GL_RETURN, 1.0f); - } + } gl.glFinish(); - + final int width = drawable.getWidth(); final int height = drawable.getHeight(); - + final String fname = getSnapshotFilename(0, null, caps, width, height, false, TextureIO.PNG, null); try { Screenshot.writeToFile(new File(fname), width, height, false); @@ -93,83 +92,83 @@ public class TestBug605FlippedImageAWT extends UITestCase { throw e; } catch (IOException e) { throw new GLException(e); - } + } testFlipped(width, height); } - + public void init(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println("GL_RENDERER: "+gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: "+gl.glGetString(GL.GL_VERSION)); - } - public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + } + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public void dispose(GLAutoDrawable drawable) {} } - + static final int green = 0x0000ff00; // above static final int red = 0x00ff0000; // below private void testFlipped(int width, int height) { // Default origin 0/0 is lower left corner, so is the memory layout - // However AWT origin 0/0 is upper left corner + // However AWT origin 0/0 is upper left corner final BufferedImage image = Screenshot.readToBufferedImage(width, height); - + final int below = image.getRGB(0, height-1) & 0x00ffffff; System.err.println("below: 0x"+Integer.toHexString(below)); - + final int above = image.getRGB(0, 0) & 0x00ffffff; System.err.println("above: 0x"+Integer.toHexString(above)); - + if (above == green && below == red) { System.out.println("Image right side up"); } else if (above == red && below == green) { Assert.assertTrue("Image is flipped", false); } else { Assert.assertTrue("Error in test", false); - } + } } - + private void test(GLCapabilitiesImmutable caps) { - + final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(caps.getGLProfile()); final GLAutoDrawable glad = glFactory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null); final FlippedImageTest tglel = new FlippedImageTest(); glad.addGLEventListener(tglel); - + // 1 frame incl. snapshot to memory & file glad.display(); System.err.println("XXX "+glad.getChosenGLCapabilities()); System.err.println("XXX "+glad.getContext().getGLVersion()); - - glad.destroy(); + + glad.destroy(); } - + @Test public void test01DefaultFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01StencilFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); caps.setStencilBits(8); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01DefaultPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + @Test public void test01AccumStencilPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); @@ -178,10 +177,10 @@ public class TestBug605FlippedImageAWT extends UITestCase { caps.setAccumGreenBits(16); caps.setAccumBlueBits(16); caps.setStencilBits(8); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + public static void main(String[] args) { org.junit.runner.JUnitCore.main(TestBug605FlippedImageAWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java index 4fc681a74..8d4710ad3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -38,8 +38,7 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -52,71 +51,71 @@ public class TestBug605FlippedImageNEWT extends UITestCase { static class FlippedImageTest implements GLEventListener { public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); - + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT | GL2.GL_ACCUM_BUFFER_BIT ); - + gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); - + // red below gl.glColor3f(1, 0, 0); gl.glRectf(-1, -1, 1, 0); - + // green above gl.glColor3f(0, 1, 0); gl.glRectf(-1, 0, 1, 1); gl.glFinish(); - + final GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities(); if(caps.getAccumGreenBits() > 0) { gl.glAccum(GL2.GL_ACCUM, 1.0f); gl.glAccum(GL2.GL_RETURN, 1.0f); - } + } gl.glFinish(); } - + public void init(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println("GL_RENDERER: "+gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: "+gl.glGetString(GL.GL_VERSION)); - } - public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + } + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public void dispose(GLAutoDrawable drawable) {} } - + static final int green = 0x0000ff00; // above static final int red = 0x00ff0000; // below private int getRGB(ByteBuffer bb, int o) { - return ( (int)bb.get(o+0) & 0x000000ff ) << 16 | - ( (int)bb.get(o+1) & 0x000000ff ) << 8 | - ( (int)bb.get(o+2) & 0x000000ff ); + return ( bb.get(o+0) & 0x000000ff ) << 16 | + ( bb.get(o+1) & 0x000000ff ) << 8 | + ( bb.get(o+2) & 0x000000ff ); } - + private void testFlipped(ByteBuffer bb, int width, int height, int comp) { // Default origin 0/0 is lower left corner, so is the memory layout - + // x=0, y=0: RGB -> _RGB [high-byte .. low-byte] final int below = getRGB(bb, 0); System.err.println("below: 0x"+Integer.toHexString(below)); - + // x=0, y=height-1: RGB -> _RGB [high-byte .. low-byte] final int above= getRGB(bb, ( height - 1 ) * ( width * comp )); System.err.println("above: 0x"+Integer.toHexString(above)); - + if (above == green && below == red) { System.out.println("Image right side up"); } else if (above == red && below == green) { Assert.assertTrue("Image is flipped", false); } else { Assert.assertTrue("Error in test", false); - } + } } - + private void test(GLCapabilitiesImmutable caps) { final GLReadBufferUtil rbu = new GLReadBufferUtil(false, false); final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(caps.getGLProfile()); @@ -125,42 +124,42 @@ public class TestBug605FlippedImageNEWT extends UITestCase { glad.addGLEventListener(tglel); final SnapshotGLEventListener snap = new SnapshotGLEventListener(rbu); glad.addGLEventListener(snap); - snap.setMakeSnapshotAlways(true); - + snap.setMakeSnapshotAlways(true); + // 1 frame incl. snapshot to memory & file glad.display(); System.err.println("XXX "+glad.getChosenGLCapabilities()); System.err.println("XXX "+glad.getContext().getGLVersion()); - testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getWidth(), glad.getHeight(), 3); - - glad.destroy(); + testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getWidth(), glad.getHeight(), 3); + + glad.destroy(); } - + @Test public void test01DefaultFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01StencilFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); caps.setStencilBits(8); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01DefaultPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + @Test public void test01AccumStencilPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); @@ -169,10 +168,10 @@ public class TestBug605FlippedImageNEWT extends UITestCase { caps.setAccumGreenBits(16); caps.setAccumBlueBits(16); caps.setStencilBits(8); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + public static void main(String[] args) { org.junit.runner.JUnitCore.main(TestBug605FlippedImageNEWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java index dcb041147..87d4dafd6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -39,6 +39,8 @@ 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.Test; import org.junit.FixMethodOrder; @@ -51,8 +53,6 @@ import javax.media.opengl.GLCapabilities ; import javax.media.opengl.GLEventListener ; import javax.media.opengl.GLProfile; -import junit.framework.Assert; - import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.event.KeyAdapter; @@ -68,63 +68,63 @@ import com.jogamp.opengl.test.junit.util.UITestCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { - + static int duration = 500; - + static class BigFlashingX implements GLEventListener - { + { float r = 0f, g = 0f, b = 0f; - + public void init( GLAutoDrawable drawable ) { GL2 gl = drawable.getGL().getGL2() ; - + gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) ; - + gl.glEnable( GL.GL_LINE_SMOOTH ) ; gl.glEnable( GL.GL_BLEND ) ; gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ) ; } - + public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) { - // System.err.println( ">>>>>>>> reshape " + x + ", " + y + ", " + width + ", " +height ) ; + // System.err.println( ">>>>>>>> reshape " + x + ", " + y + ", " + width + ", " +height ) ; GL2 gl = drawable.getGL().getGL2() ; - + gl.glViewport( 0, 0, width, height ) ; - + gl.glMatrixMode( GL2.GL_PROJECTION ) ; gl.glLoadIdentity() ; gl.glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ; - + gl.glMatrixMode( GL2.GL_MODELVIEW ) ; gl.glLoadIdentity() ; } - + public void display( GLAutoDrawable drawable ) { - // System.err.println( ">>>> display" ) ; + // System.err.println( ">>>> display" ) ; GL2 gl = drawable.getGL().getGL2() ; - + // Sven: I could have been seeing things, but it seemed that if this // glClear is in here twice it seems aggravates the problem. Not // sure why other than it just takes longer, but this is pretty // fast operation. gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT ) ; gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT ) ; - + gl.glColor4f( r, g, b, 1.0f ) ; - + gl.glBegin( GL.GL_LINES ) ; { gl.glVertex2f( -1.0f, 1.0f ) ; gl.glVertex2f( 1.0f, -1.0f ) ; - + gl.glVertex2f( -1.0f, -1.0f ) ; gl.glVertex2f( 1.0f, 1.0f ) ; } gl.glEnd() ; - + if(r<1f) { r+=0.1f; } else if(g<1f) { @@ -137,25 +137,25 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { b = 0f; } } - + public void dispose( GLAutoDrawable drawable ) { } } - + //////////////////////////////////////////////////////////////////////////////// - + static class ResizeThread extends Thread { volatile boolean shallStop = false; - private Shell _shell ; + private final Shell _shell ; private int _n ; - + public ResizeThread( Shell shell ) { super(); _shell = shell ; } - + final Runnable resizeAction = new Runnable() { public void run() { @@ -172,10 +172,10 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { } catch (Exception e0) { e0.printStackTrace(); Assert.assertTrue("Deadlock @ setSize: "+e0, false); - } + } ++_n ; } }; - + public void run() { // The problem was originally observed by grabbing the lower right @@ -185,11 +185,11 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { // // This loop simulates rapid resizing by the user by toggling // the shell back-and-forth between two sizes. - + System.err.println("[R-0 shallStop "+shallStop+", disposed "+_shell.isDisposed()+"]"); - + final Display display = _shell.getDisplay(); - + while( !shallStop && !_shell.isDisposed() ) { try @@ -197,8 +197,8 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("[R-n shallStop "+shallStop+", disposed "+_shell.isDisposed()+"]"); display.asyncExec( resizeAction ); display.wake(); - - Thread.sleep( 50L ) ; + + Thread.sleep( 50L ) ; } catch( InterruptedException e ) { break ; } @@ -206,26 +206,26 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("*R-Exit* shallStop "+shallStop+", disposed "+_shell.isDisposed()); } } - + //////////////////////////////////////////////////////////////////////////////// - + static class KeyfireThread extends Thread { volatile boolean shallStop = false; Display _display; Robot _robot; int _n = 0; - + public KeyfireThread(Robot robot, Display display) { _robot = robot; _display = display; } - + public void run() { System.err.println("[K-0]"); - + while( !shallStop ) { try { @@ -245,26 +245,26 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("*K-Exit*"); } } - + //////////////////////////////////////////////////////////////////////////////// - + private volatile boolean shallStop = false; - + static class SWT_DSC { volatile Display display; volatile Shell shell; volatile Composite composite; volatile com.jogamp.newt.Display swtNewtDisplay = null; - + public void init() { SWTAccessor.invoke(true, new Runnable() { - public void run() { + public void run() { display = new Display(); Assert.assertNotNull( display ); }}); - + display.syncExec(new Runnable() { - public void run() { + public void run() { shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new FillLayout() ); @@ -274,7 +274,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { }}); swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } - + public void dispose() { Assert.assertNotNull( display ); Assert.assertNotNull( shell ); @@ -297,17 +297,17 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { swtNewtDisplay = null; display = null; shell = null; - composite = null; + composite = null; } } - + @Test public void test() throws InterruptedException, AWTException, InvocationTargetException { final Robot robot = new Robot(); - + final SWT_DSC dsc = new SWT_DSC(); dsc.init(); - + final GLWindow glWindow; { final GLProfile gl2Profile = GLProfile.get( GLProfile.GL2 ) ; @@ -320,38 +320,38 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { public void keyReleased(com.jogamp.newt.event.KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; - } + } System.err.print("."); - glWindow.display(); - } + glWindow.display(); + } }); NewtCanvasSWT.create( dsc.composite, 0, glWindow ) ; } - + dsc.display.syncExec( new Runnable() { public void run() { dsc.shell.setText( "NewtCanvasSWT Resize Bug Demo" ) ; dsc.shell.setSize( 400, 450 ) ; dsc.shell.open() ; } } ); - + AWTRobotUtil.requestFocus(robot, glWindow, false); AWTRobotUtil.setMouseToClientLocation(robot, glWindow, 50, 50); shallStop = false; - + final ResizeThread resizer; { resizer = new ResizeThread( dsc.shell ) ; resizer.start() ; } - + final KeyfireThread keyfire; { keyfire = new KeyfireThread( robot, dsc.display ) ; keyfire.start() ; } - + { final Thread t = new Thread(new Runnable() { @Override @@ -377,7 +377,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { t.setDaemon(true); t.start(); } - + try { while( !shallStop && !dsc.display.isDisposed() ) { dsc.display.syncExec( new Runnable() { @@ -394,12 +394,12 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { e0.printStackTrace(); Assert.assertTrue("Deadlock @ dispatch: "+e0, false); } - + // canvas is disposed implicit, due to it's disposed listener ! - + dsc.dispose(); } - + public static void main( String[] args ) { for(int i=0; i