summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java220
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java189
2 files changed, 409 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java
new file mode 100644
index 000000000..c6e78b219
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java
@@ -0,0 +1,220 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.io.IOException;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDebugListener;
+import javax.media.opengl.GLDebugMessage;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestGLDebug00NEWT extends UITestCase {
+
+ static String dbgTstMsg0 = "Hello World";
+ static int dbgTstId0 = 42;
+
+ public class WindowContext {
+ public final Window window;
+ public final GLContext context;
+
+ public WindowContext(Window w, GLContext c) {
+ window = w;
+ context = c;
+ }
+ }
+
+ WindowContext createWindow(GLProfile glp, boolean debugGL) {
+ GLCapabilities caps = new GLCapabilities(glp);
+ //
+ // 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 window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setSize(128, 128);
+ window.setVisible(true);
+
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
+ GLDrawable drawable = factory.createGLDrawable(window);
+ Assert.assertNotNull(drawable);
+
+ drawable.setRealized(true);
+
+ GLContext context = drawable.createContext(null);
+ Assert.assertNotNull(context);
+
+ context.enableGLDebugMessage(debugGL);
+
+ int res = context.makeCurrent();
+ Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res);
+
+ return new WindowContext(window, context);
+ }
+
+ void destroyWindow(WindowContext winctx) {
+ GLDrawable drawable = winctx.context.getGLDrawable();
+
+ Assert.assertNotNull(winctx.context);
+ winctx.context.destroy();
+
+ Assert.assertNotNull(drawable);
+ drawable.setRealized(false);
+
+ Assert.assertNotNull(winctx.window);
+ winctx.window.destroy();
+ }
+
+
+ void test01GLDebug01EnableDisable(boolean enable, String dbgTstMsg, int dbgTstId) throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+
+ WindowContext winctx = createWindow(glp, enable);
+ MyGLDebugListener myGLDebugListener = new MyGLDebugListener(dbgTstMsg, dbgTstId);
+ if(enable) {
+ winctx.context.addGLDebugListener(myGLDebugListener);
+ }
+ String glDebugExt = winctx.context.getGLDebugMessageExtension();
+ System.err.println("glDebug extension: "+glDebugExt);
+ System.err.println("glDebug enabled: "+winctx.context.isGLDebugMessageEnabled());
+ System.err.println("glDebug listener: "+winctx.context.getGLDebugListenerSize());
+ System.err.println("context version: "+winctx.context.getGLVersion());
+
+ Assert.assertEquals((null == glDebugExt) ? false : enable, winctx.context.isGLDebugMessageEnabled());
+ Assert.assertEquals(enable?1:0, winctx.context.getGLDebugListenerSize());
+
+ if(winctx.context.isGLDebugMessageEnabled() && null != dbgTstMsg && 0 <= dbgTstId) {
+ winctx.context.glDebugMessageInsert(GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB,
+ GL2GL3.GL_DEBUG_TYPE_OTHER_ARB,
+ dbgTstId,
+ GL2GL3.GL_DEBUG_SEVERITY_MEDIUM_ARB, -1, dbgTstMsg);
+ Assert.assertEquals(true, myGLDebugListener.received());
+ }
+
+ destroyWindow(winctx);
+ }
+
+ @Test
+ public void test01GLDebug01Disabled() throws InterruptedException {
+ test01GLDebug01EnableDisable(false, null, -1);
+ }
+
+ @Test
+ public void test01GLDebug01Enabled() throws InterruptedException {
+ test01GLDebug01EnableDisable(true, dbgTstMsg0, dbgTstId0);
+ }
+
+ @Test
+ public void test02GLDebug01Error() throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+
+ WindowContext winctx = createWindow(glp, true);
+
+ MyGLDebugListener myGLDebugListener = new MyGLDebugListener(
+ GL2GL3.GL_DEBUG_SOURCE_API_ARB,
+ GL2GL3.GL_DEBUG_TYPE_ERROR_ARB,
+ GL2GL3.GL_DEBUG_SEVERITY_HIGH_ARB);
+ winctx.context.addGLDebugListener(myGLDebugListener);
+
+ GL gl = winctx.context.getGL();
+
+ gl.glBindFramebuffer(-1, -1); // ERROR !
+
+ if( winctx.context.isGLDebugMessageEnabled() ) {
+ Assert.assertEquals(true, myGLDebugListener.received());
+ }
+
+ destroyWindow(winctx);
+ }
+
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestGLDebug00NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ public class MyGLDebugListener implements GLDebugListener {
+ int recSource;
+ int recType;
+ int recSeverity;
+
+ String recMsg;
+ int recId;
+ boolean received = false;
+
+ public MyGLDebugListener(int recSource, int recType, int recSeverity) {
+ this.recSource = recSource;
+ this.recType = recType;
+ this.recSeverity = recSeverity;
+ this.recMsg = null;
+ this.recId = -1;
+
+ }
+ public MyGLDebugListener(String recMsg, int recId) {
+ this.recSource = -1;
+ this.recType = -1;
+ this.recSeverity = -1;
+ this.recMsg = recMsg;
+ this.recId = recId;
+ }
+
+ public boolean received() { return received; }
+
+ public void messageSent(GLDebugMessage event) {
+ System.err.println("XXX: "+event);
+ if(null != recMsg && recMsg.equals(event.getDbgMsg()) && recId == event.getDbgId()) {
+ received = true;
+ } else if(0 <= recSource && recSource == event.getDbgSource() &&
+ recType == event.getDbgType() &&
+ recSeverity== event.getDbgSeverity() ) {
+ received = true;
+ }
+ }
+ }
+}
+ \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java
new file mode 100644
index 000000000..05870ee0d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java
@@ -0,0 +1,189 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.io.IOException;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDebugListener;
+import javax.media.opengl.GLDebugMessage;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestGLDebug01NEWT extends UITestCase {
+
+ static String dbgTstMsg0 = "Hello World";
+ static int dbgTstId0 = 42;
+
+ GLWindow createWindow(GLProfile glp, boolean debugGL) {
+ GLCapabilities caps = new GLCapabilities(glp);
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow window = GLWindow.create(caps);
+ Assert.assertNotNull(window);
+ window.setContextCreationFlags(debugGL?GLContext.CTX_OPTION_DEBUG:0);
+ window.setSize(128, 128);
+ window.setVisible(true);
+
+ Assert.assertNotNull(window.getContext());
+ Assert.assertNotNull(window.getContext().isCreated());
+
+ return window;
+ }
+
+ void destroyWindow(GLWindow window) {
+ window.destroy();
+ }
+
+
+ void test01GLDebug01EnableDisable(boolean enable, final String dbgTstMsg, final int dbgTstId) throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+
+ final GLWindow window = createWindow(glp, enable);
+ final GLContext ctx = window.getContext();
+ MyGLDebugListener myGLDebugListener = new MyGLDebugListener(dbgTstMsg, dbgTstId);
+ if(enable) {
+ ctx.addGLDebugListener(myGLDebugListener);
+ }
+ String glDebugExt = ctx.getGLDebugMessageExtension();
+ System.err.println("glDebug extension: "+glDebugExt);
+ System.err.println("glDebug enabled: "+ctx.isGLDebugMessageEnabled());
+ System.err.println("glDebug listener: "+ctx.getGLDebugListenerSize());
+ System.err.println("context version: "+ctx.getGLVersion());
+
+ Assert.assertEquals((null == glDebugExt) ? false : enable, ctx.isGLDebugMessageEnabled());
+ Assert.assertEquals(enable?1:0, ctx.getGLDebugListenerSize());
+ if(ctx.isGLDebugMessageEnabled() && null != dbgTstMsg && 0 <= dbgTstId) {
+ window.invoke(true, new GLRunnable() {
+ public void run(GLAutoDrawable drawable) {
+ drawable.getContext().glDebugMessageInsert(GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB,
+ GL2GL3.GL_DEBUG_TYPE_OTHER_ARB,
+ dbgTstId,
+ GL2GL3.GL_DEBUG_SEVERITY_MEDIUM_ARB, -1, dbgTstMsg);
+ }
+ });
+ Assert.assertEquals(true, myGLDebugListener.received());
+ }
+
+ destroyWindow(window);
+ }
+
+ @Test
+ public void test01GLDebug01Disabled() throws InterruptedException {
+ test01GLDebug01EnableDisable(false, null, -1);
+ }
+
+ @Test
+ public void test01GLDebug01Enabled() throws InterruptedException {
+ test01GLDebug01EnableDisable(true, dbgTstMsg0, dbgTstId0);
+ }
+
+ @Test
+ public void test02GLDebug01Error() throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+
+ GLWindow window = createWindow(glp, true);
+
+ MyGLDebugListener myGLDebugListener = new MyGLDebugListener(
+ GL2GL3.GL_DEBUG_SOURCE_API_ARB,
+ GL2GL3.GL_DEBUG_TYPE_ERROR_ARB,
+ GL2GL3.GL_DEBUG_SEVERITY_HIGH_ARB);
+ window.getContext().addGLDebugListener(myGLDebugListener);
+
+ window.invoke(true, new GLRunnable() {
+ public void run(GLAutoDrawable drawable) {
+ drawable.getGL().glBindFramebuffer(-1, -1); // ERROR !
+ }
+ } );
+
+ if( window.getContext().isGLDebugMessageEnabled() ) {
+ Assert.assertEquals(true, myGLDebugListener.received());
+ }
+
+ destroyWindow(window);
+ }
+
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestGLDebug01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ public class MyGLDebugListener implements GLDebugListener {
+ int recSource;
+ int recType;
+ int recSeverity;
+
+ String recMsg;
+ int recId;
+ boolean received = false;
+
+ public MyGLDebugListener(int recSource, int recType, int recSeverity) {
+ this.recSource = recSource;
+ this.recType = recType;
+ this.recSeverity = recSeverity;
+ this.recMsg = null;
+ this.recId = -1;
+
+ }
+ public MyGLDebugListener(String recMsg, int recId) {
+ this.recSource = -1;
+ this.recType = -1;
+ this.recSeverity = -1;
+ this.recMsg = recMsg;
+ this.recId = recId;
+ }
+
+ public boolean received() { return received; }
+
+ public void messageSent(GLDebugMessage event) {
+ System.err.println("XXX: "+event);
+ if(null != recMsg && recMsg.equals(event.getDbgMsg()) && recId == event.getDbgId()) {
+ received = true;
+ } else if(0 <= recSource && recSource == event.getDbgSource() &&
+ recType == event.getDbgType() &&
+ recSeverity== event.getDbgSeverity() ) {
+ received = true;
+ }
+ }
+ }
+}
+ \ No newline at end of file