< prev index next >

tests/system/src/test/java/test/robot/com/sun/glass/ui/monocle/RotateTest.java

Print this page
rev 9504 : need to fix test log and others


   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.After;
  33 import org.junit.Assert;
  34 import org.junit.Assume;
  35 import org.junit.Before;
  36 import org.junit.Ignore;
  37 import org.junit.Test;
  38 import org.junit.runners.Parameterized;
  39 
  40 import java.util.Collection;
  41 
  42 /**
  43  * Rotate tests generated by two touch points.
  44  * By default rotation starting form 0 degrees position - on Axis Y,
  45  * but it can be sent from any other location on the object
  46  *  */
  47 public class RotateTest extends ParameterizedTestBase {
  48 


  59         super(device);
  60     }
  61 
  62     @Parameterized.Parameters
  63     public static Collection<Object[]> data() {
  64         return TestTouchDevices.getTouchDeviceParameters(2);
  65     }
  66 
  67     @Before
  68     public void init() {
  69         //Rotate tests should be run only on platforms that support current feature
  70         Assume.assumeTrue(Boolean.getBoolean("com.sun.javafx.gestures.rotate"));
  71         centerX = (int) Math.round(width * 0.5);
  72         centerY = (int) Math.round(height * 0.5);
  73         radius = (int) Math.round(height * 0.45);
  74     }
  75 
  76     @After
  77     public void releaseAll() throws Exception {
  78         if (device.getPressedPoints() == 2) {
  79             TestLog.reset();
  80             device.removePoint(p1);
  81             device.removePoint(p2);
  82             device.sync();
  83         }
  84     }
  85 
  86     private void updateNewTouchPoint(int angle, int radius, int centerX, int centerY) {
  87 
  88         int transformedAngle = 90 - angle;
  89         newX1 = centerX + (int) Math.round(radius *
  90                 Math.cos(Math.toRadians(transformedAngle)));
  91         newY1 = centerY - (int) Math.round(radius *
  92                 Math.sin(Math.toRadians(transformedAngle)));
  93     }
  94 
  95     private int getDistance(int xPoint1, int yPoint1, int xPoint2, int yPoint2) {
  96         double d = Math.sqrt(Math.pow((xPoint1 - xPoint2), 2)
  97                 + Math.pow((yPoint1 - yPoint2), 2));
  98         return (int) d;
  99     }
 100 
 101     private int getRotateThreshold() {
 102         String s = System.getProperty("com.sun.javafx.gestures.rotate.threshold");
 103         if (s != null) {
 104             return Integer.valueOf(s);
 105         } else {
 106             return 5;
 107         }
 108     }
 109 
 110     private void Rotate(int startAngle, int radius, int x2, int y2, int angleStep,
 111                         int numOfIterations) throws Exception {
 112 
 113         int totalAngle = angleStep;
 114         updateNewTouchPoint(startAngle, radius, x2, y2);
 115 
 116         TestLog.reset();
 117         p1 = device.addPoint(newX1, newY1);
 118         p2 = device.addPoint(x2, y2);
 119         device.sync();
 120         //verify pressing two fingers
 121         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", newX1, newY1);
 122         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 123 
 124         //saving previous coordinates:
 125         int previousX = newX1;
 126         int previousY = newY1;
 127 
 128         updateNewTouchPoint((angleStep + startAngle), radius, x2, y2);
 129 
 130         Assume.assumeTrue(getDistance(previousX, previousY, newX1, newY1 )
 131                 > device.getTapRadius());
 132 
 133         //start the rotation
 134         TestLog.reset();
 135         device.setPoint(p1, newX1, newY1);
 136         device.sync();
 137         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", newX1, newY1);
 138         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 139 
 140         if (Math.abs(angleStep) >= getRotateThreshold()) {
 141             TestLog.waitForLogContaining("Rotation started, angle: " + ZERO_ANGLE
 142                 + ", total angle: " + ZERO_ANGLE + ", inertia value: false");
 143             TestLog.waitForLogContaining("Rotation, angle: " + angleStep
 144                 + ", total angle: " + totalAngle
 145                 + ", inertia value: false");
 146         } else {
 147             Assert.assertEquals(0, TestLog.countLogContaining("Rotation started"));
 148             Assert.assertEquals(0, TestLog.countLogContaining("Rotation, angle"));
 149         }
 150         boolean passedTheThreshold =false;
 151         if (numOfIterations >= 2) {
 152             for (int i = 2; i <= numOfIterations; i++) {
 153                 updateNewTouchPoint(angleStep * i + startAngle, radius, x2, y2);
 154                 totalAngle += angleStep;
 155                 TestLog.reset();
 156                 device.setPoint(p1, newX1, newY1);
 157                 device.sync();
 158 
 159                 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", newX1, newY1);
 160                 TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 161 
 162                 String expectedLog;
 163                 if (Math.abs(angleStep) < getRotateThreshold()) {
 164                     if(Math.abs(totalAngle) >= getRotateThreshold()) {
 165                         if (!passedTheThreshold) {
 166                             expectedLog = "Rotation, angle: " + totalAngle
 167                                 + ", total angle: " + totalAngle
 168                                 + ", inertia value: false";
 169                             passedTheThreshold = true;
 170                         } else {
 171                             expectedLog = "Rotation, angle: " + angleStep
 172                                 + ", total angle: " + totalAngle
 173                                 + ", inertia value: false";
 174                         }
 175                     } else {
 176                         expectedLog = "sync";
 177                     }
 178                 } else {
 179                     expectedLog = "Rotation, angle: " + angleStep
 180                             + ", total angle: " + totalAngle
 181                             + ", inertia value: false";
 182                 }
 183                 TestLog.waitForLogContaining(expectedLog);
 184             }
 185         }
 186         TestLog.reset();
 187         device.removePoint(p1);
 188         device.removePoint(p2);
 189         device.sync();
 190         //verify fingers release
 191         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", newX1, newY1);
 192         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2);
 193         if (Math.abs(totalAngle) >= getRotateThreshold()) {
 194             TestLog.waitForLogContaining("Rotation finished, angle: " + ZERO_ANGLE
 195                     + ", total angle: " + totalAngle + ", inertia value: false");
 196             Assert.assertEquals(1, TestLog.countLogContaining("Rotation "
 197                     + "finished, " + "angle: " + ZERO_ANGLE
 198                     + ", total angle: " + totalAngle
 199                     + ", inertia value: false"));
 200         } else {
 201             Assert.assertEquals(0, TestLog.countLogContaining("Rotation finished, "
 202                     + "angle: " + ZERO_ANGLE + ", total angle: " + totalAngle
 203                     + ", inertia value: false"));
 204         }
 205         if (TestLog.countLogContaining("Rotation finished") > 0) {
 206             TestLog.waitForLogContainingSubstrings("Rotation", "inertia value: true");
 207         }
 208         TestLog.reset();
 209         p2 = device.addPoint(x2, y2);
 210         device.sync();
 211         device.removePoint(p2);
 212         device.sync();
 213         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2);
 214     }
 215 
 216     private void Rotate(int radius, int x2, int y2, int angleStep,
 217                         int numOfIterations) throws Exception {
 218         Rotate(0, radius, x2, y2, angleStep, numOfIterations);
 219     }
 220 
 221     private void Rotate(int startAngle, int angleStep, int numOfIterations) throws Exception {
 222         Rotate(startAngle, radius, centerX, centerY, angleStep, numOfIterations);
 223     }
 224 
 225     private void Rotate(int angleStep, int numOfIterations) throws Exception {
 226         Rotate(0, radius, centerX, centerY, angleStep, numOfIterations);
 227     }
 228 
 229     /**
 230      * Tap two fingers, drag a little bit upper finger right in order move,
 231      * but not enough for rotation.
 232      */
 233     @Test




   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.After;
  33 import org.junit.Assert;
  34 import org.junit.Assume;
  35 import org.junit.Before;
  36 import org.junit.Ignore;
  37 import org.junit.Test;
  38 import org.junit.runners.Parameterized;
  39 
  40 import java.util.Collection;
  41 
  42 /**
  43  * Rotate tests generated by two touch points.
  44  * By default rotation starting form 0 degrees position - on Axis Y,
  45  * but it can be sent from any other location on the object
  46  *  */
  47 public class RotateTest extends ParameterizedTestBase {
  48 


  59         super(device);
  60     }
  61 
  62     @Parameterized.Parameters
  63     public static Collection<Object[]> data() {
  64         return TestTouchDevices.getTouchDeviceParameters(2);
  65     }
  66 
  67     @Before
  68     public void init() {
  69         //Rotate tests should be run only on platforms that support current feature
  70         Assume.assumeTrue(Boolean.getBoolean("com.sun.javafx.gestures.rotate"));
  71         centerX = (int) Math.round(width * 0.5);
  72         centerY = (int) Math.round(height * 0.5);
  73         radius = (int) Math.round(height * 0.45);
  74     }
  75 
  76     @After
  77     public void releaseAll() throws Exception {
  78         if (device.getPressedPoints() == 2) {
  79             TestLogShim.reset();
  80             device.removePoint(p1);
  81             device.removePoint(p2);
  82             device.sync();
  83         }
  84     }
  85 
  86     private void updateNewTouchPoint(int angle, int radius, int centerX, int centerY) {
  87 
  88         int transformedAngle = 90 - angle;
  89         newX1 = centerX + (int) Math.round(radius *
  90                 Math.cos(Math.toRadians(transformedAngle)));
  91         newY1 = centerY - (int) Math.round(radius *
  92                 Math.sin(Math.toRadians(transformedAngle)));
  93     }
  94 
  95     private int getDistance(int xPoint1, int yPoint1, int xPoint2, int yPoint2) {
  96         double d = Math.sqrt(Math.pow((xPoint1 - xPoint2), 2)
  97                 + Math.pow((yPoint1 - yPoint2), 2));
  98         return (int) d;
  99     }
 100 
 101     private int getRotateThreshold() {
 102         String s = System.getProperty("com.sun.javafx.gestures.rotate.threshold");
 103         if (s != null) {
 104             return Integer.valueOf(s);
 105         } else {
 106             return 5;
 107         }
 108     }
 109 
 110     private void Rotate(int startAngle, int radius, int x2, int y2, int angleStep,
 111                         int numOfIterations) throws Exception {
 112 
 113         int totalAngle = angleStep;
 114         updateNewTouchPoint(startAngle, radius, x2, y2);
 115 
 116         TestLogShim.reset();
 117         p1 = device.addPoint(newX1, newY1);
 118         p2 = device.addPoint(x2, y2);
 119         device.sync();
 120         //verify pressing two fingers
 121         TestLogShim.waitForLogContaining("TouchPoint: PRESSED %d, %d", newX1, newY1);
 122         TestLogShim.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 123 
 124         //saving previous coordinates:
 125         int previousX = newX1;
 126         int previousY = newY1;
 127 
 128         updateNewTouchPoint((angleStep + startAngle), radius, x2, y2);
 129 
 130         Assume.assumeTrue(getDistance(previousX, previousY, newX1, newY1 )
 131                 > device.getTapRadius());
 132 
 133         //start the rotation
 134         TestLogShim.reset();
 135         device.setPoint(p1, newX1, newY1);
 136         device.sync();
 137         TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", newX1, newY1);
 138         TestLogShim.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 139 
 140         if (Math.abs(angleStep) >= getRotateThreshold()) {
 141             TestLogShim.waitForLogContaining("Rotation started, angle: " + ZERO_ANGLE
 142                 + ", total angle: " + ZERO_ANGLE + ", inertia value: false");
 143             TestLogShim.waitForLogContaining("Rotation, angle: " + angleStep
 144                 + ", total angle: " + totalAngle
 145                 + ", inertia value: false");
 146         } else {
 147             Assert.assertEquals(0, TestLogShim.countLogContaining("Rotation started"));
 148             Assert.assertEquals(0, TestLogShim.countLogContaining("Rotation, angle"));
 149         }
 150         boolean passedTheThreshold =false;
 151         if (numOfIterations >= 2) {
 152             for (int i = 2; i <= numOfIterations; i++) {
 153                 updateNewTouchPoint(angleStep * i + startAngle, radius, x2, y2);
 154                 totalAngle += angleStep;
 155                 TestLogShim.reset();
 156                 device.setPoint(p1, newX1, newY1);
 157                 device.sync();
 158 
 159                 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", newX1, newY1);
 160                 TestLogShim.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 161 
 162                 String expectedLog;
 163                 if (Math.abs(angleStep) < getRotateThreshold()) {
 164                     if(Math.abs(totalAngle) >= getRotateThreshold()) {
 165                         if (!passedTheThreshold) {
 166                             expectedLog = "Rotation, angle: " + totalAngle
 167                                 + ", total angle: " + totalAngle
 168                                 + ", inertia value: false";
 169                             passedTheThreshold = true;
 170                         } else {
 171                             expectedLog = "Rotation, angle: " + angleStep
 172                                 + ", total angle: " + totalAngle
 173                                 + ", inertia value: false";
 174                         }
 175                     } else {
 176                         expectedLog = "sync";
 177                     }
 178                 } else {
 179                     expectedLog = "Rotation, angle: " + angleStep
 180                             + ", total angle: " + totalAngle
 181                             + ", inertia value: false";
 182                 }
 183                 TestLogShim.waitForLogContaining(expectedLog);
 184             }
 185         }
 186         TestLogShim.reset();
 187         device.removePoint(p1);
 188         device.removePoint(p2);
 189         device.sync();
 190         //verify fingers release
 191         TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", newX1, newY1);
 192         TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2);
 193         if (Math.abs(totalAngle) >= getRotateThreshold()) {
 194             TestLogShim.waitForLogContaining("Rotation finished, angle: " + ZERO_ANGLE
 195                     + ", total angle: " + totalAngle + ", inertia value: false");
 196             Assert.assertEquals(1, TestLogShim.countLogContaining("Rotation "
 197                     + "finished, " + "angle: " + ZERO_ANGLE
 198                     + ", total angle: " + totalAngle
 199                     + ", inertia value: false"));
 200         } else {
 201             Assert.assertEquals(0, TestLogShim.countLogContaining("Rotation finished, "
 202                     + "angle: " + ZERO_ANGLE + ", total angle: " + totalAngle
 203                     + ", inertia value: false"));
 204         }
 205         if (TestLogShim.countLogContaining("Rotation finished") > 0) {
 206             TestLogShim.waitForLogContainingSubstrings("Rotation", "inertia value: true");
 207         }
 208         TestLogShim.reset();
 209         p2 = device.addPoint(x2, y2);
 210         device.sync();
 211         device.removePoint(p2);
 212         device.sync();
 213         TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2);
 214     }
 215 
 216     private void Rotate(int radius, int x2, int y2, int angleStep,
 217                         int numOfIterations) throws Exception {
 218         Rotate(0, radius, x2, y2, angleStep, numOfIterations);
 219     }
 220 
 221     private void Rotate(int startAngle, int angleStep, int numOfIterations) throws Exception {
 222         Rotate(startAngle, radius, centerX, centerY, angleStep, numOfIterations);
 223     }
 224 
 225     private void Rotate(int angleStep, int numOfIterations) throws Exception {
 226         Rotate(0, radius, centerX, centerY, angleStep, numOfIterations);
 227     }
 228 
 229     /**
 230      * Tap two fingers, drag a little bit upper finger right in order move,
 231      * but not enough for rotation.
 232      */
 233     @Test


< prev index next >