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.EventObject;
44import com.jogamp.opengl.GLCapabilities;
45import com.jogamp.opengl.GLEventListener;
46import javax.swing.JFrame;
48import java.io.IOException;
50import jogamp.nativewindow.jawt.JAWTUtil;
52import org.junit.BeforeClass;
54import org.junit.FixMethodOrder;
55import org.junit.runners.MethodSorters;
57import com.jogamp.newt.awt.NewtCanvasAWT;
58import com.jogamp.newt.event.InputEvent;
59import com.jogamp.newt.event.KeyEvent;
60import com.jogamp.newt.opengl.GLWindow;
61import com.jogamp.opengl.util.Animator;
62import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
64import com.jogamp.opengl.test.junit.util.*;
74@FixMethodOrder(MethodSorters.NAME_ASCENDING)
76 static int width, height;
77 static long durationPerTest = 100;
78 static long awtWaitTimeout = 1000;
101 @Test(timeout=180000)
102 public
void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException {
104 glWindow.
setSize(width, height);
112 private void testNewtCanvasAWT_Impl(
final boolean onscreen)
throws AWTException, InterruptedException, InvocationTargetException {
122 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "+ glWindow.
getTitle());
123 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
124 frame1.setSize(width, height);
125 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
127 frame1.setVisible(
true);
135 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
137 frame1.setVisible(
false);
140 }
catch(
final Throwable throwable ) {
141 throwable.printStackTrace();
142 Assume.assumeNoException( throwable );
147 @Test(timeout=180000)
148 public
void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
149 if( JAWTUtil.isOffscreenLayerRequired() ) {
150 System.err.println(
"Platform doesn't support onscreen rendering.");
153 testNewtCanvasAWT_Impl(
true);
156 @Test(timeout=180000)
157 public
void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
158 if( !JAWTUtil.isOffscreenLayerSupported() ) {
159 System.err.println(
"Platform doesn't support offscreen rendering.");
162 testNewtCanvasAWT_Impl(
false);
165 static void testKeyCodeModifier(
final Robot robot,
final NEWTKeyAdapter keyAdapter,
final short modifierKey,
final int modifierMask,
final short keyCode,
166 final char keyCharOnly,
final char keyCharMod) {
172 for(
int j=0; j < 100 && keyAdapter.
getQueueSize() < 2; j++) {
182 for(
int j=0; j < 100 && keyAdapter.
getQueueSize() < 2+4; j++) {
189 final List<EventObject> queue = keyAdapter.
copyQueue();
201 static void testKeyCodeAllModifierV1(
final Robot robot,
final NEWTKeyAdapter keyAdapter) {
222 for(
int j=0; j < 100 && keyAdapter.
getQueueSize() < 4+4; j++) {
229 final List<EventObject> queue = keyAdapter.
copyQueue();
243 void testImpl(
final GLWindow glWindow)
throws AWTException, InterruptedException, InvocationTargetException {
244 final Robot robot =
new Robot();
245 robot.setAutoWaitForIdle(
true);
259 final Animator animator =
new Animator(glWindow);
262 Thread.sleep(durationPerTest);
274 testKeyCodeAllModifierV1(robot, glWindow1KA);
283 static int atoi(
final String a) {
286 i = Integer.parseInt(a);
287 }
catch (
final Exception ex) { ex.printStackTrace(); }
291 public static void main(
final String args[])
throws IOException {
292 for(
int i=0; i<args.length; i++) {
293 if(args[i].equals(
"-time")) {
294 durationPerTest = atoi(args[++i]);
302 System.out.println(
"durationPerTest: "+durationPerTest);
304 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.
static final short VK_SHIFT
Constant for the CTRL function key.
static final char NULL_CHAR
This value, '\0', is used to indicate that the keyChar is unknown or not printable.
static final short VK_P
See VK_A.
static final short VK_ALT
Constant for the left ALT function key.
static final short EVENT_KEY_PRESSED
A key has been pressed, excluding auto-repeat-modifier keys.
static final short VK_Y
See VK_A.
static final short VK_1
See VK_0.
static final short EVENT_KEY_RELEASED
A key has been released, excluding auto-repeat-modifier keys.
static final short VK_CONTROL
Constant for the CTRL function key.
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 combinations of key code modifiers of key event.
static void main(final String args[])
static int newtKeyPress(final int i, final Robot robot, final boolean press, final short newtKeyCode, final int msDelay)
No validation is performed .
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 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()
static void validateKeyEvent(final KeyEvent e, final short eventType, final int modifiers, final short keyCode, final char keyChar)
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.