< prev index next >

tests/system/src/test/java/test/robot/com/sun/glass/ui/monocle/SwipeTest.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.TestApplication;
  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 com.sun.javafx.PlatformUtil;
  33 import javafx.scene.input.GestureEvent;
  34 import org.junit.Assert;
  35 import org.junit.Assume;
  36 import org.junit.Before;
  37 import org.junit.Ignore;
  38 import org.junit.Test;
  39 import org.junit.runners.Parameterized;
  40 
  41 import java.util.ArrayList;
  42 import java.util.Collection;
  43 import java.util.List;
  44 import java.util.Timer;
  45 import java.util.TimerTask;
  46 import java.util.concurrent.CountDownLatch;
  47 import test.com.sun.glass.ui.monocle.TestRunnable;
  48 


 104             this.amplitude = amplitude;
 105             this.wavelength = wavelength;
 106             this.expectedSwipe = expectedSwipe;
 107         }
 108 
 109         public String toString() {
 110             return "SwipeTestCase["
 111                     + "length=" + length
 112                     + ",theta=" + theta
 113                     + ",time=" + time
 114                     + ",density=" + density
 115                     + ",amplitude=" + amplitude
 116                     + ",wavelength=" + wavelength
 117                     + ",expectedSwipe=" + expectedSwipe + "]";
 118         }
 119     }
 120 
 121     public SwipeTest(TestTouchDevice device, SwipeTestCase testCase) throws Exception {
 122         super(device);
 123         this.testCase = testCase;
 124         TestLog.format("Starting test with %s, %s", device, testCase);
 125         TestApplication.getStage();
 126         TestRunnable.invokeAndWait(() -> {
 127             Assume.assumeTrue(
 128                     TestApplication.isMonocle() || TestApplication.isLens());
 129             Assume.assumeTrue(PlatformUtil.isEmbedded());
 130         });
 131     }
 132 
 133     @Parameterized.Parameters
 134     public static Collection<Object[]> data() {
 135         List<Object[]> params = new ArrayList<>();
 136         List<TestTouchDevice> devices = TestTouchDevices.getTouchDevices();
 137         for (TestTouchDevice device : devices) {
 138             for (SwipeTestCase testCase : TEST_CASES) {
 139                 params.add(new Object[] { device, testCase });
 140             }
 141         }
 142         return params;
 143     }
 144 
 145     @Before
 146     public void addListener() throws Exception {
 147         TestApplication.getStage().getScene().addEventHandler(
 148                 GestureEvent.ANY,
 149                 e -> TestLog.format("%s at %.0f, %.0f",
 150                                     e.getEventType(),
 151                                     e.getScreenX(),
 152                                     e.getScreenY()));
 153     }
 154 
 155     /**
 156      * Sends a series of points as a sine wave
 157      *
 158      * @param p The point ID to move
 159      * @param x1 Starting X
 160      * @param y1 Starting Y
 161      * @param length length of the vector from the start point to the end point
 162      * @param theta Direction of the sine wave, measured in radians
 163      *              clockwise from the upwards Y axis
 164      * @param time Time to send all points, in milliseconds
 165      * @param density number of points to send per second
 166      * @param amplitude of the sine wave, in pixels
 167      * @param wavelength of the sine wave, in pixels
 168      */
 169     private CountDownLatch generatePoints(int p,


 216 
 217     @Test
 218     @Ignore("RT-37709")
 219     public void testSwipe() throws Exception {
 220         final int x = (int) Math.round(width * 0.5);
 221         final int y = (int) Math.round(height * 0.5);
 222         // tap
 223         int p = device.addPoint(x, y);
 224         device.sync();
 225         // swipe
 226         generatePoints(p, x, y,
 227                        testCase.length,
 228                        testCase.theta,
 229                        testCase.time,
 230                        testCase.density,
 231                        testCase.amplitude,
 232                        testCase.wavelength).await();
 233         // release
 234         device.removePoint(p);
 235         device.sync();
 236         TestLog.waitForLog("Mouse pressed: %d, %d", x, y);
 237         TestLog.waitForLogContaining("Mouse released");
 238         TestLog.waitForLogContaining("Mouse clicked");
 239         TestLog.waitForLogContaining("Touch pressed");
 240         TestLog.waitForLogContaining("Touch released");
 241         if (testCase.expectedSwipe == null) {
 242             Assert.assertEquals(0, TestLog.countLogContaining("SWIPE"));
 243         } else {
 244             TestLog.waitForLogContaining(testCase.expectedSwipe);
 245             Assert.assertEquals(1, TestLog.countLogContaining("SWIPE"));
 246         }
 247     }
 248 
 249 }


   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.TestApplication;
  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 com.sun.javafx.PlatformUtil;
  33 import javafx.scene.input.GestureEvent;
  34 import org.junit.Assert;
  35 import org.junit.Assume;
  36 import org.junit.Before;
  37 import org.junit.Ignore;
  38 import org.junit.Test;
  39 import org.junit.runners.Parameterized;
  40 
  41 import java.util.ArrayList;
  42 import java.util.Collection;
  43 import java.util.List;
  44 import java.util.Timer;
  45 import java.util.TimerTask;
  46 import java.util.concurrent.CountDownLatch;
  47 import test.com.sun.glass.ui.monocle.TestRunnable;
  48 


 104             this.amplitude = amplitude;
 105             this.wavelength = wavelength;
 106             this.expectedSwipe = expectedSwipe;
 107         }
 108 
 109         public String toString() {
 110             return "SwipeTestCase["
 111                     + "length=" + length
 112                     + ",theta=" + theta
 113                     + ",time=" + time
 114                     + ",density=" + density
 115                     + ",amplitude=" + amplitude
 116                     + ",wavelength=" + wavelength
 117                     + ",expectedSwipe=" + expectedSwipe + "]";
 118         }
 119     }
 120 
 121     public SwipeTest(TestTouchDevice device, SwipeTestCase testCase) throws Exception {
 122         super(device);
 123         this.testCase = testCase;
 124         TestLogShim.format("Starting test with %s, %s", device, testCase);
 125         TestApplication.getStage();
 126         TestRunnable.invokeAndWait(() -> {
 127             Assume.assumeTrue(
 128                     TestApplication.isMonocle() || TestApplication.isLens());
 129             Assume.assumeTrue(PlatformUtil.isEmbedded());
 130         });
 131     }
 132 
 133     @Parameterized.Parameters
 134     public static Collection<Object[]> data() {
 135         List<Object[]> params = new ArrayList<>();
 136         List<TestTouchDevice> devices = TestTouchDevices.getTouchDevices();
 137         for (TestTouchDevice device : devices) {
 138             for (SwipeTestCase testCase : TEST_CASES) {
 139                 params.add(new Object[] { device, testCase });
 140             }
 141         }
 142         return params;
 143     }
 144 
 145     @Before
 146     public void addListener() throws Exception {
 147         TestApplication.getStage().getScene().addEventHandler(
 148                 GestureEvent.ANY,
 149                 e -> TestLogShim.format("%s at %.0f, %.0f",
 150                                     e.getEventType(),
 151                                     e.getScreenX(),
 152                                     e.getScreenY()));
 153     }
 154 
 155     /**
 156      * Sends a series of points as a sine wave
 157      *
 158      * @param p The point ID to move
 159      * @param x1 Starting X
 160      * @param y1 Starting Y
 161      * @param length length of the vector from the start point to the end point
 162      * @param theta Direction of the sine wave, measured in radians
 163      *              clockwise from the upwards Y axis
 164      * @param time Time to send all points, in milliseconds
 165      * @param density number of points to send per second
 166      * @param amplitude of the sine wave, in pixels
 167      * @param wavelength of the sine wave, in pixels
 168      */
 169     private CountDownLatch generatePoints(int p,


 216 
 217     @Test
 218     @Ignore("RT-37709")
 219     public void testSwipe() throws Exception {
 220         final int x = (int) Math.round(width * 0.5);
 221         final int y = (int) Math.round(height * 0.5);
 222         // tap
 223         int p = device.addPoint(x, y);
 224         device.sync();
 225         // swipe
 226         generatePoints(p, x, y,
 227                        testCase.length,
 228                        testCase.theta,
 229                        testCase.time,
 230                        testCase.density,
 231                        testCase.amplitude,
 232                        testCase.wavelength).await();
 233         // release
 234         device.removePoint(p);
 235         device.sync();
 236         TestLogShim.waitForLog("Mouse pressed: %d, %d", x, y);
 237         TestLogShim.waitForLogContaining("Mouse released");
 238         TestLogShim.waitForLogContaining("Mouse clicked");
 239         TestLogShim.waitForLogContaining("Touch pressed");
 240         TestLogShim.waitForLogContaining("Touch released");
 241         if (testCase.expectedSwipe == null) {
 242             Assert.assertEquals(0, TestLogShim.countLogContaining("SWIPE"));
 243         } else {
 244             TestLogShim.waitForLogContaining(testCase.expectedSwipe);
 245             Assert.assertEquals(1, TestLogShim.countLogContaining("SWIPE"));
 246         }
 247     }
 248 
 249 }
< prev index next >