Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.view.cts;
     18 
     19 import static android.view.cts.MotionEventUtils.withCoords;
     20 
     21 import android.support.test.filters.SmallTest;
     22 import android.support.test.runner.AndroidJUnit4;
     23 import android.view.MotionEvent;
     24 import android.view.cts.MotionEventUtils.PointerCoordsBuilder;
     25 
     26 import org.junit.Before;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 
     30 /**
     31  * Test {@link MotionEvent.PointerCoords}.
     32  */
     33 @SmallTest
     34 @RunWith(AndroidJUnit4.class)
     35 public class MotionEvent_PointerCoordsTest {
     36     private PointerCoordsBuilder mBuilder;
     37     private MotionEvent.PointerCoords mPointerCoords;
     38 
     39     @Before
     40     public void setup() {
     41         mBuilder = withCoords(10.0f, 20.0f).withPressure(1.2f).withSize(2.0f).withTool(1.2f, 1.4f).
     42                 withTouch(3.0f, 2.4f);
     43         mPointerCoords = mBuilder.build();
     44     }
     45 
     46     @Test
     47     public void testCreation() {
     48         mBuilder.verifyMatchesPointerCoords(mPointerCoords);
     49     }
     50 
     51     @Test
     52     public void testAxesModifications() {
     53         // Change value of X
     54         mPointerCoords.setAxisValue(MotionEvent.AXIS_X, 15.0f);
     55         withCoords(15.0f, 20.0f).withPressure(1.2f).withSize(2.0f).withTool(1.2f, 1.4f).
     56                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     57 
     58         // Change value of Y
     59         mPointerCoords.setAxisValue(MotionEvent.AXIS_Y, 25.0f);
     60         withCoords(15.0f, 25.0f).withPressure(1.2f).withSize(2.0f).withTool(1.2f, 1.4f).
     61                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     62 
     63         // Change value of pressure
     64         mPointerCoords.setAxisValue(MotionEvent.AXIS_PRESSURE, 2.2f);
     65         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(2.0f).withTool(1.2f, 1.4f).
     66                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     67 
     68         // Change value of size
     69         mPointerCoords.setAxisValue(MotionEvent.AXIS_SIZE, 10.0f);
     70         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(10.0f).withTool(1.2f, 1.4f).
     71                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     72 
     73         // Change value of tool major
     74         mPointerCoords.setAxisValue(MotionEvent.AXIS_TOOL_MAJOR, 7.0f);
     75         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(10.0f).withTool(7.0f, 1.4f).
     76                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     77 
     78         // Change value of tool minor
     79         mPointerCoords.setAxisValue(MotionEvent.AXIS_TOOL_MINOR, 2.0f);
     80         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(10.0f).withTool(7.0f, 2.0f).
     81                 withTouch(3.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     82 
     83         // Change value of tool major
     84         mPointerCoords.setAxisValue(MotionEvent.AXIS_TOUCH_MAJOR, 5.0f);
     85         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(10.0f).withTool(7.0f, 2.0f).
     86                 withTouch(5.0f, 2.4f).verifyMatchesPointerCoords(mPointerCoords);
     87 
     88         // Change value of tool minor
     89         mPointerCoords.setAxisValue(MotionEvent.AXIS_TOUCH_MINOR, 2.1f);
     90         withCoords(15.0f, 25.0f).withPressure(2.2f).withSize(10.0f).withTool(7.0f, 2.0f).
     91                 withTouch(5.0f, 2.1f).verifyMatchesPointerCoords(mPointerCoords);
     92     }
     93 
     94     @Test
     95     public void testCopyFrom() {
     96         final MotionEvent.PointerCoords pointerCoords = new MotionEvent.PointerCoords();
     97         pointerCoords.copyFrom(mPointerCoords);
     98         mBuilder.verifyMatchesPointerCoords(pointerCoords);
     99     }
    100 
    101     @Test
    102     public void testClear() {
    103         mPointerCoords.clear();
    104         withCoords(0.0f, 0.0f).withPressure(0.0f).withSize(0.0f).withTool(0.0f, 0.0f).
    105                 withTouch(0.0f, 0.0f).verifyMatchesPointerCoords(mPointerCoords);
    106     }
    107 }
    108