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