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;
41import java.util.Arrays;
42import java.util.EventObject;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLEventListener;
47import javax.swing.JFrame;
49import java.io.IOException;
51import org.junit.BeforeClass;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
56import com.jogamp.newt.awt.NewtCanvasAWT;
57import com.jogamp.newt.event.InputEvent;
58import com.jogamp.newt.event.KeyEvent;
59import com.jogamp.newt.opengl.GLWindow;
60import com.jogamp.opengl.util.Animator;
61import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
62import com.jogamp.opengl.test.junit.util.*;
86@FixMethodOrder(MethodSorters.NAME_ASCENDING)
88 static int width, height;
89 static long durationPerTest = 100;
90 static long awtWaitTimeout = 1000;
113 @Test(timeout=180000)
114 public
void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException {
116 glWindow.
setSize(width, height);
124 @Test(timeout=180000)
125 public
void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
132 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "+ glWindow.
getTitle());
133 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
134 frame1.setSize(width, height);
135 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
137 frame1.setVisible(
true);
145 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
147 frame1.setVisible(
false);
150 }
catch(
final Throwable throwable ) {
151 throwable.printStackTrace();
152 Assume.assumeNoException( throwable );
157 static void testKeyEventAutoRepeat(
final Robot robot,
final NEWTKeyAdapter keyAdapter,
final int loops,
final int pressDurationMS) {
158 System.err.println(
"KEY Event Auto-Repeat Test: "+loops);
159 final EventObject[][] first =
new EventObject[loops][2];
160 final EventObject[][] last =
new EventObject[loops][2];
165 for(
int i=0; i<loops; i++) {
166 System.err.println(
"+++ KEY Event Auto-Repeat START Input Loop: "+i);
171 final int minCodeCount = firstIdx + 2;
172 final int desiredCodeCount = firstIdx + 4;
173 for(
int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.
getQueueSize() < desiredCodeCount; j++) {
176 final List<EventObject> keyEvents = keyAdapter.
copyQueue();
177 Assert.assertTrue(
"AR Test didn't collect enough key events: required min "+minCodeCount+
", received "+(keyAdapter.
getQueueSize()-firstIdx)+
", "+keyEvents,
179 first[i][0] = keyEvents.get(firstIdx+0);
180 first[i][1] = keyEvents.get(firstIdx+1);
181 firstIdx = keyEvents.size() - 2;
182 last[i][0] = keyEvents.get(firstIdx+0);
183 last[i][1] = keyEvents.get(firstIdx+1);
184 System.err.println(
"+++ KEY Event Auto-Repeat END Input Loop: "+i);
187 firstIdx = keyEvents.size();
192 for(
int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.
getQueueSize() < firstIdx+2; j++) {
198 final List<EventObject> keyEvents = keyAdapter.
copyQueue();
204 final int perLoopSI = 2;
205 final int expSI, expAR;
207 expSI = perLoopSI * loops;
208 expAR = ( keyEvents.size() - expSI*2 ) / 2;
210 expSI = keyEvents.size() / 2;
220 System.err.println(
"No AUTO-REPEAT triggered by AWT Robot .. aborting test analysis");
224 for(
int i=0; i<loops; i++) {
225 System.err.println(
"Auto-Repeat Loop "+i+
" - Head:");
227 System.err.println(
"Auto-Repeat Loop "+i+
" - Tail:");
230 for(
int i=0; i<loops; i++) {
253 void testImpl(
final GLWindow glWindow)
throws AWTException, InterruptedException, InvocationTargetException {
254 final Robot robot =
new Robot();
255 robot.setAutoWaitForIdle(
true);
258 glWindow.addGLEventListener(demo1);
262 glWindow.addKeyListener(glWindow1KA);
267 final Animator animator =
new Animator(glWindow);
270 Thread.sleep(durationPerTest);
279 final int origAutoDelay = robot.getAutoDelay();
280 robot.setAutoDelay(10);
282 testKeyEventAutoRepeat(robot, glWindow1KA, 3, 1000);
284 robot.setAutoDelay(origAutoDelay);
288 glWindow.removeKeyListener(glWindow1KA);
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 {
303 for(
int i=0; i<args.length; i++) {
304 if(args[i].equals(
"-time")) {
305 durationPerTest = atoi(args[++i]);
313 System.out.println(
"durationPerTest: "+durationPerTest);
315 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
static final short VK_A
VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A)
static final short EVENT_KEY_PRESSED
A key has been pressed, excluding auto-repeat-modifier keys.
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
static final short EVENT_KEY_RELEASED
A key has been released, excluding auto-repeat-modifier keys.
final short getEventType()
Returns the event type of this event.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
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 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 incl.
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 int getQueueSize()
synchronized void reset()
synchronized int getKeyPressedCount(final boolean autoRepeatOnly)
static void dumpKeyEvents(final List< EventObject > keyEvents)
static void validateKeyEventOrder(final List< EventObject > keyEvents)
static final int TIME_SLICE
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)
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.