29package com.jogamp.opengl.test.junit.newt.event;
31import org.junit.After;
32import org.junit.Assert;
33import org.junit.AfterClass;
34import org.junit.Assume;
35import org.junit.Before;
37import java.awt.AWTException;
38import java.awt.BorderLayout;
40import java.lang.reflect.InvocationTargetException;
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLEventListener;
44import javax.swing.JFrame;
46import java.io.IOException;
48import jogamp.nativewindow.jawt.JAWTUtil;
50import org.junit.BeforeClass;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
55import com.jogamp.newt.awt.NewtCanvasAWT;
56import com.jogamp.newt.opengl.GLWindow;
57import com.jogamp.opengl.util.Animator;
58import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
60import com.jogamp.opengl.test.junit.util.*;
73@FixMethodOrder(MethodSorters.NAME_ASCENDING)
75 static int width, height;
76 static long durationPerTest = 100;
77 static long awtWaitTimeout = 1000;
100 @Test(timeout=180000)
101 public
void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException {
103 glWindow.
setSize(width, height);
111 private void testNewtCanvasAWT_Impl(
final boolean onscreen)
throws AWTException, InterruptedException, InvocationTargetException {
121 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "+ glWindow.
getTitle());
122 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
123 frame1.setSize(width, height);
124 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
126 frame1.setVisible(
true);
134 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
136 frame1.setVisible(
false);
139 }
catch(
final Throwable throwable ) {
140 throwable.printStackTrace();
141 Assume.assumeNoException( throwable );
146 @Test(timeout=180000)
147 public
void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
148 if( JAWTUtil.isOffscreenLayerRequired() ) {
149 System.err.println(
"Platform doesn't support onscreen rendering.");
152 testNewtCanvasAWT_Impl(
true);
155 @Test(timeout=180000)
156 public
void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
157 if( !JAWTUtil.isOffscreenLayerSupported() ) {
158 System.err.println(
"Platform doesn't support offscreen rendering.");
161 testNewtCanvasAWT_Impl(
false);
164 static void testKeyEventOrder(
final Robot robot,
final NEWTKeyAdapter keyAdapter,
final int loops) {
165 System.err.println(
"KEY Event Order Test: "+loops);
167 for(
int i=0; i<loops; i++) {
195 final int expTotal = 6*loops;
197 expTotal , expTotal ,
202 void testImpl(
final GLWindow glWindow)
throws AWTException, InterruptedException, InvocationTargetException {
203 final Robot robot =
new Robot();
204 robot.setAutoWaitForIdle(
true);
216 final Animator animator =
new Animator(glWindow);
219 Thread.sleep(durationPerTest);
228 testKeyEventOrder(robot, glWindow1KA, 6);
237 static int atoi(
final String a) {
240 i = Integer.parseInt(a);
241 }
catch (
final Exception ex) { ex.printStackTrace(); }
245 public static void main(
final String args[])
throws IOException {
246 for(
int i=0; i<args.length; i++) {
247 if(args[i].equals(
"-time")) {
248 durationPerTest = atoi(args[++i]);
256 System.out.println(
"durationPerTest: "+durationPerTest);
258 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void removeKeyListener(final KeyListener l)
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.
Testing key event order excl.
static void main(final String args[])
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static int keyPress(final int i, final Robot robot, final boolean press, final int keyCode, final int msDelay)
No validation is performed .
static void assertRequestFocusAndWait(final Robot robot, final Object requestFocus, final Object waitForFocus, final FocusEventCountAdapter gain, final FocusEventCountAdapter lost)
static void waitForIdle(final Robot robot)
Issuing validateAWTEDTIsAlive() before calling Robot#waitForIdle().
synchronized List< EventObject > copyQueue()
synchronized void setVerbose(final boolean v)
Instance starts in verbose mode, call w/ false to disable verbosity.
synchronized void reset()
static void validateKeyEventOrder(final List< EventObject > keyEvents)
static void validateKeyAdapterStats(final NEWTKeyAdapter keyAdapter, final int expPressedCountSI, final int expReleasedCountSI, final int expPressedCountAR, final int expReleasedCountAR)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
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.