modules/graphics/src/test/java/test/javafx/scene/input/TouchEventTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   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 javafx.scene.input;
  27 
  28 import com.sun.javafx.pgstub.StubScene;
  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.Random;
  32 import javafx.event.Event;
  33 import javafx.scene.Group;
  34 import javafx.scene.Scene;
  35 import javafx.scene.shape.Rectangle;
  36 import javafx.stage.Stage;
  37 import javafx.event.EventHandler;
  38 import javafx.geometry.Point3D;




  39 import org.junit.Assert;
  40 import org.junit.Ignore;
  41 import org.junit.Test;
  42 import static org.junit.Assert.*;
  43 
  44 public class TouchEventTest {
  45     private static final int SANE_BENCHMARK_CYCLES = 1000000;
  46     private static final int CRAZY_BENCHMARK_CYCLES = 500000;
  47 
  48     private int touched;
  49 
  50     @Test public void testTouchPointConstructor() {
  51         Rectangle node = new Rectangle();
  52         node.setTranslateX(3);
  53         node.setTranslateY(2);
  54         node.setTranslateZ(50);
  55         PickResult pickRes = new PickResult(node, new Point3D(15, 25, 100), 33);
  56         TouchPoint tp = new TouchPoint(2, TouchPoint.State.STATIONARY,
  57                 10, 20, 30, 40, node, pickRes);
  58 


1539                 System.currentTimeMillis(), 1, false, false, false, false, false);
1540         ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
1541                 TouchPoint.State.PRESSED, 1368, 110, 110, 110, 110);
1542         ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
1543 
1544         ((StubScene) scene.impl_getPeer()).getListener().touchEventBegin(
1545                 System.currentTimeMillis(), 1, false, false, false, false, false);
1546         ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
1547                 TouchPoint.State.PRESSED, 1, 110, 110, 110, 110);
1548         ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
1549     }
1550 
1551     private Scene createScene() {
1552         final Group root = new Group();
1553 
1554         final Scene scene = new Scene(root, 400, 400);
1555 
1556         Rectangle rect = new Rectangle(100, 100, 100, 100);
1557         Rectangle rect2 = new Rectangle(200, 200, 100, 100);
1558 
1559         root.getChildren().addAll(rect, rect2);
1560 
1561         Stage stage = new Stage();
1562         stage.setScene(scene);
1563         stage.show();
1564 
1565         return scene;
1566     }
1567 
1568     @Test
1569     @Ignore("This is a benchmark, not any functional test. Run it individually if you wish.")
1570     public void saneOrderingBenchmark() {
1571         long[] ids = new long[] { 2, 3, 4, 5, 6 };
1572         boolean[] active = new boolean[] { false, false, false, false, false };
1573         int count = 0;
1574         int tick = 5;
1575         int available = 5;
1576         Random rand = new Random();
1577 
1578         Scene scene = createScene();
1579 




   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.javafx.scene.input;
  27 
  28 import test.com.sun.javafx.pgstub.StubScene;
  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.Random;
  32 import javafx.event.Event;
  33 import javafx.scene.Group;
  34 import javafx.scene.Scene;
  35 import javafx.scene.shape.Rectangle;
  36 import javafx.stage.Stage;
  37 import javafx.event.EventHandler;
  38 import javafx.geometry.Point3D;
  39 import javafx.scene.ParentShim;
  40 import javafx.scene.input.PickResult;
  41 import javafx.scene.input.TouchEvent;
  42 import javafx.scene.input.TouchPoint;
  43 import org.junit.Assert;
  44 import org.junit.Ignore;
  45 import org.junit.Test;
  46 import static org.junit.Assert.*;
  47 
  48 public class TouchEventTest {
  49     private static final int SANE_BENCHMARK_CYCLES = 1000000;
  50     private static final int CRAZY_BENCHMARK_CYCLES = 500000;
  51 
  52     private int touched;
  53 
  54     @Test public void testTouchPointConstructor() {
  55         Rectangle node = new Rectangle();
  56         node.setTranslateX(3);
  57         node.setTranslateY(2);
  58         node.setTranslateZ(50);
  59         PickResult pickRes = new PickResult(node, new Point3D(15, 25, 100), 33);
  60         TouchPoint tp = new TouchPoint(2, TouchPoint.State.STATIONARY,
  61                 10, 20, 30, 40, node, pickRes);
  62 


1543                 System.currentTimeMillis(), 1, false, false, false, false, false);
1544         ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
1545                 TouchPoint.State.PRESSED, 1368, 110, 110, 110, 110);
1546         ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
1547 
1548         ((StubScene) scene.impl_getPeer()).getListener().touchEventBegin(
1549                 System.currentTimeMillis(), 1, false, false, false, false, false);
1550         ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
1551                 TouchPoint.State.PRESSED, 1, 110, 110, 110, 110);
1552         ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
1553     }
1554 
1555     private Scene createScene() {
1556         final Group root = new Group();
1557 
1558         final Scene scene = new Scene(root, 400, 400);
1559 
1560         Rectangle rect = new Rectangle(100, 100, 100, 100);
1561         Rectangle rect2 = new Rectangle(200, 200, 100, 100);
1562 
1563         ParentShim.getChildren(root).addAll(rect, rect2);
1564 
1565         Stage stage = new Stage();
1566         stage.setScene(scene);
1567         stage.show();
1568 
1569         return scene;
1570     }
1571 
1572     @Test
1573     @Ignore("This is a benchmark, not any functional test. Run it individually if you wish.")
1574     public void saneOrderingBenchmark() {
1575         long[] ids = new long[] { 2, 3, 4, 5, 6 };
1576         boolean[] active = new boolean[] { false, false, false, false, false };
1577         int count = 0;
1578         int tick = 5;
1579         int available = 5;
1580         Random rand = new Random();
1581 
1582         Scene scene = createScene();
1583