Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2008 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.graphics.cts;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.assertFalse;
     21 import static org.junit.Assert.assertTrue;
     22 
     23 import android.graphics.Point;
     24 import android.graphics.PointF;
     25 import android.os.Parcel;
     26 import android.support.test.filters.SmallTest;
     27 import android.support.test.runner.AndroidJUnit4;
     28 
     29 import org.junit.Test;
     30 import org.junit.runner.RunWith;
     31 
     32 @SmallTest
     33 @RunWith(AndroidJUnit4.class)
     34 public class PointFTest {
     35     private PointF mPointF;
     36 
     37     @Test
     38     public void testConstructor() {
     39         mPointF = new PointF();
     40         mPointF = new PointF(10.0f, 10.0f);
     41 
     42         Point point = new Point(10, 10);
     43         mPointF = new PointF(point);
     44     }
     45 
     46     @Test
     47     public void testNegate() {
     48         mPointF = new PointF(10, 10);
     49         mPointF.negate();
     50         assertEquals(-10.0f, mPointF.x, 0.0f);
     51         assertEquals(-10.0f, mPointF.y, 0.0f);
     52     }
     53 
     54     @Test
     55     public void testLength1() {
     56         mPointF = new PointF(0.3f, 0.4f);
     57         assertEquals(0.5f, mPointF.length(), 0.0f);
     58     }
     59 
     60     @Test
     61     public void testLength2() {
     62         assertEquals(0.5f, PointF.length(0.3f, 0.4f), 0.0f);
     63     }
     64 
     65     @Test
     66     public void testSet1() {
     67         mPointF = new PointF();
     68         mPointF.set(0.3f, 0.4f);
     69         assertEquals(0.3f, mPointF.x, 0.0f);
     70         assertEquals(0.4f, mPointF.y, 0.0f);
     71     }
     72 
     73     @Test
     74     public void testSet2() {
     75         mPointF = new PointF();
     76         PointF pointF = new PointF(0.3f, 0.4f);
     77         mPointF.set(pointF);
     78         assertEquals(0.3f, mPointF.x, 0.0f);
     79         assertEquals(0.4f, mPointF.y, 0.0f);
     80     }
     81 
     82     @Test
     83     public void testEquals() {
     84         mPointF = new PointF(0.3f, 0.4f);
     85         assertTrue(mPointF.equals(0.3f, 0.4f));
     86         assertFalse(mPointF.equals(0.4f, 0.3f));
     87     }
     88 
     89     @Test
     90     public void testOffset() {
     91         mPointF = new PointF(10.0f, 10.0f);
     92         mPointF.offset(1.0f, 1.1f);
     93         assertEquals(11.0f, mPointF.x, 0.0f);
     94         assertEquals(11.1f, mPointF.y, 0.0f);
     95     }
     96 
     97     @Test
     98     public void testDescribeContents() {
     99         mPointF = new PointF(10.0f, 20.0f);
    100         assertEquals(0, mPointF.describeContents());
    101     }
    102 
    103     @Test
    104     public void testParceling() {
    105         mPointF = new PointF(10.0f, 20.0f);
    106         Parcel p = Parcel.obtain();
    107         mPointF.writeToParcel(p, 0);
    108         p.setDataPosition(0);
    109 
    110         mPointF = new PointF();
    111         mPointF.readFromParcel(p);
    112         assertEquals(10.0f, mPointF.x, 0.0f);
    113         assertEquals(20.0f, mPointF.y, 0.0f);
    114 
    115         p.recycle();
    116     }
    117 }
    118