29package com.jogamp.opengl.test.junit.newt;
31import java.io.IOException;
33import org.junit.Assert;
34import org.junit.FixMethodOrder;
36import org.junit.runners.MethodSorters;
38import com.jogamp.common.ExceptionUtils;
39import com.jogamp.common.util.InterruptSource;
40import com.jogamp.common.util.SourcedInterruptedException;
41import com.jogamp.common.util.VersionUtil;
42import com.jogamp.junit.util.SingletonJunitCase;
43import com.jogamp.newt.opengl.GLWindow;
44import com.jogamp.newt.util.EDTUtil;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLCapabilitiesImmutable;
47import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.util.Animator;
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static long durationTest00 = 1000;
61 static long durationTest01 = 1000;
62 static int width = 800;
63 static int height = 600;
66 Assert.assertNotNull(caps);
71 Assert.assertNotNull(glWindow);
72 glWindow.
setSize(width, height);
83 static void destroyWindow(
final GLWindow glWindow)
throws InterruptedException {
90 static class MyThread
extends InterruptSource.Thread implements Thread.UncaughtExceptionHandler {
91 volatile boolean myThreadStarted =
false;
92 volatile boolean myThreadStopped =
false;
94 public MyThread(
final Runnable target,
final String name) {
95 super(
null, target, name);
96 setUncaughtExceptionHandler(
this);
99 public static void testInterrupted1()
throws InterruptedException {
100 if( java.lang.Thread.interrupted() ) {
101 throw SourcedInterruptedException.wrap(
102 new InterruptedException(java.lang.Thread.currentThread().getName()+
".testInterrupted -> TRUE (silent interruption)"));
105 public synchronized void testInterrupted(
final boolean ignore)
throws InterruptedException {
106 if( isInterrupted() ) {
107 final boolean current;
108 if(
this == java.lang.Thread.currentThread() ) {
109 java.lang.Thread.interrupted();
114 final int counter = getInterruptCounter(
false);
115 final Throwable source = getInterruptSource(
true);
116 final InterruptedException e =
new SourcedInterruptedException(
117 getName()+
".testInterrupted -> TRUE (current "+current+
", counter "+counter+
")",
122 ExceptionUtils.dumpThrowable(
"Ignored", e);
129 myThreadStarted =
true;
133 myThreadStopped =
true;
138 public void uncaughtException(
final java.lang.Thread t,
final Throwable e) {
139 System.err.println(
"UncaughtException on Thread "+t.getName()+
": "+e.getMessage());
140 ExceptionUtils.dumpThrowable(
"UncaughtException", e);
145 volatile boolean interrupt1 =
false;
146 volatile boolean interrupt2 =
false;
147 volatile boolean interruptInit0 =
false;
158 final MyThread t = (MyThread)Thread.currentThread();
160 Assert.assertNotNull(caps);
161 final GLWindow window1 = createWindow(caps);
166 Assert.assertEquals(
true,window1.
isVisible());
170 for(
int i=0; ok && i*100<durationTest00; i++) {
182 System.err.println(
"test00.resize["+i+
"]: "+ow+
"x"+oh+
" -> "+nw+
"x"+nh);
184 ok = 0==t.getInterruptCounter(
false) && !t.isInterrupted() && edt.
isRunning() && anim.isAnimating();
185 t.testInterrupted(
false);
187 }
catch (
final InterruptedException e) {
188 ExceptionUtils.dumpThrowable(
"InterruptedException-1", e);
193 destroyWindow(window1);
194 t.testInterrupted(
false);
195 }
catch (
final InterruptedException e) {
196 ExceptionUtils.dumpThrowable(
"InterruptedException-2", e);
199 Assert.assertEquals(
"interruptCounter not zero", 0, t.getInterruptCounter(
false));
200 Assert.assertFalse(
"interrupt() occured!", t.isInterrupted());
201 Assert.assertFalse(
"Interrupt-1 occured!", interrupt1);
202 Assert.assertFalse(
"Interrupt-2 occured!", interrupt2);
209 final MyThread t = (MyThread)Thread.currentThread();
212 final boolean ok =
true;
213 for(
int i=0; ok && i*100<durationTest01; i++) {
215 Assert.assertNotNull(caps);
216 final GLWindow window1 = createWindow(caps);
217 lastWindow = window1;
219 Assert.assertEquals(
true,window1.
isVisible());
226 destroyWindow(window1);
227 t.testInterrupted(
false);
229 }
catch (
final InterruptedException e) {
230 ExceptionUtils.dumpThrowable(
"InterruptedException-1", e);
234 destroyWindow(lastWindow);
235 t.testInterrupted(
false);
236 }
catch (
final InterruptedException e) {
237 ExceptionUtils.dumpThrowable(
"InterruptedException-2", e);
240 Assert.assertEquals(
"interruptCounter not zero", 0, t.getInterruptCounter(
false));
241 Assert.assertFalse(
"interrupt() occured!", t.isInterrupted());
242 Assert.assertFalse(
"Interrupt-1 occured!", interrupt1);
243 Assert.assertFalse(
"Interrupt-2 occured!", interrupt2);
248 interruptInit0 =
false;
249 final MyThread t =
new MyThread(
new Runnable() {
251 final MyThread t = (MyThread)Thread.currentThread();
254 System.err.println(VersionUtil.getPlatformInfo());
257 t.testInterrupted(
false);
258 }
catch (
final InterruptedException e) {
259 ExceptionUtils.dumpThrowable(
"InterruptedException-Init0", e);
260 interruptInit0 =
true;
263 t.clearInterruptSource();
274 boolean interrupted =
false;
276 MyThread.testInterrupted1();
277 while( !t.myThreadStarted ) {
279 MyThread.testInterrupted1();
281 while( !t.myThreadStopped ) {
283 MyThread.testInterrupted1();
285 MyThread.testInterrupted1();
286 }
catch (
final InterruptedException e) {
287 ExceptionUtils.dumpThrowable(
"InterruptedException-All", e);
290 Assert.assertFalse(
"Thread Interrupt-All occured!", interrupted);
291 Assert.assertFalse(
"Interrupt-Init0 occured!", interruptInit0);
294 static int atoi(
final String a) {
297 i = Integer.parseInt(a);
298 }
catch (
final Exception ex) { ex.printStackTrace(); }
302 public static void main(
final String args[])
throws IOException {
304 SingletonJunitCase.enableSingletonLock(
false);
306 for(
int i=0; i<args.length; i++) {
307 if(args[i].equals(
"-time00")) {
308 durationTest00 = atoi(args[++i]);
309 }
else if(args[i].equals(
"-time01")) {
310 durationTest01 = atoi(args[++i]);
311 }
else if(args[i].equals(
"-width")) {
312 width = atoi(args[++i]);
313 }
else if(args[i].equals(
"-height")) {
314 height = atoi(args[++i]);
317 System.out.println(
"durationTest00: "+durationTest00);
318 System.out.println(
"durationTest01: "+durationTest01);
319 System.out.println(
"defaultSize : "+width+
"x"+height);
321 org.junit.runner.JUnitCore.
main(tstname);
abstract EDTUtil getEDTUtil()
abstract Display getDisplay()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final String getStateMaskString()
Returns a string representation of the current state mask.
final boolean isNativeValid()
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static void initSingleton()
Static initialization of JOGL.
GearsES2 setVerbose(final boolean v)
Unit test to identify Thread.interrupt() caller for DefaultEDTUtil.invokeImpl(..) wait interruption.
void subTest00()
Test whether resize triggers DefaultEDTUtil.invokeImpl(..) wait interruption.
static void main(final String args[])
void subTest01()
Test whether create/destroy triggers DefaultEDTUtil.invokeImpl(..) wait interruption.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
EDT stands for Event Dispatch Thread.
void setUpdateFPSFrames(int frames, PrintStream out)
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.