aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-09-03 18:48:57 +0200
committerSven Gothel <[email protected]>2015-09-03 18:48:57 +0200
commite1bf8dd6a24796589bcfcdc6dd66c5a4911d4dcd (patch)
tree698092c0f15f15f2ce85d8e8580ba09ae89185e4
parent3e5c410e1d0ae42c68a7ab1342a7da96ef523a4b (diff)
Bug 1211 TestBug1211IRQ00NEWT: Add assertions incl. testing Thread.interrupted() assuring no silence interruption occured
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java87
1 files changed, 70 insertions, 17 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java
index 2487b3e79..a5b7e31b5 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java
@@ -28,25 +28,25 @@
package com.jogamp.opengl.test.junit.newt;
+import java.io.IOException;
+
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Test;
import org.junit.FixMethodOrder;
+import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.jogamp.opengl.*;
-
-import com.jogamp.newt.*;
-import com.jogamp.newt.opengl.*;
+import com.jogamp.common.ExceptionUtils;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.newt.util.EDTUtil;
-
-import java.io.IOException;
-
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLCapabilitiesImmutable;
+import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
-import com.jogamp.common.ExceptionUtils;
-import com.jogamp.common.util.VersionUtil;
/**
* Unit test to identify Thread.interrupt() caller for DefaultEDTUtil.invokeImpl(..) wait interruption.
@@ -87,7 +87,7 @@ public class TestBug1211IRQ00NEWT extends UITestCase {
return glWindow;
}
- static void destroyWindow(final GLWindow glWindow) {
+ static void destroyWindow(final GLWindow glWindow) throws InterruptedException {
if(null!=glWindow) {
glWindow.destroy();
Assert.assertEquals(false,glWindow.isNativeValid());
@@ -96,19 +96,42 @@ public class TestBug1211IRQ00NEWT extends UITestCase {
static class MyThread extends Thread {
volatile boolean interruptCalled;
+
public MyThread(final Runnable target, final String name) {
super(target, name);
interruptCalled = false;
}
public boolean interruptCalled() { return interruptCalled; }
+
+ public static void testInterrupted() throws InterruptedException {
+ if( Thread.interrupted() ) {
+ throw new InterruptedException("Thread.testInterrupted -> TRUE (silent interruption)");
+ }
+ }
+
@Override
public void interrupt() {
System.err.println("MyThread.interrupt() ******************************************************");
ExceptionUtils.dumpStack(System.err);
+ interruptCalled = true;
super.interrupt();
}
}
+
+ volatile boolean interrupt1 = false;
+ volatile boolean interrupt2 = false;
+ volatile boolean interrupt3 = false;
+ volatile boolean interrupt4 = false;
+
+ @Before
+ public void initTest() {
+ interrupt1 = false;
+ interrupt2 = false;
+ interrupt3 = false;
+ interrupt4 = false;
+ }
+
/**
* Test whether resize triggers DefaultEDTUtil.invokeImpl(..) wait interruption.
*/
@@ -142,21 +165,36 @@ public class TestBug1211IRQ00NEWT extends UITestCase {
System.err.println("test00.resize["+i+"]: "+ow+"x"+oh+" -> "+nw+"x"+nh);
window1.setSize(nw, nh);
final MyThread _t = (MyThread)Thread.currentThread();
- ok = !_t.interruptCalled() && edt.isRunning() && anim.isAnimating();
+ ok = !_t.interruptCalled() && !_t.isInterrupted() && edt.isRunning() && anim.isAnimating();
+ MyThread.testInterrupted();
}
} catch (final InterruptedException e) {
- ExceptionUtils.dumpThrowable("MyThread.InterruptedException", e);
+ ExceptionUtils.dumpThrowable("MyThread.InterruptedException-1", e);
+ interrupt1 = true;
+ }
+ try {
+ anim.stop();
+ destroyWindow(window1);
+ MyThread.testInterrupted();
+ } catch (final InterruptedException e) {
+ ExceptionUtils.dumpThrowable("MyThread.InterruptedException-2", e);
+ interrupt2 = true;
}
- anim.stop();
- destroyWindow(window1);
}
}, "Thread_Test01");
t.start();
try {
t.join();
+ MyThread.testInterrupted();
} catch (final InterruptedException e) {
ExceptionUtils.dumpThrowable("Thread.InterruptedException", e);
+ interrupt3 = true;
}
+ Assert.assertFalse("MyThread.interruptCalled()", t.interruptCalled());
+ Assert.assertFalse("MyThread.interrupt() occured!", t.isInterrupted());
+ Assert.assertFalse("MyThread Interrupt-1 occured!", interrupt1);
+ Assert.assertFalse("MyThread Interrupt-2 occured!", interrupt2);
+ Assert.assertFalse("Thread Interrupt-3 occured!", interrupt3);
}
/**
@@ -183,19 +221,34 @@ public class TestBug1211IRQ00NEWT extends UITestCase {
Thread.sleep(100);
anim.stop();
destroyWindow(window1);
+ MyThread.testInterrupted();
}
} catch (final InterruptedException e) {
ExceptionUtils.dumpThrowable("MyThread.InterruptedException", e);
+ interrupt1 = true;
+ }
+ try {
+ destroyWindow(lastWindow);
+ MyThread.testInterrupted();
+ } catch (final InterruptedException e) {
+ ExceptionUtils.dumpThrowable("MyThread.InterruptedException-2", e);
+ interrupt2 = true;
}
- destroyWindow(lastWindow);
}
}, "Thread_Test01");
t.start();
try {
t.join();
+ MyThread.testInterrupted();
} catch (final InterruptedException e) {
ExceptionUtils.dumpThrowable("Thread.InterruptedException", e);
+ interrupt3 = true;
}
+ Assert.assertFalse("MyThread.interruptCalled()", t.interruptCalled());
+ Assert.assertFalse("MyThread.interrupt() occured!", t.isInterrupted());
+ Assert.assertFalse("MyThread Interrupt-1 occured!", interrupt1);
+ Assert.assertFalse("MyThread Interrupt-2 occured!", interrupt2);
+ Assert.assertFalse("Thread Interrupt-3 occured!", interrupt3);
}
static void ncSleep(final long ms) {
try {