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.TestLog;
  29 import test.robot.com.sun.glass.ui.monocle.ParameterizedTestBase;
  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 org.junit.*;
  33 import org.junit.runners.Parameterized;
  34 
  35 import java.util.Collection;
  36 
  37 /** Zoom tests with two touch points */
  38 public class ZoomTest extends ParameterizedTestBase {
  39 
  40     public ZoomTest(TestTouchDevice device) {
  41         super(device);
  42     }
  43 
  44     @Parameterized.Parameters
  45     public static Collection<Object[]> data() {
  46         return TestTouchDevices.getTouchDeviceParameters(2);
  47     }
  48 
  49     @Before
  50     public void verifyZoomEnabled() {
  51         Assume.assumeTrue(Boolean.getBoolean("com.sun.javafx.gestures.zoom"));
  52     }
  53 
  54     private void tapToStopInertia() throws Exception {
  55         int point1X = (int) Math.round(width * 0.1);
  56         int point1Y = (int) Math.round(height * 0.3);
  57         Assert.assertEquals(0, device.getPressedPoints());
  58         TestLog.reset();
  59         int p = device.addPoint(point1X, point1Y);
  60         device.sync();
  61         device.removePoint(p);
  62         device.sync();
  63         TestLog.waitForLog("Mouse clicked: %d, %d", point1X, point1Y);
  64     }
  65 
  66     /**
  67      * Touch down two fingers,
  68      * drag upper finger up in order move but not enough for zooming,
  69      * drag again to zoom in (make it twice bigger)
  70      */
  71     @Test
  72     public void testZoomInSmallStepBigStep() throws Exception {
  73         int x1 = (int) Math.round(width / 2);
  74         int y1 = (int) Math.round(height * 0.3);
  75         int x2 = (int) Math.round(width / 2);
  76         int y2 = (int) Math.round(height * 0.7);
  77         int step = (int) Math.round(height * 0.1);
  78         int smallStep = (int) device.getTapRadius() + 1;
  79         double threshold = 0;
  80         String s = System.getProperty("com.sun.javafx.gestures.zoom.threshold");
  81         if (s != null) {
  82             threshold = Double.valueOf(s);
  83         } else {
  84             threshold = 0.1;
  85         }
  86         Assume.assumeTrue(((y2 - y1) * threshold) > smallStep);
  87 
  88         TestLog.reset();
  89         //tap two fingers
  90         int p1 = device.addPoint(x1, y1);
  91         int p2 = device.addPoint(x2, y2);
  92         device.sync();
  93 
  94         //verify pressing two fingers
  95         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
  96         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
  97 
  98         //drag upper finger up in order move but not enough for zooming
  99         int newy1 = y1 - smallStep;
 100         int newy2 = 0;
 101         TestLog.reset();
 102         device.setPoint(p1, x1, newy1);
 103         device.sync();
 104 
 105         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 106         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 107         Assert.assertEquals(0, TestLog.countLogContaining("Zoom started"));
 108 
 109         //drag upper finger up and lower down in order to zoom in
 110         newy1 = y1 - step;
 111         newy2 = y2 + step;
 112         TestLog.reset();
 113         device.setPoint(p1, x1, newy1);
 114         device.setPoint(p2, x2, newy2);
 115         device.sync();
 116         double factor0 = 1.0;
 117         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 118 
 119         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 120         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 121         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 122                 + ", total factor: " + factor0  + ", inertia value: false");
 123         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 124                 + ", total factor: " + factor1 + ", inertia value: false");
 125 
 126         step = step * 2;
 127         newy1 = y1 - step;
 128         newy2 = y2 + step;
 129         TestLog.reset();
 130         device.setPoint(p1, x1, newy1);
 131         device.setPoint(p2, x2, newy2);
 132         device.sync();
 133         double factor2 = (double) (newy2 - newy1)/(y2 - y1 + step);
 134 
 135         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 136         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 137         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 138                 + ", total factor: " + (factor1 * factor2)
 139                 + ", inertia value: false");
 140 
 141         //release first finger
 142         TestLog.reset();
 143         device.removePoint(p1);
 144         device.sync();
 145         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, newy1);
 146         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, newy2);
 147         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 148                 + ", total factor: " + (factor1 * factor2)
 149                 + ", inertia value: false");
 150         //release second finger
 151         TestLog.reset();
 152         device.removePoint(p2);
 153         device.sync();
 154         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 155         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, newy2);
 156         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 157         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 158         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 159                 + x2 +", " + newy2));
 160         tapToStopInertia();
 161     }
 162 
 163     /**
 164      * Touch down two fingers, zoom in (make it twice bigger)
 165      */
 166     @Test
 167     public void testZoomIn() throws Exception {
 168         int x1 = (int) Math.round(width / 2);
 169         int y1 = (int) Math.round(height * 0.3);
 170         int x2 = (int) Math.round(width / 2);
 171         int y2 = (int) Math.round(height * 0.7);
 172         int step = (int) Math.round(height * 0.1);
 173 
 174         TestLog.reset();
 175         //tap two fingers
 176         int p1 = device.addPoint(x1, y1);
 177         int p2 = device.addPoint(x2, y2);
 178         device.sync();
 179 
 180         //verify pressing two fingers
 181         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 182         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 183 
 184         //drag upper finger up and lower down in order to zoom in
 185         int newy1 = y1 - step;
 186         int newy2 = y2 + step;
 187         TestLog.reset();
 188         device.setPoint(p1, x1, newy1);
 189         device.setPoint(p2, x2, newy2);
 190         device.sync();
 191         double factor0 = 1.0;
 192         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 193 
 194         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 195         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 196         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 197                 + ", total factor: " + factor0 + ", inertia value: false");
 198         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 199                 + ", total factor: " + factor1  + ", inertia value: false");
 200 
 201         step = step * 2;
 202         newy1 = y1 - step;
 203         newy2 = y2 + step;
 204         TestLog.reset();
 205         device.setPoint(p1, x1, newy1);
 206         device.setPoint(p2, x2, newy2);
 207         device.sync();
 208         double factor2 = (double) (newy2 - newy1)/(y2 - y1 + step);
 209 
 210         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 211         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 212         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 213                 + ", total factor: " + (factor1 * factor2)
 214                 + ", inertia value: false");
 215 
 216         //release first finger
 217         TestLog.reset();
 218         device.removePoint(p1);
 219         device.sync();
 220         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 221                 x1, newy1);
 222         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 223                 x2, newy2);
 224         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 225                 + ", total factor: " + (factor1 * factor2)
 226                 + ", inertia value: false");
 227 
 228         //release second finger
 229         TestLog.reset();
 230         device.removePoint(p2);
 231         device.sync();
 232         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 233         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 234                 x2, newy2);
 235         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 236         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 237         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 238                 + x2 +", " + newy2));
 239         tapToStopInertia();
 240     }
 241 
 242     /**
 243      * Touch down two fingers, zoom out (make it quarter of original size)
 244      */
 245     @Test
 246     public void testZoomOut() throws Exception {
 247         int x1 = (int) Math.round(width / 2);
 248         int y1 = (int) Math.round(height * 0.1);
 249         int x2 = (int) Math.round(width / 2);
 250         int y2 = (int) Math.round(height * 0.9);
 251         int step = (int) Math.round(height * 0.1);
 252         double factor0 = 1.0;
 253 
 254         //tap two fingers
 255         TestLog.reset();
 256         int p1 = device.addPoint(x1, y1);
 257         int p2 = device.addPoint(x2, y2);
 258         device.sync();
 259 
 260         //verify pressing two fingers
 261         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 262         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 263 
 264         //drag upper finger down and lower - up, in order to zoom out
 265         TestLog.reset();
 266         int newy1 = y1 + step;
 267         int newy2 = y2 - step;
 268         device.setPoint(p1, x1, newy1);
 269         device.setPoint(p2, x2, newy2);
 270         device.sync();
 271         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 272 
 273         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 274         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 275         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 276                 + ", total factor: " + factor0 + ", inertia value: false");
 277         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 278                 + ", total factor: " + factor1 + ", inertia value: false");
 279 
 280         TestLog.reset();
 281         y1 = y1 + step;
 282         y2 = y2 - step;
 283         newy1 = y1 + step;
 284         newy2 = y2 - step;
 285 
 286         device.setPoint(p1, x1, newy1);
 287         device.setPoint(p2, x2, newy2);
 288         device.sync();
 289         double factor2 = (double) (newy2 - newy1)/(y2 - y1);
 290 
 291         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 292         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 293         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 294                 + ", total factor: " + (factor1 * factor2)
 295                 + ", inertia value: false");
 296 
 297         TestLog.reset();
 298         y1 = y1 + step;
 299         y2 = y2 - step;
 300         newy1 = y1 + step;
 301         newy2 = y2 - step;
 302 
 303         device.setPoint(p1, x1, newy1);
 304         device.setPoint(p2, x2, newy2);
 305         device.sync();
 306         double factor3 = (double) (newy2 - newy1)/(y2 - y1);
 307 
 308         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 309         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 310         TestLog.waitForLogContaining("Zoom, factor: " + factor3
 311                 + ", total factor: " + (factor1 * factor2 * factor3)
 312                 + ", inertia value: false");
 313 
 314         //release first finger
 315         TestLog.reset();
 316         device.removePoint(p1);
 317         device.sync();
 318         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 319                 x1, newy1);
 320         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 321                 x2, newy2);
 322         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 323                 + ", total factor: " + (factor1 * factor2 * factor3)
 324                 + ", inertia value: false");
 325 
 326         //release second finger
 327         TestLog.reset();
 328         device.removePoint(p2);
 329         device.sync();
 330         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 331         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 332                 x2, newy2);
 333         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 334         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 335         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 336                 + x2 +", " + newy2));
 337         tapToStopInertia();
 338     }
 339 
 340     /**
 341      * Touch down two fingers,
 342      * drag upper finger down in order move but not enough for zooming,
 343      * drag again to zoom out (quarter of original size)
 344      */
 345     @Test
 346     public void testZoomOutSmallStepBigStep() throws Exception {
 347         int x1 = (int) Math.round(width / 2);
 348         int y1 = (int) Math.round(height * 0.1);
 349         int x2 = (int) Math.round(width / 2);
 350         int y2 = (int) Math.round(height * 0.9);
 351         int step = (int) Math.round(height * 0.1);
 352         int smallStep = (int) device.getTapRadius() + 1;
 353         double threshold = 0;
 354         String s = System.getProperty("com.sun.javafx.gestures.zoom.threshold");
 355         if (s != null) {
 356             threshold = Double.valueOf(s);
 357         } else {
 358             threshold = 0.1;
 359         }
 360         Assume.assumeTrue(((y2 - y1) * threshold) > smallStep);
 361         double factor0 = 1.0;
 362 
 363         TestLog.reset();
 364         //tap two fingers
 365         int p1 = device.addPoint(x1, y1);
 366         int p2 = device.addPoint(x2, y2);
 367         device.sync();
 368 
 369         //verify pressing two fingers
 370         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 371         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 372 
 373         //drag upper finger down in order move but not enough for zooming
 374         TestLog.reset();
 375         int newy1 = y1 + smallStep;
 376         int newy2 = 0;
 377 
 378         device.setPoint(p1, x1, newy1);
 379         device.sync();
 380 
 381         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 382         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 383         Assert.assertEquals(0, TestLog.countLogContaining("Zoom started"));
 384 
 385         //drag upper finger up and lower down in order to zoom in
 386         TestLog.reset();
 387         newy1 = y1 + step;
 388         newy2 = y2 - step;
 389         device.setPoint(p1, x1, newy1);
 390         device.setPoint(p2, x2, newy2);
 391         device.sync();
 392         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 393 
 394         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 395         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 396         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 397                 + ", total factor: " + factor0 + ", inertia value: false");
 398         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 399                 + ", total factor: " + factor1 + ", inertia value: false");
 400         TestLog.reset();
 401         y1 = y1 + step;
 402         y2 = y2 - step;
 403         newy1 = y1 + step;
 404         newy2 = y2 - step;
 405         device.setPoint(p1, x1, newy1);
 406         device.setPoint(p2, x2, newy2);
 407         device.sync();
 408         double factor2 = (double) (newy2 - newy1)/(y2 - y1);
 409 
 410         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 411         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 412         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 413                 + ", total factor: " + (factor1 * factor2)
 414                 + ", inertia value: false");
 415 
 416         TestLog.reset();
 417         y1 = y1 + step;
 418         y2 = y2 - step;
 419         newy1 = y1 + step;
 420         newy2 = y2 - step;
 421         device.setPoint(p1, x1, newy1);
 422         device.setPoint(p2, x2, newy2);
 423         device.sync();
 424         double factor3 = (double) (newy2 - newy1)/(y2 - y1);
 425 
 426         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 427         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 428         TestLog.waitForLogContaining("Zoom, factor: " + factor3
 429                 + ", total factor: " + (factor1 * factor2 * factor3)
 430                 + ", inertia value: false");
 431 
 432         //release first finger
 433         TestLog.reset();
 434         device.removePoint(p1);
 435         device.sync();
 436         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 437                 x1, newy1);
 438         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 439                 x2, newy2);
 440         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 441                 + ", total factor: " + (factor1 * factor2 * factor3)
 442                 + ", inertia value: false");
 443 
 444         //release second finger
 445         TestLog.reset();
 446         device.removePoint(p2);
 447         device.sync();
 448         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 449         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 450                 x2, newy2);
 451         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 452         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 453         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 454                 + x2 +", " + newy2));
 455         tapToStopInertia();
 456     }
 457 }
--- EOF ---