29package com.jogamp.opengl.test.junit.newt;
31import org.junit.Assert;
32import org.junit.BeforeClass;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
37import com.jogamp.opengl.*;
39import com.jogamp.newt.*;
40import com.jogamp.newt.event.*;
41import com.jogamp.newt.opengl.*;
42import com.jogamp.newt.util.EDTUtil;
44import java.io.IOException;
46import com.jogamp.opengl.test.junit.util.UITestCase;
47import com.jogamp.opengl.test.junit.util.MiscUtils;
48import com.jogamp.opengl.test.junit.util.NewtTestUtil;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55 static final int width = 500, height = 500, xy_pos=100;
56 static long durationPerTest = 100;
65 throws InterruptedException
67 Assert.assertNotNull(caps);
75 Assert.assertNotNull(window);
83 setDemoFields(demo, glWindow);
86 glWindow.
setSize(width, height);
90 private void testDisplayCreate01(
final Display display,
final Screen screen)
throws InterruptedException {
93 Assert.assertEquals(0,display.getReferenceCount());
94 Assert.assertEquals(
false,display.isNativeValid());
95 Assert.assertNotNull(display.getEDTUtil());
96 Assert.assertEquals(
false,display.getEDTUtil().isRunning());
97 Assert.assertEquals(0,screen.getReferenceCount());
98 Assert.assertEquals(
false,screen.isNativeValid());
101 final GLWindow window = createWindow(screen, caps, width, height);
103 Assert.assertEquals(screen,window.
getScreen());
105 Assert.assertEquals(0,display.getReferenceCount());
106 Assert.assertEquals(
false,display.isNativeValid());
107 Assert.assertEquals(
true,display.getEDTUtil().isRunning());
108 Assert.assertEquals(0,screen.getReferenceCount());
109 Assert.assertEquals(
false,screen.isNativeValid());
111 Assert.assertNotNull(window.
getScreen());
113 Assert.assertEquals(
false,window.
isVisible());
114 Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos));
120 Assert.assertEquals(screen,window.
getScreen());
122 Assert.assertEquals(1,display.getReferenceCount());
123 Assert.assertEquals(
true,display.isNativeValid());
124 Assert.assertEquals(
true,display.getEDTUtil().isRunning());
125 Assert.assertEquals(1,screen.getReferenceCount());
126 Assert.assertEquals(
true,screen.isNativeValid());
128 Assert.assertEquals(
true,window.
isVisible());
129 Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos));
130 System.err.println(
"Frames for setVisible(true) 1: "+window.
getTotalFPSFrames());
142 Assert.assertEquals(
false,window.
isVisible());
144 NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos);
151 Assert.assertEquals(
true,window.
isVisible());
152 Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos));
153 System.err.println(
"Frames for setVisible(true) 1: "+window.
getTotalFPSFrames());
164 Assert.assertEquals(screen,window.
getScreen());
166 Assert.assertEquals(0,display.getReferenceCount());
167 Assert.assertEquals(
false,display.isNativeValid());
168 Assert.assertNotNull(display.getEDTUtil());
169 Assert.assertEquals(
false,display.getEDTUtil().isRunning());
170 Assert.assertEquals(0,screen.getReferenceCount());
171 Assert.assertEquals(
false,screen.isNativeValid());
173 Assert.assertEquals(
false,window.
isVisible());
181 Assert.assertEquals(
false,window.
isVisible());
186 Assert.assertEquals(screen,window.
getScreen());
188 Assert.assertEquals(1,display.getReferenceCount());
189 Assert.assertEquals(
true,display.isNativeValid());
190 Assert.assertEquals(
true,display.getEDTUtil().isRunning());
191 Assert.assertEquals(1,screen.getReferenceCount());
192 Assert.assertEquals(
true,screen.isNativeValid());
194 Assert.assertEquals(
true,window.
isVisible());
195 System.err.println(
"Frames for setVisible(true) 2: "+window.
getTotalFPSFrames());
210 Assert.assertEquals(0,display.getReferenceCount());
211 Assert.assertEquals(
false,display.isNativeValid());
213 final EDTUtil edtUtil = display.getEDTUtil();
214 Assert.assertNotNull(edtUtil);
215 Assert.assertEquals(
false,edtUtil.
isRunning());
217 Assert.assertEquals(
true,edtUtil.
isRunning());
218 edtUtil.
invoke(
true,
null);
219 Assert.assertEquals(
true,edtUtil.
isRunning());
222 Assert.assertEquals(
false,edtUtil.
isRunning());
224 Assert.assertEquals(0,screen.getReferenceCount());
225 Assert.assertEquals(
false,screen.isNativeValid());
227 Assert.assertNotNull(window.
getScreen());
229 Assert.assertEquals(
false,window.
isVisible());
239 System.err.println(
"Pass - 1");
240 testDisplayCreate01(display, screen);
241 System.err.println(
"Pass - 2");
242 testDisplayCreate01(display, screen);
248 Assert.assertNotNull(demo);
249 Assert.assertNotNull(glWindow);
255 static int atoi(
final String a) {
258 i = Integer.parseInt(a);
259 }
catch (
final Exception ex) { ex.printStackTrace(); }
263 public static void main(
final String args[])
throws IOException {
264 for(
int i=0; i<args.length; i++) {
265 if(args[i].equals(
"-time")) {
266 durationPerTest = atoi(args[++i]);
269 System.err.println(
"durationPerTest: "+durationPerTest);
271 org.junit.runner.JUnitCore.
main(tstname);
static int getActiveDisplayNumber()
static void dumpDisplayList(final String prefix)
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isNativeValid()
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
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 void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
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 setDemoFields(final GLEventListener demo, final GLWindow glWindow)
static void main(final String args[])
void testDisplayCreate01_AutoDestroyLifecycle()
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
Specifying NEWT's Window functionality:
EDT stands for Event Dispatch Thread.
boolean invokeStop(boolean wait, Runnable finalTask)
Append the final task to the EDT task queue, signals EDT to stop.
void start()
Starts the EDT after it's creation or after stopping.
boolean invoke(boolean wait, Runnable task)
Appends task to the EDT task queue if current thread is not EDT, otherwise execute task immediately.
boolean waitUntilStopped()
Wait until EDT task is stopped.
void setUpdateFPSFrames(int frames, PrintStream out)
void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
long getTotalFPSDuration()
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.