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.input.devices;
  27 
  28 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  29 import com.sun.glass.ui.monocle.TestLog;
  30 import test.robot.com.sun.glass.ui.monocle.UInput;
  31 import org.junit.Assume;
  32 
  33 import java.util.HashSet;
  34 import java.util.Set;
  35 
  36 /** The touch screen used in the Freescale i.MX6Q Sabre Device Platform,
  37  * extrapolated to five touch points. There is some guesswork here as to
  38  * whether the screen always resends stationary points and what happens when
  39  * all fingers are removed from the screen. Also, on some devices on release
  40  * of the last point no tracking ID is sent. Instead we get the following event
  41  * sequence:
  42  *
  43  *   EV_ABS ABS_MT_TOUCH_MAJOR 0
  44  *   EV_KEY BTN_TOUCH 0
  45  *   EV_SYN SYN_MT_REPORT 0
  46  *
  47  * On other devices a touch ID of -1 is sent on release of the last point
  48  * instead of the touch ID that has been used until then.
  49  *
  50  * These questions are resolved in different ways in subclasses.
  51  */
  52 public class EGalaxMultiTouchDeviceBase extends TestTouchDevice {
  53 
  54     protected final boolean resendStationaryPoints;
  55     protected final boolean sendBtnTouch;
  56     protected final boolean sendTouchMajor;
  57     protected final SendIDOnRelease sendIDOnRelease;
  58 
  59     private Set<Integer> modifiedPoints = new HashSet<>();
  60 
  61     enum SendIDOnRelease {
  62         SEND_ID, SEND_MINUS_ONE, DONT_SEND
  63     }
  64 
  65     public EGalaxMultiTouchDeviceBase(boolean resendStationaryPoints,
  66                                       boolean sendBtnTouch,
  67                                       boolean sendTouchMajor,
  68                                       SendIDOnRelease sendIDOnRelease) {
  69         super(5);
  70         this.resendStationaryPoints = resendStationaryPoints;
  71         this.sendBtnTouch = sendBtnTouch;
  72         this.sendTouchMajor = sendTouchMajor;
  73         this.sendIDOnRelease = sendIDOnRelease;
  74     }
  75 
  76     @Override
  77     public void create() {
  78         // this device fails multitouch tests on Lens
  79         Assume.assumeTrue(TestApplication.isMonocle());
  80         ui = new UInput();
  81         ui.processLine("OPEN");
  82         ui.processLine("EVBIT EV_SYN");
  83         if (sendBtnTouch) {
  84             ui.processLine("EVBIT EV_KEY");
  85             ui.processLine("KEYBIT BTN_TOUCH");
  86         }
  87         ui.processLine("ABSBIT ABS_MT_TRACKING_ID");
  88         ui.processLine("ABSBIT ABS_MT_POSITION_X");
  89         ui.processLine("ABSBIT ABS_MT_POSITION_Y");
  90         if (sendTouchMajor) {
  91             ui.processLine("ABSBIT ABS_MT_TOUCH_MAJOR");
  92             ui.processLine("ABSMIN ABS_MT_TOUCH_MAJOR 0");
  93             ui.processLine("ABSMAX ABS_MT_TOUCH_MAJOR 255");
  94         }
  95         ui.processLine("ABSMIN ABS_MT_TRACKING_ID 0");
  96         ui.processLine("ABSMAX ABS_MT_TRACKING_ID 5");
  97         ui.processLine("ABSMIN ABS_MT_POSITION_X 0");
  98         ui.processLine("ABSMAX ABS_MT_POSITION_X 32767");
  99         ui.processLine("ABSMIN ABS_MT_POSITION_Y 0");
 100         ui.processLine("ABSMAX ABS_MT_POSITION_Y 32767");
 101         ui.processLine("PROPBIT INPUT_PROP_POINTER");
 102         ui.processLine("PROPBIT INPUT_PROP_DIRECT");
 103         ui.processLine("PROPERTY ID_INPUT_TOUCHSCREEN 1");
 104         ui.processLine("CREATE");
 105         setAbsScale(32768, 32768);
 106     }
 107 
 108     @Override
 109     public int addPoint(double x, double y) {
 110         int p = super.addPoint(x, y);
 111         ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 112         if (sendTouchMajor) {
 113             ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 1");
 114         }
 115         ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]);
 116         ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]);
 117         ui.processLine("EV_SYN SYN_MT_REPORT 0");
 118         modifiedPoints.add(p);
 119         if (sendBtnTouch && pressedPoints == 1) {
 120             ui.processLine("EV_KEY BTN_TOUCH 1");
 121         }
 122         return p;
 123     }
 124 
 125     @Override
 126     public void removePoint(int p) {
 127         super.removePoint(p);
 128         if (pressedPoints == 0) {
 129             switch (sendIDOnRelease) {
 130                 case SEND_ID:
 131                     ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 132                     break;
 133                 case SEND_MINUS_ONE:
 134                     ui.processLine("EV_ABS ABS_MT_TRACKING_ID -1");
 135                     break;
 136                 case DONT_SEND:
 137                     break;
 138             }
 139             if (sendTouchMajor) {
 140                 ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 0");
 141             }
 142             if (sendIDOnRelease == SendIDOnRelease.SEND_ID) {
 143                 ui.processLine("EV_SYN SYN_MT_REPORT 0");
 144             }
 145             if (sendBtnTouch) {
 146                 ui.processLine("EV_KEY BTN_TOUCH 0");
 147             }
 148         } else {
 149             ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 150             if (sendTouchMajor) {
 151                 ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 0");
 152             }
 153             ui.processLine("EV_SYN SYN_MT_REPORT 0");
 154         }
 155     }
 156 
 157     @Override
 158     public void setPoint(int p, double x, double y) {
 159         super.setPoint(p, x, y);
 160         ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 161         if (sendTouchMajor) {
 162             ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 1");
 163         }
 164         ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]);
 165         ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]);
 166         ui.processLine("EV_SYN SYN_MT_REPORT 0");
 167         modifiedPoints.add(p);
 168     }
 169 
 170     @Override
 171     public void setAndRemovePoint(int p, double x, double y) {
 172         // This device doesn't send move and release at the same time
 173         removePoint(p);
 174     }
 175 
 176     @Override
 177     public void sync() {
 178         if (resendStationaryPoints) {
 179             for (int p = 0; p < points.length; p++) {
 180                 if (points[p] && !modifiedPoints.contains(p)) {
 181                     ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 182                     if (sendTouchMajor) {
 183                         ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 1");
 184                     }
 185                     ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]);
 186                     ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]);
 187                     ui.processLine("EV_SYN SYN_MT_REPORT 0");
 188                 }
 189             }
 190         }
 191         modifiedPoints.clear();
 192         super.sync();
 193     }
 194 
 195     @Override
 196     public void resendStateAndSync() {
 197         TestLog.log("TestTouchDevice: sync");
 198         for (int p = 0; p < points.length; p++) {
 199             if (points[p]) {
 200                 ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + p);
 201                 ui.processLine("EV_ABS ABS_MT_TOUCH_MAJOR 1");
 202                 ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]);
 203                 ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]);
 204                 ui.processLine("EV_SYN SYN_MT_REPORT 0");
 205             }
 206         }
 207         modifiedPoints.clear();
 208         sync();
 209     }
 210 
 211 }
--- EOF ---