rev 9504 : need to fix test log and others

   1 /*
   2  * Copyright (c) 2013, 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.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.Assert;
  33 import org.junit.Test;
  34 import org.junit.runners.Parameterized;
  35 
  36 import java.util.Collection;
  37 
  38 public class FuzzyTapTest extends ParameterizedTestBase {
  39 
  40     public FuzzyTapTest(TestTouchDevice device) {
  41         super(device);
  42     }
  43 
  44     @Parameterized.Parameters
  45     public static Collection<Object[]> data() {
  46         return TestTouchDevices.getTouchDeviceParameters(1);
  47     }
  48 
  49     /** Touch down, touch up at a slightly different location*/
  50     @Test
  51     public void tap1() throws Exception {
  52         final int x = (int) width / 2;
  53         final int y = (int) height / 2;
  54         final int tapRadius = device.getTapRadius();
  55         final int x1 = x + tapRadius / 2;
  56         final int y1 = y + tapRadius / 2;
  57         int p = device.addPoint(x, y);
  58         device.sync();
  59         device.setAndRemovePoint(p, x1, y1);
  60         device.sync();
  61         TestLogShim.waitForLog("Mouse pressed: " + x + ", " + y, 3000);
  62         TestLogShim.waitForLog("Mouse clicked: " + x + ", " + y, 3000);
  63         TestLogShim.waitForLog("Mouse released: " + x + ", " + y, 3000);
  64         Assert.assertEquals(0, TestLogShim.countLogContaining("Mouse dragged:"));
  65         Assert.assertEquals(0, TestLogShim.countLogContaining("Touch moved:"));
  66     }
  67 
  68     /** Touch down, small move, touch up */
  69     @Test
  70     public void tap1a() throws Exception {
  71         final int x = (int) width / 2;
  72         final int y = (int) height / 2;
  73         final int tapRadius = device.getTapRadius();
  74         final int x1 = x + tapRadius / 2;
  75         final int y1 = y + tapRadius / 2;
  76         int p = device.addPoint(x, y);
  77         device.sync();
  78         device.setPoint(p, x1, y1);
  79         device.sync();
  80         device.removePoint(p);
  81         device.sync();
  82         TestLogShim.waitForLog("Mouse clicked: " + x + ", " + y, 3000);
  83         TestLogShim.waitForLog("Mouse released: " + x + ", " + y, 3000);
  84         Assert.assertEquals(0, TestLogShim.countLogContaining("Mouse dragged:"));
  85         Assert.assertEquals(0, TestLogShim.countLogContaining("Touch moved:"));
  86     }
  87 
  88     /** Touch down, touch up outside the tap radius */
  89     @Test
  90     public void tap2() throws Exception {
  91         final int x = (int) width / 2;
  92         final int y = (int) height / 2;
  93         final int tapRadius = device.getTapRadius();
  94         final int x1 = x + tapRadius;
  95         final int y1 = y + tapRadius;
  96         int p = device.addPoint(x, y);
  97         device.sync();
  98         device.setAndRemovePoint(p, x1, y1);
  99         device.sync();
 100         TestLogShim.waitForLog("Mouse pressed: " + x + ", " + y, 3000);
 101         TestLogShim.waitForLog("Mouse released: " + x + ", " + y, 3000);
 102         TestLogShim.waitForLog("Mouse clicked: " + x + ", " + y, 3000);
 103         TestLogShim.waitForLog("Touch pressed: " + x + ", " + y, 3000);
 104         TestLogShim.waitForLog("Touch released: " + x + ", " + y, 3000);
 105         Assert.assertEquals(1, TestLogShim.countLogContaining("Mouse clicked:"));
 106     }
 107 
 108     /** Touch down, move outside touch radius, touch up */
 109     @Test
 110     public void tap2a() throws Exception {
 111         final int x = (int) width / 2;
 112         final int y = (int) height / 2;
 113         final int tapRadius = device.getTapRadius();
 114         final int x1 = x + tapRadius;
 115         final int y1 = y + tapRadius;
 116         int p = device.addPoint(x, y);
 117         device.sync();
 118         device.setPoint(p, x1, y1);
 119         device.sync();
 120         device.removePoint(p);
 121         device.sync();
 122         TestLogShim.waitForLog("Mouse pressed: " + x + ", " + y, 3000);
 123         TestLogShim.waitForLog("Mouse dragged: " + x1 + ", " + y1, 3000);
 124         TestLogShim.waitForLog("Mouse released: " + x1 + ", " + y1, 3000);
 125         TestLogShim.waitForLog("Mouse clicked: " + x1 + ", " + y1, 3000);
 126         TestLogShim.waitForLog("Touch pressed: " + x + ", " + y, 3000);
 127         TestLogShim.waitForLog("Touch moved: " + x1 + ", " + y1, 3000);
 128         TestLogShim.waitForLog("Touch released: " + x1 + ", " + y1, 3000);
 129         Assert.assertEquals(1, TestLogShim.countLogContaining("Mouse clicked: " + x1 + ", " + y1));
 130     }
 131 
 132     /** Touch down, drift outside touch radius, touch up */
 133     @Test
 134     public void tap3b() throws Exception {
 135         final int x = (int) width / 2;
 136         final int y = (int) height / 2;
 137         final int tapRadius = device.getTapRadius();
 138         final int x1 = x + tapRadius * 2;
 139         final int y1 = y + tapRadius * 2;
 140         final int x2 = x + tapRadius * 3;
 141         final int y2 = y + tapRadius * 3;
 142         int p = device.addPoint(x, y);
 143         device.sync();
 144         // drift out of the tap radius
 145         for (int i = 0; i < tapRadius * 2; i++) {
 146             device.setPoint(p, x + i, y + i);
 147             device.sync();
 148         }
 149         // extra moves to make sure the final move is not filtered out
 150         device.setPoint(p, 0, 0);
 151         device.sync();
 152         device.setPoint(p, x2, y2);
 153         device.sync();
 154         // and release
 155         device.removePoint(p);
 156         device.sync();
 157         TestLogShim.waitForLog("Mouse pressed: " + x + ", " + y, 3000);
 158         TestLogShim.waitForLog("Mouse dragged: " + x2 + ", " + y2, 3000);
 159         TestLogShim.waitForLog("Mouse released: " + x2 + ", " + y2, 3000);
 160         TestLogShim.waitForLog("Mouse clicked: " + x2 + ", " + y2, 3000);
 161         TestLogShim.waitForLog("Touch pressed: " + x + ", " + y, 3000);
 162         TestLogShim.waitForLog("Touch moved: " + x2 + ", " + y2, 3000);
 163         TestLogShim.waitForLog("Touch released: " + x2 + ", " + y2, 3000);
 164         Assert.assertEquals(1, TestLogShim.countLogContaining("Mouse clicked: " + x2 + ", " + y2));
 165     }
 166 }
--- EOF ---