1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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 test.robot.com.sun.glass.ui.monocle.TestApplication;
  30 import test.robot.com.sun.glass.ui.monocle.input.devices.TestTouchDevice;
  31 import test.robot.com.sun.glass.ui.monocle.input.devices.TestTouchDevices;
  32 import javafx.application.Platform;
  33 import javafx.scene.input.InputEvent;
  34 import org.junit.Test;
  35 import org.junit.runners.Parameterized;
  36 
  37 import java.util.Collection;
  38 
  39 public class TouchExceptionTest extends ParameterizedTestBase {
  40 
  41     public TouchExceptionTest(TestTouchDevice device) {
  42         super(device);
  43     }
  44 
  45     @Parameterized.Parameters
  46     public static Collection<Object[]> data() {
  47         return TestTouchDevices.getTouchDeviceParameters(1);
  48     }
  49 
  50     /** Throw an exception in an event handler */
  51     @Test
  52     public void testRuntimeException() throws Exception {
  53         Platform.runLater(
  54                 () -> Thread.currentThread()
  55                         .setUncaughtExceptionHandler((t, e) -> TestLog.log(e.toString()))
  56         );
  57         TestApplication.getStage().getScene().addEventHandler(
  58                 InputEvent.ANY,
  59                 (e) -> { throw new RuntimeException(e.toString()); });
  60         final int x = (int) Math.round(width * 0.5);
  61         final int y = (int) Math.round(height * 0.5);
  62         // tap
  63         int p = device.addPoint(x, y);
  64         device.sync();
  65         // release
  66         device.removePoint(p);
  67         device.sync();
  68         TestLog.waitForLog("Touch pressed: %d, %d", x, y);
  69         TestLog.waitForLog("Touch released: %d, %d", x, y);
  70     }
  71 }