JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
BaseNewtEventModifiers.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.newt.event ;
30
31import java.io.PrintStream ;
32import java.util.ArrayList ;
33import java.util.concurrent.atomic.AtomicInteger;
34
36
37import org.junit.Assert ;
38import org.junit.BeforeClass ;
39import org.junit.FixMethodOrder;
40import org.junit.Test ;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.common.util.InterruptSource;
44import com.jogamp.common.util.RunnableTask;
45import com.jogamp.newt.event.MouseEvent;
46import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
48
49/**
50 * Test whether or not event modifiers are preserved by NEWT. This
51 * class defines most of the tests, but leaves the type of window
52 * and canvas up to subclasses.
53 */
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55public abstract class BaseNewtEventModifiers extends UITestCase {
56
57 ////////////////////////////////////////////////////////////////////////////
58
59 protected static final int TEST_FRAME_X = 100 ;
60 protected static final int TEST_FRAME_Y = 100 ;
61
62 protected static final int TEST_FRAME_WIDTH = 400 ;
63 protected static final int TEST_FRAME_HEIGHT = 400 ;
64
65 protected static final int INITIAL_MOUSE_X = TEST_FRAME_X + ( TEST_FRAME_WIDTH / 2 ) ;
66 protected static final int INITIAL_MOUSE_Y = TEST_FRAME_Y + ( TEST_FRAME_HEIGHT / 2 ) ;
67
68 protected static final int MS_ROBOT_KEY_PRESS_DELAY = 50 ;
69 protected static final int MS_ROBOT_KEY_RELEASE_DELAY = 50 ;
70 protected static final int MS_ROBOT_MOUSE_MOVE_DELAY = 200 ;
71
72 protected static final int MS_ROBOT_AUTO_DELAY = 50 ;
73 protected static final int MS_ROBOT_POST_TEST_DELAY = 100;
74
75 protected static final boolean _debug = true ;
76 protected static final PrintStream _debugPrintStream = System.err ;
77
78 ////////////////////////////////////////////////////////////////////////////
79
80 static
81 {
83 }
84
85 private static class TestMouseListener implements com.jogamp.newt.event.MouseListener
86 {
87 private static final String NO_EVENT_DELIVERY = "no event delivery" ;
88
89 private boolean _modifierCheckEnabled ;
90 private int _expectedModifiers;
91 private final AtomicInteger _eventCount = new AtomicInteger(0);
92 private ArrayList<String> _failures = new ArrayList<String>() ;
93
94 public synchronized void setModifierCheckEnabled( final boolean value ) {
95 _modifierCheckEnabled = value ;
96 }
97
98 public synchronized boolean modifierCheckEnabled() {
99 return _modifierCheckEnabled ;
100 }
101
102 /**
103 * Sets the modifiers the listener should expect, and clears
104 * out any existing accumulated failures. Normally this kind
105 * of double duty in a setter might be considered evil, but
106 * in this test code it's probably ok.
107 */
108
109 public synchronized void setExpectedModifiers( final int value ) {
110 _expectedModifiers = value ;
111 clear();
112 }
113
114 public synchronized ArrayList<String> clear() {
115 final ArrayList<String> old = _failures;
116
117 _eventCount.set(0);
118
119 // Assume we will have a failure due to no event delivery.
120 // If an event is delivered and it's good this assumed
121 // failure will get cleared out.
122 _failures = new ArrayList<String>();
123 _failures.add( NO_EVENT_DELIVERY );
124 return old;
125 }
126
127 public ArrayList<String> getFailures(final int waitEventCount) {
128 int j;
129 for(j=0; j < 20 && _eventCount.get() < waitEventCount; j++) { // wait until events are collected
130 _robot.delay(MS_ROBOT_AUTO_DELAY);
131 }
132 if(0 == _eventCount.get()) {
133 _debugPrintStream.println("**** No Event. Waited "+j+" * "+MS_ROBOT_AUTO_DELAY+"ms, eventCount "+_eventCount);
134 }
135 return clear();
136 }
137
138 private synchronized void _checkModifiers( final com.jogamp.newt.event.MouseEvent hasEvent ) {
139 if( _modifierCheckEnabled ) {
140
141 final MouseEvent expEvent = new MouseEvent(hasEvent.getEventType(), hasEvent.getSource(), hasEvent.getWhen(), _expectedModifiers,
142 hasEvent.getX(), hasEvent.getY(), hasEvent.getClickCount(), hasEvent.getButton(),
143 hasEvent.getRotation(), hasEvent.getRotationScale());
144
145 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.SHIFT_MASK, "shift" ) ;
146 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.CTRL_MASK, "ctrl" ) ;
147 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.META_MASK, "meta" ) ;
148 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.ALT_MASK, "alt" ) ;
149 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK, "graph" ) ;
150
151 for( int n = 0 ; n < _numButtonsToTest ; ++n ) {
152 _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.getButtonMask( n + 1 ), "button"+(n+1) ) ;
153 }
154 }
155 }
156
157 private synchronized void _checkModifierMask( final com.jogamp.newt.event.MouseEvent expEvent, final com.jogamp.newt.event.MouseEvent hasEvent, final int mask, final String maskS ) {
158
159 // If the "no event delivery" failure is still in the list then
160 // get rid of it since that obviously isn't true anymore. We
161 // want to do this whether or not there's an issue with the
162 // modifiers.
163
164 if( _failures.size() == 1 && _failures.get(0).equals( NO_EVENT_DELIVERY ) ) {
165 _failures.clear() ;
166 }
167
168 if( ( hasEvent.getModifiers() & mask ) != ( expEvent.getModifiers() & mask ) ) {
169 final StringBuilder sb = new StringBuilder();
170 sb.append( com.jogamp.newt.event.MouseEvent.getEventTypeString( hasEvent.getEventType() ) ).append(": mask ").append(maskS).append(" 0x").append(Integer.toHexString(mask));
171 sb.append(", eventCount ").append(_eventCount).append(", expected:");
172 expEvent.getModifiersString(sb);
173 sb.append(", have: ");
174 hasEvent.getModifiersString(sb);
175 sb.append(" - full event: ");
176 hasEvent.toString(sb);
177 _failures.add( sb.toString() ) ;
178 }
179 }
180
181 @Override
182 public synchronized void mousePressed( final com.jogamp.newt.event.MouseEvent event ) {
183 _eventCount.incrementAndGet();
184 if( _debug ) {
185 _debugPrintStream.println( "MousePressed "+_eventCount+": "+event);
186 }
187 _checkModifiers( event ) ;
188 }
189
190 @Override
191 public synchronized void mouseReleased( final com.jogamp.newt.event.MouseEvent event ) {
192 _eventCount.incrementAndGet();
193 if( _debug ) {
194 _debugPrintStream.println( "MouseReleased "+_eventCount+": "+event);
195 }
196 _checkModifiers( event ) ;
197 }
198
199 @Override
200 public synchronized void mouseDragged( final com.jogamp.newt.event.MouseEvent event ) {
201 _eventCount.incrementAndGet();
202 if( _debug ) {
203 _debugPrintStream.println( "MouseDragged "+_eventCount+": "+event);
204 }
205 _checkModifiers( event ) ;
206 }
207
208 //
209 // IGNORED
210 //
211
212 @Override
213 public synchronized void mouseMoved( final com.jogamp.newt.event.MouseEvent event ) {
214 // Ignored, since mouse MOVE doesn't hold mouse button, we look for DRAGGED!
215 // _eventCount++;
216 if( _debug ) {
217 _debugPrintStream.println( "MouseMoved ignored: "+event);
218 }
219 // _checkModifiers( event ) ;
220 }
221
222 @Override
223 public synchronized void mouseClicked( final com.jogamp.newt.event.MouseEvent event ) {
224 // Ignored, since we look for PRESS/RELEASE only!
225 // _eventCount++;
226 if( _debug ) {
227 _debugPrintStream.println( "MouseClicked ignored: "+event);
228 }
229 // _checkModifiers( event ) ;
230 }
231
232 @Override
233 public synchronized void mouseWheelMoved( final com.jogamp.newt.event.MouseEvent event ) {
234 // _eventCount++;
235 if( _debug ) {
236 _debugPrintStream.println( "MouseWheeleMoved ignored: "+event);
237 }
238 // _checkModifiers( event ) ;
239 }
240
241 @Override
242 public synchronized void mouseEntered( final com.jogamp.newt.event.MouseEvent event ) {
243 // _eventCount++;
244 if( _debug ) {
245 _debugPrintStream.println( "MouseEntered ignored: "+event);
246 }
247 // _checkModifiers( event ) ;
248 }
249
250 @Override
251 public synchronized void mouseExited( final com.jogamp.newt.event.MouseEvent event ) {
252 // _eventCount++;
253 if( _debug ) {
254 _debugPrintStream.println( "MouseExited ignored: "+event);
255 }
256 // _checkModifiers( event ) ;
257 }
258
259 }
260
261 ////////////////////////////////////////////////////////////////////////////
262
263 private static int _numButtonsToTest ;
264 private static int _awtButtonMasks[] ;
265
266 protected static java.awt.Robot _robot ;
267
268 protected static TestMouseListener _testMouseListener ;
269
270 ////////////////////////////////////////////////////////////////////////////
271
272 public static int getAWTButtonMask(final int button) {
273 // Java7: java.awt.event.InputEvent.getMaskForButton( n + 1 ) ; -> using InputEvent.BUTTON1_DOWN_MASK .. etc
274 // Java6: Only use BUTTON1_MASK, ..
275 int m;
276 switch(button) {
277 case 1 : m = java.awt.event.InputEvent.BUTTON1_MASK; break;
278 case 2 : m = java.awt.event.InputEvent.BUTTON2_MASK; break;
279 case 3 : m = java.awt.event.InputEvent.BUTTON3_MASK; break;
280 default: throw new IllegalArgumentException("Only buttons 1-3 have a MASK value, requested button "+button);
281 }
282 return m;
283 }
284
285 /**
286 * Must be called from subclass `@BeforeClass` code,
287 * allowing it to perform its specific initialization first.
288 * @throws Exception
289 */
290 public static void baseBeforeClass() throws Exception {
291
292 // Who know how many buttons the AWT will say exist on given platform.
293 // We'll test the smaller of what NEWT supports and what the
294 // AWT says is available.
295 /** Java7:
296 if( java.awt.Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() ) {
297 _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ;
298 } else {
299 _numButtonsToTest = 3 ;
300 } */
301 _numButtonsToTest = 3 ;
302
303 // Then again, maybe not:
304
305 // FIXME? - for reasons I'm not quite sure of the AWT MouseEvent
306 // constructor does some strange things for buttons other than
307 // 1, 2, and 3. Furthermore, while developing this test it
308 // appeared that events sent by the robot for buttons 9 and
309 // up weren't even delivered to the listeners.
310 //
311 // So... for now we're only going to test 3 buttons since
312 // that's the common case _and_ Java6 safe.
313
314 _numButtonsToTest = 3 ;
315
316 {
317 if( _numButtonsToTest > com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) {
318 _numButtonsToTest = com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ;
319 }
320
321 // These two arrays are assumed to be peers, i.e. are the same
322 // size, and a given index references the same button in
323 // either array.
324
325 _awtButtonMasks = new int[_numButtonsToTest] ;
326
327 for( int n = 0 ; n < _awtButtonMasks.length ; ++n ) {
328 _awtButtonMasks[n] = getAWTButtonMask( n + 1 );
329 }
330 }
331
332 _robot = new java.awt.Robot() ;
333 _robot.setAutoWaitForIdle( true ) ;
334
335 _testMouseListener = new TestMouseListener() ;
336 }
337
338 ////////////////////////////////////////////////////////////////////////////
339 // Following both methods are mandatory to deal with SWT's requirement
340 // to run the SWT event dispatch on the TK thread - which must be the main thread on OSX.
341 // We spawn off the actual test-action into another thread,
342 // while dispatching the events until the test-action is completed.
343 // YES: This is sort of ideal - NOT :)
344
345 protected void eventDispatch() {
346 try {
347 Thread.sleep(100);
348 } catch (final InterruptedException e) { }
349 }
350
351 private void execOffThreadWithOnThreadEventDispatch(final Runnable testAction) throws Exception {
352 _testMouseListener.setModifierCheckEnabled( false ) ;
353 _robot.setAutoDelay( MS_ROBOT_AUTO_DELAY ) ;
354 {
355 // Make sure all the buttons and modifier keys are released.
356 clearKeyboadAndMouse();
357 }
358 _testMouseListener.setModifierCheckEnabled( true ) ;
359
360 // final Object sync = new Object();
361 final RunnableTask rt = new RunnableTask( testAction, null, true, System.err );
362 try {
363 // synchronized(sync) {
364 new InterruptSource.Thread(null, rt, "Test-Thread").start();
365 int i=0;
366 while( rt.isInQueue() ) {
367 System.err.println("WAIT-till-done: eventDispatch() #"+i++);
368 eventDispatch();
369 }
370 final Throwable throwable = rt.getThrowable();
371 if(null!=throwable) {
372 throw new RuntimeException(throwable);
373 }
374 // }
375 } finally {
376 System.err.println("WAIT-till-done: DONE");
377 _testMouseListener.setModifierCheckEnabled( false ) ;
378 clearKeyboadAndMouse();
379 }
380 }
381
382 ////////////////////////////////////////////////////////////////////////////
383
384 // The approach on all these tests is to tell the test mouse listener what
385 // modifiers we think it should receive. Then when the events are delivered
386 // it compares what we told it to expect with what actually showed up and
387 // complains if there are differences.
388 //
389 // As things stand currently the tests below generally work for AWTCanvas
390 // and fail for everything else. This may point to a flaw in the test
391 // code, or a flaw in the NEWT stuff; not sure yet. One exception is the
392 // tests involving ALT and META, which on at least X11 cause the desktop
393 // to do undesirable stuff while the tests are in progress. So... these
394 // tests have been commented out for now and probably should be left
395 // that way.
396 //
397 // Due to the fact that a majority of these fail currently for
398 // everything but AWTCanvas for the time being we probably shouldn't
399 // run the tests for NewtCanvasAWT and NewtCanvasSWT until we can
400 // pay more attention to the NEWT event modifier stuff.
401
402 @Test(timeout=180000) // TO 3 min
403 public void test01SingleButtonPressAndRelease() throws Exception {
404 execOffThreadWithOnThreadEventDispatch(new Runnable() {
405 @Override
406 public void run() {
407 try {
408 _doSingleButtonPressAndRelease( 0, 0 );
409 } catch (final Exception e) { throw new RuntimeException(e); }
410 } } );
411 }
412
413 @Test(timeout=180000) // TO 3 min
414 public void test02SingleButtonPressAndReleaseWithShift() throws Exception {
415 execOffThreadWithOnThreadEventDispatch(new Runnable() {
416 @Override
417 public void run() {
418 try {
419 _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_SHIFT, java.awt.event.InputEvent.SHIFT_DOWN_MASK ) ;
420 } catch (final Exception e) { throw new RuntimeException(e); }
421 } } );
422 }
423
424 @Test(timeout=180000) // TO 3 min
425 public void test03SingleButtonPressAndReleaseWithCtrl() throws Exception {
426 execOffThreadWithOnThreadEventDispatch(new Runnable() {
427 @Override
428 public void run() {
429 try {
430 _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_CONTROL, java.awt.event.InputEvent.CTRL_DOWN_MASK ) ;
431 } catch (final Exception e) { throw new RuntimeException(e); }
432 } } );
433 }
434
435 /**
436 * The META and ALT tests get too tied up with functions of the window system on X11,
437 * so it's probably best to leave them commented out.
438 @Test(timeout=180000) // TO 3 min
439 public void test04SingleButtonPressAndReleaseWithMeta() throws Exception {
440 execOffThreadWithOnThreadEventDispatch(new Runnable() {
441 public void run() {
442 try {
443 _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_META, java.awt.event.InputEvent.META_DOWN_MASK ) ;
444 } catch (Exception e) { throw new RuntimeException(e); }
445 } } );
446 }
447
448 @Test(timeout=180000) // TO 3 min
449 public void test05SingleButtonPressAndReleaseWithAlt() throws Exception {
450 execOffThreadWithOnThreadEventDispatch(new Runnable() {
451 public void run() {
452 try {
453 _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT, java.awt.event.InputEvent.ALT_DOWN_MASK ) ;
454 } catch (Exception e) { throw new RuntimeException(e); }
455 } } );
456 }
457 */
458
459 /**
460 * FIXME - not sure yet what's up with ALT_GRAPH. It appears that this
461 * modifier didn't make it through, so I had to disable this test else it would always fail.
462 *
463 * My US keyboard doesn't have an AltGr key, so maybe X is smart
464 * enough to not let this modifier slip through (?).
465 @Test
466 public void test06SingleButtonPressAndReleaseWithAltGraph() throws Exception {
467 execOffThreadWithOnThreadEventDispatch(new Runnable() {
468 public void run() {
469 try {
470 _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH, java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) ;
471 } catch (Exception e) { throw new RuntimeException(e); }
472 } } );
473 }
474 */
475
476 ////////////////////////////////////////////////////////////////////////////
477
478 @Test(timeout=180000) // TO 3 min
479 public void test10HoldOneButtonAndPressAnother() throws Exception {
480 execOffThreadWithOnThreadEventDispatch(new Runnable() {
481 @Override
482 public void run() {
483 try {
484 _doHoldOneButtonAndPressAnother( 0, 0 ) ;
485 } catch (final Exception e) { throw new RuntimeException(e); }
486 } } );
487 }
488
489 @Test(timeout=180000) // TO 3 min
490 public void test20PressAllButtonsInSequence() throws Exception {
491 execOffThreadWithOnThreadEventDispatch(new Runnable() {
492 @Override
493 public void run() {
494 try {
495 _doPressAllButtonsInSequence( 0, 0 ) ;
496 } catch (final Exception e) { throw new RuntimeException(e); }
497 } } );
498 }
499
500 @Test(timeout=180000) // TO 3 min
501 public void test30SingleButtonClickAndDrag() throws Exception {
502 execOffThreadWithOnThreadEventDispatch(new Runnable() {
503 @Override
504 public void run() {
505 try {
506 _doSingleButtonClickAndDrag( 0, 0 ) ;
507 } catch (final Exception e) { throw new RuntimeException(e); }
508 } } );
509 }
510
511 ////////////////////////////////////////////////////////////////////////////
512
513 private void _doSingleButtonPressAndRelease( final int keyCode, final int keyModifierMask ) throws Exception {
514
515 if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonPressAndRelease" ) ; }
516
517 _doKeyPress( keyCode ) ;
518
519 for (int n = 0 ; n < _numButtonsToTest ; ++n) {
520
521 final int awtButtonMask = _awtButtonMasks[n] ;
522
523 if( _debug ) { _debugPrintStream.println( "*** pressing button " + ( n + 1 ) ) ; }
524 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
525 _robot.mousePress( awtButtonMask ) ;
526 _checkFailures("mouse-press("+(n+1)+")", 1) ;
527
528 if( _debug ) { _debugPrintStream.println( "*** releasing button " + ( n + 1 ) ) ; }
529 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
530 _robot.mouseRelease( awtButtonMask ) ;
531 _checkFailures("mouse-release("+(n+1)+")", 1) ;
532 }
533
534 _doKeyRelease( keyCode ) ;
535 }
536
537 ////////////////////////////////////////////////////////////////////////////
538
539 private void _doHoldOneButtonAndPressAnother( final int keyCode, final int keyModifierMask ) throws Exception {
540
541 if( _debug ) { _debugPrintStream.println( "\n>>>> _doHoldOneButtonAndPressAnother" ) ; }
542
543 _doKeyPress( keyCode ) ;
544
545 for (int n = 0 ; n < _numButtonsToTest ; ++n) {
546
547 final int awtButtonMask = _awtButtonMasks[n] ;
548
549 if( _debug ) { _debugPrintStream.println( "*** pressing button " + ( n + 1 ) ) ; }
550 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
551 _robot.mousePress( awtButtonMask ) ;
552 _checkFailures("mouse-press("+(n+1)+")", 1) ;
553
554 for (int m = 0 ; m < _numButtonsToTest ; ++m) {
555
556 if( n != m ) {
557
558 if( _debug ) { _debugPrintStream.println( "*** pressing additional button " + ( m + 1 ) ) ; }
559 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask | _awtButtonMasks[m] ) ) ;
560 _robot.mousePress( _awtButtonMasks[m] ) ;
561 _checkFailures("mouse-press("+(n+1)+", "+(m+1)+")", 1) ;
562
563 if( _debug ) { _debugPrintStream.println( "*** releasing additional button " + ( m + 1 ) ) ; }
564 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask | _awtButtonMasks[m] ) ) ;
565 _robot.mouseRelease( _awtButtonMasks[m] ) ;
566 _checkFailures("mouse-release("+(n+1)+", "+(m+1)+")", 1) ;
567 }
568 }
569
570 if( _debug ) { _debugPrintStream.println( "*** releasing button " + ( n + 1 ) ) ; }
571 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
572 _robot.mouseRelease( awtButtonMask ) ;
573 _checkFailures("mouse-release("+(n+1)+")", 1);
574 }
575
576 _doKeyRelease( keyCode ) ;
577 }
578
579 ////////////////////////////////////////////////////////////////////////////
580
581 private void _doPressAllButtonsInSequence( final int keyCode, final int keyModifierMask ) throws Exception {
582
583 if( _debug ) { _debugPrintStream.println( "\n>>>> _doPressAllButtonsInSequence" ) ; }
584
585 _doKeyPress( keyCode ) ;
586
587 {
588 int cumulativeAwtModifiers = 0 ;
589
590 for (int n = 0 ; n < _numButtonsToTest ; ++n) {
591
592 cumulativeAwtModifiers |= _awtButtonMasks[n] ;
593
594 if( _debug ) { _debugPrintStream.println( "*** pressing button " + ( n + 1 ) ) ; }
595 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ;
596 _robot.mousePress( _awtButtonMasks[n] ) ;
597 _checkFailures("mouse-press("+(n+1)+")", 1) ;
598 }
599
600 for (int n = _numButtonsToTest - 1 ; n >= 0 ; --n) {
601
602 if( _debug ) { _debugPrintStream.println( "*** releasing button " + ( n + 1 ) ) ; }
603 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ;
604 _robot.mouseRelease( _awtButtonMasks[n] ) ;
605 _checkFailures("mouse-release("+(n+1)+")", 1) ;
606
607 cumulativeAwtModifiers &= ~_awtButtonMasks[n] ;
608 }
609 }
610
611 _doKeyRelease( keyCode ) ;
612 }
613
614 ////////////////////////////////////////////////////////////////////////////
615
616 private void _doSingleButtonClickAndDrag( final int keyCode, final int keyModifierMask ) throws Exception {
617
618 if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonClickAndDrag" ) ; }
619
620 _doKeyPress( keyCode ) ;
621
622 _testMouseListener.setModifierCheckEnabled( true ) ;
623
624 for (int n = 0 ; n < _numButtonsToTest ; ++n) {
625
626 final int awtButtonMask = _awtButtonMasks[n] ;
627
628 if( _debug ) { _debugPrintStream.println( "*** pressing button " + ( n + 1 ) ) ; }
629 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
630 _robot.mousePress( awtButtonMask ) ;
631 _checkFailures("mouse-press("+(n+1)+")", 1) ;
632
633 // To get a drag we only need to move one pixel.
634 if( _debug ) { _debugPrintStream.println( "*** moving mouse" ) ; }
635 final int newX = INITIAL_MOUSE_X + 8, newY = INITIAL_MOUSE_Y + 8;
636 _robot.mouseMove( newX, newY ) ;
637 _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY);
638 _checkFailures("mouse-move("+newX+", "+newY+")", 1) ;
639
640 if( _debug ) { _debugPrintStream.println( "*** releasing button " + ( n + 1 ) ) ; }
641 _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ;
642 _robot.mouseRelease( awtButtonMask ) ;
643 _checkFailures("mouse-release("+(n+1)+")", 1) ;
644
645 _testMouseListener.setModifierCheckEnabled( false ) ;
646 _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ;
647 _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY);
648 _testMouseListener.setModifierCheckEnabled( true ) ;
649 }
650
651 _doKeyRelease( keyCode ) ;
652 }
653
654 ////////////////////////////////////////////////////////////////////////////
655
656 private void _doKeyPress( final int keyCode ) {
657 AWTRobotUtil.validateAWTEDTIsAlive();
658 if( keyCode != 0 ) {
659 final boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ;
660 _testMouseListener.setModifierCheckEnabled( false ) ;
661 _robot.keyPress( keyCode ) ;
662 _robot.delay(MS_ROBOT_KEY_PRESS_DELAY);
663 _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ;
664 }
665 }
666
667 ////////////////////////////////////////////////////////////////////////////
668
669 private void _doKeyRelease( final int keyCode ) {
670 AWTRobotUtil.validateAWTEDTIsAlive();
671 if( keyCode != 0 ) {
672 final boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ;
673 _testMouseListener.setModifierCheckEnabled( false ) ;
674 _robot.keyRelease( keyCode ) ;
675 _robot.delay(MS_ROBOT_KEY_RELEASE_DELAY);
676 _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ;
677 }
678 }
679
680 ////////////////////////////////////////////////////////////////////////////
681
682 private void _checkFailures(final String descr, final int waitEventCount) {
683 final ArrayList<String> failures = _testMouseListener.getFailures(waitEventCount) ;
684
685 _debugPrintStream.print(getSimpleTestName(".")+" - "+descr+": ");
686 final int numFailures = failures.size() ;
687 if( numFailures == 0 ) {
688 _debugPrintStream.println( " PASSED" ) ;
689 } else {
690 _debugPrintStream.println( " FAILED" ) ;
691 for( int n = 0 ; n < numFailures ; ++n ) {
692 _debugPrintStream.print( " " ) ;
693 _debugPrintStream.println( failures.get(n) ) ;
694 }
695 }
696
697 Assert.assertTrue( failures.size() == 0 ) ;
698 }
699
700 ////////////////////////////////////////////////////////////////////////////
701
702 public void eventDispatchedPostTestDelay() throws Exception {
703 eventDispatch(); eventDispatch(); eventDispatch();
704 Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ;
705 eventDispatch(); eventDispatch(); eventDispatch();
706 _testMouseListener.clear();
707 }
708
709 public void clearKeyboadAndMouse() throws Exception {
710 // Make sure all modifiers are released, otherwise the user's
711 // desktop can get locked up (ask me how I know this).
712 _releaseModifiers() ;
713 _escape() ;
714 eventDispatchedPostTestDelay();
715 }
716
717 ////////////////////////////////////////////////////////////////////////////
718
719 private void _releaseModifiers() {
720
721 if (_robot != null) {
723
724 _robot.setAutoDelay( MS_ROBOT_AUTO_DELAY ) ;
725
726 final boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ;
727 _testMouseListener.setModifierCheckEnabled( false ) ;
728
729 {
730 _robot.keyRelease( java.awt.event.KeyEvent.VK_SHIFT ) ;
731 _robot.keyRelease( java.awt.event.KeyEvent.VK_CONTROL ) ;
732 // _robot.keyRelease( java.awt.event.KeyEvent.VK_META ) ;
733 // _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT ) ;
734 // _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH ) ;
735
736 for (int n = 0 ; n < _awtButtonMasks.length ; ++n) {
737 _robot.mouseRelease( _awtButtonMasks[n] ) ;
738 }
739 }
740
741 _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ;
742 }
743 }
744
745 private void _escape() {
746 if (_robot != null) {
747 AWTRobotUtil.validateAWTEDTIsAlive();
748 _robot.keyPress( java.awt.event.KeyEvent.VK_ESCAPE ) ;
749 _robot.keyRelease( java.awt.event.KeyEvent.VK_ESCAPE ) ;
750 }
751 }
752
753 ////////////////////////////////////////////////////////////////////////////
754
755 /**
756 * Brute force method to return the NEWT event modifiers equivalent
757 * to the specified AWT event extended modifiers.
758 *
759 * @param awtExtendedModifiers
760 * The AWT extended modifiers.
761 *
762 * @return
763 * The equivalent NEWT modifiers.
764 */
765
766 private int _getNewtModifiersForAwtExtendedModifiers( final int awtExtendedModifiers ) {
767
768 int mask = 0 ;
769
770 if( ( awtExtendedModifiers & java.awt.event.InputEvent.SHIFT_DOWN_MASK ) != 0 ) {
771 mask |= com.jogamp.newt.event.InputEvent.SHIFT_MASK ;
772 }
773
774 if( ( awtExtendedModifiers & java.awt.event.InputEvent.CTRL_DOWN_MASK ) != 0 ) {
775 mask |= com.jogamp.newt.event.InputEvent.CTRL_MASK ;
776 }
777
778 if( ( awtExtendedModifiers & java.awt.event.InputEvent.META_DOWN_MASK ) != 0 ) {
779 mask |= com.jogamp.newt.event.InputEvent.META_MASK ;
780 }
781
782 if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_DOWN_MASK ) != 0 ) {
783 mask |= com.jogamp.newt.event.InputEvent.ALT_MASK ;
784 }
785
786 if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) != 0 ) {
787 mask |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ;
788 }
789
790 for (int n = 0 ; n < _numButtonsToTest ; ++n) {
791 if ((awtExtendedModifiers & getAWTButtonMask(n+1)) != 0) {
792 mask |= com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ;
793 }
794 }
795
796 return mask ;
797 }
798
799 ////////////////////////////////////////////////////////////////////////////
800}
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
Test whether or not event modifiers are preserved by NEWT.
static void baseBeforeClass()
Must be called from subclass @BeforeClass code, allowing it to perform its specific initialization fi...
static void validateAWTEDTIsAlive()
Throws Error if isAWTEDTAlive() returns false.