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.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 49 private int newX1; 50 private int newY1; 51 private static final int ZERO_ANGLE = 0; 52 private int centerX; 53 private int centerY; 54 private int radius; 55 private int p1; 56 private int p2; 57 58 public RotateTest(TestTouchDevice device) { 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 234 public void testSmallStepRightNoRotateSent() throws Exception { 235 Rotate(4, 1); 236 } 237 238 /** 239 * Tap two fingers, drag a little bit upper finger right in order move, 240 * but not enough for rotation, then make 2 more small moves 241 */ 242 @Test 243 public void testRotateRightByFewSmallSteps() throws Exception { 244 Rotate(4, 5); 245 } 246 247 /** 248 * Tap two fingers, drag upper finger right in order to rotate 249 */ 250 @Test 251 public void testRotateRight() throws Exception { 252 Rotate(15, 6); 253 } 254 255 /** 256 * Tap two fingers, rotate the object right (by 3 steps, 50 degrees each) 257 */ 258 @Test 259 public void testRotateRightBigSteps() throws Exception { 260 Rotate(50, 3); 261 } 262 263 /** 264 * Tap two fingers, rotate the object right by only 1 very big step - 80 degrees 265 */ 266 @Test 267 @Ignore //RT-36616 268 public void testRotateRightOneBigStep() throws Exception { 269 Rotate(80, 1); 270 } 271 272 /** 273 * Tap two fingers, drag a little bit upper finger left in order move, 274 * but not enough for rotation. 275 */ 276 @Test 277 public void testSmallStepLeftNoRotateSent() throws Exception { 278 Rotate(-4, 1); 279 } 280 281 /** 282 * Tap two fingers, drag a little bit upper finger left in order move, 283 * but not enough for rotation, then make 9 more small moves 284 */ 285 @Test 286 public void testRotateLeftByFewSmallSteps() throws Exception { 287 Rotate(-4, 10); 288 } 289 290 /** 291 * Tap two fingers, drag upper finger left in order to rotate 292 */ 293 @Test 294 public void testRotateLeft() throws Exception { 295 Rotate(-10, 4); 296 } 297 298 /** 299 * Tap two fingers, rotate the object left (by 5 steps, 40 degrees each) 300 */ 301 @Test 302 public void testRotateLeftBigSteps() throws Exception { 303 Rotate(-40, 5); 304 } 305 306 /** 307 * Tap two fingers, rotate the object left by only 1 very big step - 70 degrees 308 */ 309 @Test 310 @Ignore //RT-36616 311 public void testRotateLeftOneBigStep() throws Exception { 312 Rotate(-70, 1); 313 } 314 315 /** 316 * Tap two fingers in 45 degrees, rotate the object right 317 */ 318 @Test 319 public void testRotateRightFrom45Degrees() throws Exception { 320 Rotate(45, 20, 3); 321 } 322 323 /** 324 * Tap two fingers in 45 degrees, rotate the object left 325 */ 326 @Test 327 public void testRotateLeftFrom45Degrees() throws Exception { 328 Rotate(45, -20, 3); 329 } 330 331 /** 332 * Tap two fingers in -45 degrees, rotate the object right 333 */ 334 @Test 335 public void testRotateRightFromMinus45Degrees() throws Exception { 336 Rotate(-45, 20, 3); 337 } 338 339 /** 340 * Tap two fingers in -45 degrees, rotate the object left 341 */ 342 @Test 343 public void testRotateLeftFromMinus45Degrees() throws Exception { 344 Rotate(-45, -20, 3); 345 } 346 347 /** 348 * Tap two fingers in 140 degrees, rotate the object right 349 */ 350 @Test 351 public void testRotateRightFrom140Degrees() throws Exception { 352 Rotate(140, 20, 3); 353 } 354 355 /** 356 * Tap two fingers in 140 degrees, rotate the object left 357 */ 358 @Test 359 public void testRotateLeftFrom140Degrees() throws Exception { 360 Rotate(140, -20, 3); 361 } 362 363 /** 364 * Tap two fingers in -140 degrees, rotate the object right 365 */ 366 @Test 367 public void testRotateRightFromMinus140Degrees() throws Exception { 368 Rotate(-140, 20, 3); 369 } 370 371 /** 372 * Tap two fingers in -140 degrees, rotate the object left 373 */ 374 @Test 375 public void testRotateLeftFromMinus140Degrees() throws Exception { 376 Rotate(-140, -20, 3); 377 } 378 379 }