< prev index next >

tests/system/src/test/java/test/robot/com/sun/glass/ui/monocle/TestApplication.java

Print this page
rev 9504 : need to fix test log and others


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.robot.com.sun.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.TestLog;
  29 import com.sun.glass.ui.Robot;
  30 import com.sun.glass.ui.monocle.TouchInputShim;
  31 import javafx.animation.AnimationTimer;
  32 import javafx.application.Application;
  33 import javafx.application.Platform;
  34 import javafx.event.EventHandler;
  35 import javafx.geometry.Rectangle2D;
  36 import javafx.scene.Group;
  37 import javafx.scene.Scene;
  38 import javafx.scene.input.TouchEvent;
  39 import javafx.scene.input.TouchPoint;
  40 import javafx.scene.paint.Color;
  41 import javafx.scene.shape.Rectangle;
  42 import javafx.stage.Screen;
  43 import javafx.stage.Stage;
  44 import javafx.stage.StageStyle;
  45 import org.junit.Assert;
  46 
  47 import java.util.List;
  48 import java.util.concurrent.CountDownLatch;


 189 
 190     private static void frameWait(int n) {
 191         final CountDownLatch frameCounter = new CountDownLatch(n);
 192         Platform.runLater(() -> new AnimationTimer() {
 193             @Override
 194             public void handle(long now) {
 195                 frameCounter.countDown();
 196                 if (frameCounter.getCount() == 0l) {
 197                     stop();
 198                 }
 199             }
 200         }.start());
 201         try {
 202             frameCounter.await();
 203         } catch (InterruptedException ex) {
 204             Assert.fail("Unexpected exception: " + ex);
 205         }
 206     }
 207 
 208     public static void addKeyListeners() throws Exception {
 209         getStage().getScene().setOnKeyTyped((e) -> TestLog.log(
 210                 "Key typed: " + e.getCharacter()));
 211         getStage().getScene().setOnKeyPressed((e) -> TestLog.log("Key pressed: " + e.getCode()));
 212         getStage().getScene().setOnKeyReleased((e) -> TestLog.log("Key released: " + e.getCode()));
 213     }
 214 
 215     public static void addMouseListeners() throws Exception {
 216         getStage().getScene().setOnMousePressed((e) -> TestLog.log("Mouse pressed: "
 217                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 218         getStage().getScene().setOnMouseMoved((e) -> TestLog.log("Mouse moved: "
 219                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 220         getStage().getScene().setOnMouseDragged((e) -> TestLog.log("Mouse dragged: "
 221                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 222         getStage().getScene().setOnMouseReleased((e) -> TestLog.log("Mouse released: "
 223                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 224         getStage().getScene().setOnMouseClicked((e) -> TestLog.log("Mouse clicked: "
 225                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 226         getStage().getScene().setOnMouseEntered((e) -> TestLog.log("Mouse entered: "
 227                             + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 228         getStage().getScene().setOnMouseExited((e) -> TestLog.log("Mouse exited: "
 229                             + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 230     }
 231 
 232     public static void addTouchListeners() throws Exception {
 233         Consumer<List<TouchPoint>> logTouchPoints = (tps) -> {
 234             TestLog.log("Touch points count: [" + tps.size() +"]"); 
 235             for (TouchPoint tp : tps) {
 236                 TestLog.log("TouchPoint: " + tp.getState() + " "
 237                         + (int) tp.getScreenX() + ", " + (int) tp.getScreenY()
 238                         + " id=" + tp.getId());
 239             }
 240         };
 241         getStage().getScene().setOnTouchPressed((e) -> {
 242             TestLog.log("Touch pressed: "
 243                     + (int) e.getTouchPoint().getScreenX()
 244                     + ", "
 245                     + (int) e.getTouchPoint().getScreenY());
 246             logTouchPoints.accept(e.getTouchPoints());
 247         });
 248         getStage().getScene().setOnTouchReleased((e) -> {
 249             TestLog.log("Touch released: "
 250                     + (int) e.getTouchPoint().getScreenX()
 251                     + ", "
 252                     + (int) e.getTouchPoint().getScreenY());
 253             logTouchPoints.accept(e.getTouchPoints());
 254         });
 255         getStage().getScene().setOnTouchMoved((e) -> {
 256             TestLog.log("Touch moved: "
 257                     + (int) e.getTouchPoint().getScreenX()
 258                     + ", "
 259                     + (int) e.getTouchPoint().getScreenY());
 260             logTouchPoints.accept(e.getTouchPoints());
 261         });
 262         getStage().getScene().setOnTouchStationary((e) -> {
 263             TestLog.log("Touch stationary: "
 264                     + (int) e.getTouchPoint().getScreenX()
 265                     + ", "
 266                     + (int) e.getTouchPoint().getScreenY());
 267             logTouchPoints.accept(e.getTouchPoints());
 268         });
 269     }
 270 
 271     public static void addGestureListeners() throws Exception {
 272         //Zoom
 273         getStage().getScene().setOnZoom((e) -> TestLog.log("Zoom, factor: " + e.getZoomFactor()
 274                 + ", total factor: " + e.getTotalZoomFactor()
 275                 + ", inertia value: " + e.isInertia()));
 276 
 277         getStage().getScene().setOnZoomStarted((e) -> TestLog.log("Zoom started, factor: " + e.getZoomFactor()
 278                 + ", total factor: " + e.getTotalZoomFactor()
 279                 + ", inertia value: " + e.isInertia()));
 280 
 281         getStage().getScene().setOnZoomFinished((e) -> TestLog.log("Zoom finished, factor: " + e.getZoomFactor()
 282                 + ", total factor: " + e.getTotalZoomFactor()
 283                 + ", inertia value: " + e.isInertia()));
 284 
 285         //Rotate
 286         getStage().getScene().setOnRotate((e) -> TestLog.log("Rotation, angle: " + Math.round(e.getAngle())
 287                 + ", total angle: " + Math.round(e.getTotalAngle())
 288                 + ", inertia value: " + e.isInertia()));
 289 
 290         getStage().getScene().setOnRotationStarted((e) -> TestLog.log("Rotation started, angle: " + Math.round(e.getAngle())
 291                 + ", total angle: " + Math.round(e.getTotalAngle())
 292                 + ", inertia value: " + e.isInertia()));
 293 
 294         getStage().getScene().setOnRotationFinished((e) -> TestLog.log("Rotation finished, angle: " + Math.round(e.getAngle())
 295                 + ", total angle: " + Math.round(e.getTotalAngle())
 296                 + ", inertia value: " + e.isInertia()));
 297 
 298         //Scroll
 299         getStage().getScene().setOnScroll((e) -> TestLog.log("Scroll, DeltaX: " + Math.round(e.getDeltaX())
 300                 + ", DeltaY: " + Math.round(e.getDeltaY())
 301                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 302                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 303                 + ", touch points: " + e.getTouchCount()
 304                 + ", inertia value: " + e.isInertia()));
 305 
 306         getStage().getScene().setOnScrollStarted((e) -> TestLog.log("Scroll started, DeltaX: " + Math.round(e.getDeltaX())
 307                 + ", DeltaY: " + Math.round(e.getDeltaY())
 308                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 309                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 310                 + ", touch points: " + e.getTouchCount()
 311                 + ", inertia value: " + e.isInertia()));
 312 
 313         getStage().getScene().setOnScrollFinished((e) -> TestLog.log("Scroll finished, DeltaX: " + Math.round(e.getDeltaX())
 314                 + ", DeltaY: " + Math.round(e.getDeltaY())
 315                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 316                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 317                 + ", touch points: " + e.getTouchCount()
 318                 + ", inertia value: " + e.isInertia()));
 319     }
 320 
 321     public static void movePointerTo(final int targetX, final int targetY) throws Exception {
 322         final Semaphore released = new Semaphore(0);
 323         EventHandler<TouchEvent> touchHandler = (e) -> released.release();
 324         getStage().addEventHandler(TouchEvent.TOUCH_RELEASED, touchHandler);
 325         final UInput ui = new UInput();
 326         ui.processLine("OPEN");
 327         ui.processLine("VENDOR 0x596");
 328         ui.processLine("PRODUCT 0x502");
 329         ui.processLine("VERSION 1");
 330         ui.processLine("EVBIT EV_SYN");
 331         ui.processLine("EVBIT EV_KEY");
 332         ui.processLine("KEYBIT BTN_TOUCH");
 333         ui.processLine("EVBIT EV_ABS");


 345         ui.processLine("PROPERTY ID_INPUT_TOUCHSCREEN 1");
 346         ui.processLine("CREATE");
 347         Rectangle2D r = Screen.getPrimary().getBounds();
 348         int x = (int) ((targetX * 4096.0) / r.getWidth());
 349         int y = (int) ((targetY * 4096.0) / r.getHeight());
 350         ui.processLine("EV_ABS ABS_X " + x);
 351         ui.processLine("EV_ABS ABS_Y " + y);
 352         ui.processLine("EV_ABS ABS_PRESSURE 1");
 353         ui.processLine("EV_KEY BTN_TOUCH 1");
 354         ui.processLine("EV_SYN");
 355         ui.processLine("EV_ABS ABS_X " + x);
 356         ui.processLine("EV_ABS ABS_Y " + y);
 357         ui.processLine("EV_ABS ABS_PRESSURE 0");
 358         ui.processLine("EV_KEY BTN_TOUCH 0");
 359         ui.processLine("EV_SYN");
 360         try {
 361             Assert.assertTrue(released.tryAcquire(3, TimeUnit.SECONDS));
 362             TestRunnable.invokeAndWait(() -> {
 363                 Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
 364                 try {
 365                     TestLog.log("x = " + robot.getMouseX());
 366                     TestLog.log("y = " + robot.getMouseY());
 367                     TestLog.log("targetX = " + targetX);
 368                     TestLog.log("targetY = " + targetY);
 369                     Assert.assertEquals(targetX, robot.getMouseX());
 370                     Assert.assertEquals(targetY, robot.getMouseY());
 371                 } finally {
 372                     robot.destroy();
 373                 }
 374             });
 375             frameWait(1);
 376         } finally {
 377             getStage().removeEventHandler(TouchEvent.TOUCH_RELEASED, touchHandler);
 378             ui.processLine("DESTROY");
 379             ui.processLine("CLOSE");
 380             ui.dispose();
 381         }
 382         frameWait(1);
 383     }
 384 
 385     public static int getTapRadius() {
 386         return tapRadius;
 387     }
 388 




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.robot.com.sun.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.TestLogShim;
  29 import com.sun.glass.ui.Robot;
  30 import com.sun.glass.ui.monocle.TouchInputShim;
  31 import javafx.animation.AnimationTimer;
  32 import javafx.application.Application;
  33 import javafx.application.Platform;
  34 import javafx.event.EventHandler;
  35 import javafx.geometry.Rectangle2D;
  36 import javafx.scene.Group;
  37 import javafx.scene.Scene;
  38 import javafx.scene.input.TouchEvent;
  39 import javafx.scene.input.TouchPoint;
  40 import javafx.scene.paint.Color;
  41 import javafx.scene.shape.Rectangle;
  42 import javafx.stage.Screen;
  43 import javafx.stage.Stage;
  44 import javafx.stage.StageStyle;
  45 import org.junit.Assert;
  46 
  47 import java.util.List;
  48 import java.util.concurrent.CountDownLatch;


 189 
 190     private static void frameWait(int n) {
 191         final CountDownLatch frameCounter = new CountDownLatch(n);
 192         Platform.runLater(() -> new AnimationTimer() {
 193             @Override
 194             public void handle(long now) {
 195                 frameCounter.countDown();
 196                 if (frameCounter.getCount() == 0l) {
 197                     stop();
 198                 }
 199             }
 200         }.start());
 201         try {
 202             frameCounter.await();
 203         } catch (InterruptedException ex) {
 204             Assert.fail("Unexpected exception: " + ex);
 205         }
 206     }
 207 
 208     public static void addKeyListeners() throws Exception {
 209         getStage().getScene().setOnKeyTyped((e) -> TestLogShim.log(
 210                 "Key typed: " + e.getCharacter()));
 211         getStage().getScene().setOnKeyPressed((e) -> TestLogShim.log("Key pressed: " + e.getCode()));
 212         getStage().getScene().setOnKeyReleased((e) -> TestLogShim.log("Key released: " + e.getCode()));
 213     }
 214 
 215     public static void addMouseListeners() throws Exception {
 216         getStage().getScene().setOnMousePressed((e) -> TestLogShim.log("Mouse pressed: "
 217                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 218         getStage().getScene().setOnMouseMoved((e) -> TestLogShim.log("Mouse moved: "
 219                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 220         getStage().getScene().setOnMouseDragged((e) -> TestLogShim.log("Mouse dragged: "
 221                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 222         getStage().getScene().setOnMouseReleased((e) -> TestLogShim.log("Mouse released: "
 223                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 224         getStage().getScene().setOnMouseClicked((e) -> TestLogShim.log("Mouse clicked: "
 225                 + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 226         getStage().getScene().setOnMouseEntered((e) -> TestLogShim.log("Mouse entered: "
 227                             + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 228         getStage().getScene().setOnMouseExited((e) -> TestLogShim.log("Mouse exited: "
 229                             + (int) e.getScreenX() + ", " + (int) e.getScreenY()));
 230     }
 231 
 232     public static void addTouchListeners() throws Exception {
 233         Consumer<List<TouchPoint>> logTouchPoints = (tps) -> {
 234             TestLogShim.log("Touch points count: [" + tps.size() +"]"); 
 235             for (TouchPoint tp : tps) {
 236                 TestLogShim.log("TouchPoint: " + tp.getState() + " "
 237                         + (int) tp.getScreenX() + ", " + (int) tp.getScreenY()
 238                         + " id=" + tp.getId());
 239             }
 240         };
 241         getStage().getScene().setOnTouchPressed((e) -> {
 242             TestLogShim.log("Touch pressed: "
 243                     + (int) e.getTouchPoint().getScreenX()
 244                     + ", "
 245                     + (int) e.getTouchPoint().getScreenY());
 246             logTouchPoints.accept(e.getTouchPoints());
 247         });
 248         getStage().getScene().setOnTouchReleased((e) -> {
 249             TestLogShim.log("Touch released: "
 250                     + (int) e.getTouchPoint().getScreenX()
 251                     + ", "
 252                     + (int) e.getTouchPoint().getScreenY());
 253             logTouchPoints.accept(e.getTouchPoints());
 254         });
 255         getStage().getScene().setOnTouchMoved((e) -> {
 256             TestLogShim.log("Touch moved: "
 257                     + (int) e.getTouchPoint().getScreenX()
 258                     + ", "
 259                     + (int) e.getTouchPoint().getScreenY());
 260             logTouchPoints.accept(e.getTouchPoints());
 261         });
 262         getStage().getScene().setOnTouchStationary((e) -> {
 263             TestLogShim.log("Touch stationary: "
 264                     + (int) e.getTouchPoint().getScreenX()
 265                     + ", "
 266                     + (int) e.getTouchPoint().getScreenY());
 267             logTouchPoints.accept(e.getTouchPoints());
 268         });
 269     }
 270 
 271     public static void addGestureListeners() throws Exception {
 272         //Zoom
 273         getStage().getScene().setOnZoom((e) -> TestLogShim.log("Zoom, factor: " + e.getZoomFactor()
 274                 + ", total factor: " + e.getTotalZoomFactor()
 275                 + ", inertia value: " + e.isInertia()));
 276 
 277         getStage().getScene().setOnZoomStarted((e) -> TestLogShim.log("Zoom started, factor: " + e.getZoomFactor()
 278                 + ", total factor: " + e.getTotalZoomFactor()
 279                 + ", inertia value: " + e.isInertia()));
 280 
 281         getStage().getScene().setOnZoomFinished((e) -> TestLogShim.log("Zoom finished, factor: " + e.getZoomFactor()
 282                 + ", total factor: " + e.getTotalZoomFactor()
 283                 + ", inertia value: " + e.isInertia()));
 284 
 285         //Rotate
 286         getStage().getScene().setOnRotate((e) -> TestLogShim.log("Rotation, angle: " + Math.round(e.getAngle())
 287                 + ", total angle: " + Math.round(e.getTotalAngle())
 288                 + ", inertia value: " + e.isInertia()));
 289 
 290         getStage().getScene().setOnRotationStarted((e) -> TestLogShim.log("Rotation started, angle: " + Math.round(e.getAngle())
 291                 + ", total angle: " + Math.round(e.getTotalAngle())
 292                 + ", inertia value: " + e.isInertia()));
 293 
 294         getStage().getScene().setOnRotationFinished((e) -> TestLogShim.log("Rotation finished, angle: " + Math.round(e.getAngle())
 295                 + ", total angle: " + Math.round(e.getTotalAngle())
 296                 + ", inertia value: " + e.isInertia()));
 297 
 298         //Scroll
 299         getStage().getScene().setOnScroll((e) -> TestLogShim.log("Scroll, DeltaX: " + Math.round(e.getDeltaX())
 300                 + ", DeltaY: " + Math.round(e.getDeltaY())
 301                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 302                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 303                 + ", touch points: " + e.getTouchCount()
 304                 + ", inertia value: " + e.isInertia()));
 305 
 306         getStage().getScene().setOnScrollStarted((e) -> TestLogShim.log("Scroll started, DeltaX: " + Math.round(e.getDeltaX())
 307                 + ", DeltaY: " + Math.round(e.getDeltaY())
 308                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 309                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 310                 + ", touch points: " + e.getTouchCount()
 311                 + ", inertia value: " + e.isInertia()));
 312 
 313         getStage().getScene().setOnScrollFinished((e) -> TestLogShim.log("Scroll finished, DeltaX: " + Math.round(e.getDeltaX())
 314                 + ", DeltaY: " + Math.round(e.getDeltaY())
 315                 + ", totalDeltaX: " + Math.round(e.getTotalDeltaX())
 316                 + ", totalDeltaY: " + Math.round(e.getTotalDeltaY())
 317                 + ", touch points: " + e.getTouchCount()
 318                 + ", inertia value: " + e.isInertia()));
 319     }
 320 
 321     public static void movePointerTo(final int targetX, final int targetY) throws Exception {
 322         final Semaphore released = new Semaphore(0);
 323         EventHandler<TouchEvent> touchHandler = (e) -> released.release();
 324         getStage().addEventHandler(TouchEvent.TOUCH_RELEASED, touchHandler);
 325         final UInput ui = new UInput();
 326         ui.processLine("OPEN");
 327         ui.processLine("VENDOR 0x596");
 328         ui.processLine("PRODUCT 0x502");
 329         ui.processLine("VERSION 1");
 330         ui.processLine("EVBIT EV_SYN");
 331         ui.processLine("EVBIT EV_KEY");
 332         ui.processLine("KEYBIT BTN_TOUCH");
 333         ui.processLine("EVBIT EV_ABS");


 345         ui.processLine("PROPERTY ID_INPUT_TOUCHSCREEN 1");
 346         ui.processLine("CREATE");
 347         Rectangle2D r = Screen.getPrimary().getBounds();
 348         int x = (int) ((targetX * 4096.0) / r.getWidth());
 349         int y = (int) ((targetY * 4096.0) / r.getHeight());
 350         ui.processLine("EV_ABS ABS_X " + x);
 351         ui.processLine("EV_ABS ABS_Y " + y);
 352         ui.processLine("EV_ABS ABS_PRESSURE 1");
 353         ui.processLine("EV_KEY BTN_TOUCH 1");
 354         ui.processLine("EV_SYN");
 355         ui.processLine("EV_ABS ABS_X " + x);
 356         ui.processLine("EV_ABS ABS_Y " + y);
 357         ui.processLine("EV_ABS ABS_PRESSURE 0");
 358         ui.processLine("EV_KEY BTN_TOUCH 0");
 359         ui.processLine("EV_SYN");
 360         try {
 361             Assert.assertTrue(released.tryAcquire(3, TimeUnit.SECONDS));
 362             TestRunnable.invokeAndWait(() -> {
 363                 Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
 364                 try {
 365                     TestLogShim.log("x = " + robot.getMouseX());
 366                     TestLogShim.log("y = " + robot.getMouseY());
 367                     TestLogShim.log("targetX = " + targetX);
 368                     TestLogShim.log("targetY = " + targetY);
 369                     Assert.assertEquals(targetX, robot.getMouseX());
 370                     Assert.assertEquals(targetY, robot.getMouseY());
 371                 } finally {
 372                     robot.destroy();
 373                 }
 374             });
 375             frameWait(1);
 376         } finally {
 377             getStage().removeEventHandler(TouchEvent.TOUCH_RELEASED, touchHandler);
 378             ui.processLine("DESTROY");
 379             ui.processLine("CLOSE");
 380             ui.dispose();
 381         }
 382         frameWait(1);
 383     }
 384 
 385     public static int getTapRadius() {
 386         return tapRadius;
 387     }
 388 


< prev index next >