rev 9504 : need to fix test log and others

   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.TestLogShim;
  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.scene.Group;
  33 import javafx.scene.Scene;
  34 import javafx.scene.shape.Rectangle;
  35 import org.junit.Assert;
  36 import org.junit.Assume;
  37 import org.junit.Ignore;
  38 import org.junit.Test;
  39 import org.junit.runners.Parameterized;
  40 
  41 import java.util.Collection;
  42 import test.com.sun.glass.ui.monocle.TestRunnable;
  43 
  44 public class SingleTouchTest extends ParameterizedTestBase {
  45 
  46     public SingleTouchTest(TestTouchDevice device) {
  47         super(device);
  48     }
  49 
  50     @Parameterized.Parameters
  51     public static Collection<Object[]> data() {
  52         return TestTouchDevices.getTouchDeviceParameters(1);
  53     }
  54 
  55     /**
  56      * Touch down and up
  57      */
  58     @Test
  59     public void tap() throws Exception {
  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         TestLogShim.waitForLog("Mouse pressed: %d, %d", x, y);
  69         TestLogShim.waitForLog("Mouse released: %d, %d", x, y);
  70         TestLogShim.waitForLog("Mouse clicked: %d, %d", x, y);
  71         TestLogShim.waitForLog("Touch pressed: %d, %d", x, y);
  72         TestLogShim.waitForLog("Touch released: %d, %d", x, y);
  73 
  74         // Check that the touch event has one touch point.
  75         Assert.assertEquals("Expected only one touch point", 0,
  76                             TestLogShim.getLog().stream()
  77                             .filter(s -> s.startsWith("Touch points count"))
  78                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
  79     }
  80 
  81     /**
  82      * Touch down, send repeat events in the same location, touch up
  83      */
  84     @Test
  85     public void tapHoldRelease() throws Exception {
  86         final int x = (int) Math.round(width * 0.5);
  87         final int y = (int) Math.round(height * 0.5);
  88         // tap
  89         int p = device.addPoint(x, y);
  90         device.sync();
  91         TestLogShim.waitForLog("Mouse pressed: %d, %d", x, y);
  92         TestLogShim.waitForLog("Touch pressed: %d, %d", x, y);
  93         TestLogShim.reset();
  94         // hold
  95         device.resendStateAndSync();
  96         device.sync();
  97         // release
  98         device.removePoint(p);
  99         device.sync();
 100         TestLogShim.waitForLog("Mouse released: %d, %d", x, y);
 101         TestLogShim.waitForLog("Mouse clicked: %d, %d", x, y);
 102         TestLogShim.waitForLog("Touch released: %d, %d", x, y);
 103         // We don't have anything sensible to do with repeat events in the
 104         // same location, so make sure they are filtered out.
 105         Assert.assertEquals(0, TestLogShim.countLogContaining("Mouse pressed:"));
 106         Assert.assertEquals(0, TestLogShim.countLogContaining("Touch pressed:"));
 107         // Check that the touch event has one touch point.
 108         Assert.assertEquals("Expected only one touch point", 0,
 109                             TestLogShim.getLog().stream()
 110                             .filter(s -> s.startsWith("Touch points count"))
 111                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
 112     }
 113 
 114     /**
 115      * Touch down, drag, touch up
 116      */
 117     @Test
 118     public void tapAndDrag1() throws Exception {
 119         final int x1 = (int) Math.round(width * 0.5);
 120         final int y1 = (int) Math.round(height * 0.5);
 121         final int x2 = (int) Math.round(width * 0.75);
 122         final int y2 = (int) Math.round(height * 0.75);
 123         // tap
 124         int p = device.addPoint(x1, y1);
 125         device.sync();
 126         // drag
 127         device.setPoint(p, x2, y2);
 128         device.sync();
 129         // release
 130         device.removePoint(p);
 131         device.sync();
 132         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 133         TestLogShim.waitForLog("Mouse dragged: %d, %d", x2, y2);
 134         TestLogShim.waitForLog("Mouse released: %d, %d", x2, y2);
 135         TestLogShim.waitForLog("Mouse clicked: %d, %d", x2, y2);
 136         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 137         TestLogShim.waitForLog("Touch moved: %d, %d", x2, y2);
 138         TestLogShim.waitForLog("Touch released: %d, %d", x2, y2);
 139         // Check that the touch event has one touch point.
 140         Assert.assertEquals("Expected only one touch point", 0,
 141                             TestLogShim.getLog().stream()
 142                             .filter(s -> s.startsWith("Touch points count"))
 143                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
 144     }
 145 
 146     /**
 147      * Touch down, drag, touch up, with no change in Y coordinate
 148      */
 149     @Test
 150     public void tapAndDrag2() throws Exception {
 151         final int x1 = (int) Math.round(width * 0.5);
 152         final int y1 = (int) Math.round(height * 0.5);
 153         final int x2 = (int) Math.round(width * 0.75);
 154         // tap
 155         int p = device.addPoint(x1, y1);
 156         device.sync();
 157         // drag
 158         device.setPoint(p, x2, y1);
 159         device.sync();
 160         // release
 161         device.removePoint(p);
 162         device.sync();
 163         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 164         TestLogShim.waitForLog("Mouse dragged: %d, %d", x2, y1);
 165         TestLogShim.waitForLog("Mouse released: %d, %d", x2, y1);
 166         TestLogShim.waitForLog("Mouse clicked: %d, %d", x2, y1);
 167         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 168         TestLogShim.waitForLog("Touch moved: %d, %d", x2, y1);
 169         TestLogShim.waitForLog("Touch released: %d, %d", x2, y1);
 170         // Check that the touch event has one touch point.
 171         Assert.assertEquals("Expected only one touch point", 0,
 172                             TestLogShim.getLog().stream()
 173                             .filter(s -> s.startsWith("Touch points count"))
 174                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
 175     }
 176 
 177     /**
 178      * Touch down, drag, touch up, no change in X coordinate
 179      */
 180     @Test
 181     public void tapAndDrag3() throws Exception {
 182         final int x1 = (int) Math.round(width * 0.5);
 183         final int y1 = (int) Math.round(height * 0.5);
 184         final int y2 = (int) Math.round(height * 0.75);
 185         // tap
 186         int p = device.addPoint(x1, y1);
 187         device.sync();
 188         // drag
 189         device.setPoint(p, x1, y2);
 190         device.sync();
 191         // release
 192         device.removePoint(p);
 193         device.sync();
 194         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 195         TestLogShim.waitForLog("Mouse dragged: %d, %d", x1, y2);
 196         TestLogShim.waitForLog("Mouse released: %d, %d", x1, y2);
 197         TestLogShim.waitForLog("Mouse clicked: %d, %d", x1, y2);
 198         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 199         TestLogShim.waitForLog("Touch moved: %d, %d", x1, y2);
 200         TestLogShim.waitForLog("Touch released: %d, %d", x1, y2);
 201         // Check that the touch event has one touch point.
 202         Assert.assertEquals("Expected only one touch point", 0,
 203                             TestLogShim.getLog().stream()
 204                             .filter(s -> s.startsWith("Touch points count"))
 205                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
 206     }
 207 
 208     /**
 209      * Touch down, small drag, release. The drag should be filtered out.
 210      */
 211     @Test
 212     public void tapWithTinyDrag() throws Exception {
 213         Assume.assumeTrue(device.getTapRadius() > 1);
 214         final int x1 = (int) Math.round(width * 0.5);
 215         final int y1 = (int) Math.round(height * 0.5);
 216         final int x2 = x1 + 1;
 217         final int y2 = y1 + 1;
 218         // tap
 219         int p = device.addPoint(x1, y1);
 220         device.sync();
 221         // drag
 222         device.setPoint(p, x2, y2);
 223         device.sync();
 224         // release
 225         device.removePoint(p);
 226         device.sync();
 227         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 228         TestLogShim.waitForLog("Mouse released: %d, %d", x1, y1);
 229         TestLogShim.waitForLog("Mouse clicked: %d, %d", x1, y1);
 230         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 231         TestLogShim.waitForLog("Touch released: %d, %d", x1, y1);
 232         Assert.assertEquals(0l, TestLogShim.countLogContaining("Mouse dragged"));
 233         Assert.assertEquals(0l, TestLogShim.countLogContaining("Touch moved"));
 234         // Check that the touch event has one touch point.
 235         Assert.assertEquals("Expected only one touch point", 0,
 236                             TestLogShim.getLog().stream()
 237                             .filter(s -> s.startsWith("Touch points count"))
 238                             .filter(s -> !s.startsWith("Touch points count: [1]")).count());
 239     }
 240 
 241     /**
 242      * Touch down, drag, release, tap again
 243      */
 244     @Test
 245     public void tapDragReleaseTapAgain() throws Exception {
 246         Assume.assumeTrue(device.getTapRadius() < width * 0.2);
 247         final int x1 = (int) Math.round(width * 0.5);
 248         final int y1 = (int) Math.round(height * 0.5);
 249         final int x2 = (int) Math.round(width * 0.7);
 250         final int y2 = (int) Math.round(height * 0.7);
 251         // tap
 252         int p = device.addPoint(x1, y1);
 253         device.sync();
 254         // drag
 255         device.setPoint(p, x2, y2);
 256         device.sync();
 257         // release
 258         device.removePoint(p);
 259         device.sync();
 260         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 261         TestLogShim.waitForLog("Mouse released: %d, %d", x2, y2);
 262         TestLogShim.waitForLog("Mouse clicked: %d, %d", x2, y2);
 263         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 264         TestLogShim.waitForLog("Touch released: %d, %d", x2, y2);
 265         TestLogShim.clear();
 266         // tap again and release
 267         p = device.addPoint(x1, y1);
 268         device.sync();
 269         TestLogShim.waitForLog("Mouse pressed: %d, %d", x1, y1);
 270         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 271         TestLogShim.clear();
 272         device.removePoint(p);
 273         device.sync();
 274         TestLogShim.waitForLog("Mouse released: %d, %d", x1, y1);
 275         TestLogShim.waitForLog("Mouse clicked: %d, %d", x1, y1);
 276         TestLogShim.waitForLog("Touch released: %d, %d", x1, y1);
 277     }
 278         
 279     /**
 280      * Touch down, change scene, release finger.
 281      */
 282     @Ignore("RT-37283")
 283     @Test
 284     public void testChangeSceneDuringTap() throws Exception {
 285         final int x1 = (int) Math.round(width * 0.3);
 286         final int y1 = (int) Math.round(height * 0.3);
 287         int p1 = device.addPoint(x1, y1);
 288         device.sync();
 289         TestLogShim.waitForLog("Touch pressed: %d, %d", x1, y1);
 290         TestRunnable.invokeAndWait(() ->
 291         {
 292             Rectangle r = new Rectangle(0, 0, width, height);
 293             Group g = new Group();
 294             g.getChildren().add(r);
 295             Scene scene = new Scene(g);
 296             TestApplication.getStage().setScene(scene);
 297         });
 298         device.removePoint(p1);
 299         device.sync();
 300         Assert.assertEquals(1, TestLogShim.countLogContaining("Mouse clicked: " + x1 +", " + y1));
 301     }
 302 }
--- EOF ---