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.assertNotNull; 22 import static org.junit.Assert.assertTrue; 23 24 import android.graphics.Point; 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 PointTest { 36 private Point mPoint; 37 38 @Test testConstructor()39 public void testConstructor() { 40 mPoint = new Point(); 41 mPoint = new Point(10, 10); 42 43 Point point = new Point(10, 10); 44 mPoint = new Point(point); 45 } 46 47 @Test testSet()48 public void testSet() { 49 mPoint = new Point(); 50 mPoint.set(3, 4); 51 assertEquals(3, mPoint.x); 52 assertEquals(4, mPoint.y); 53 } 54 55 @Test testEquals1()56 public void testEquals1() { 57 mPoint = new Point(3, 4); 58 assertTrue(mPoint.equals(3, 4)); 59 assertFalse(mPoint.equals(4, 3)); 60 } 61 62 @Test testEquals2()63 public void testEquals2() { 64 mPoint = new Point(3, 4); 65 Point point = new Point(3, 4); 66 assertTrue(mPoint.equals(point)); 67 point = new Point(4, 3); 68 assertFalse(mPoint.equals(point)); 69 } 70 71 @Test testHashCode()72 public void testHashCode() { 73 mPoint = new Point(10, 10); 74 Point p = new Point(100, 10); 75 assertTrue(p.hashCode() != mPoint.hashCode()); 76 } 77 78 @Test testToString()79 public void testToString() { 80 mPoint = new Point(); 81 assertNotNull(mPoint.toString()); 82 } 83 84 @Test testOffset()85 public void testOffset() { 86 mPoint = new Point(10, 10); 87 mPoint.offset(1, 1); 88 assertEquals(11, mPoint.x); 89 assertEquals(11, mPoint.y); 90 } 91 92 @Test testNegate()93 public void testNegate() { 94 mPoint = new Point(10, 10); 95 mPoint.negate(); 96 assertEquals(-10, mPoint.x); 97 assertEquals(-10, mPoint.y); 98 } 99 100 @Test testDescribeContents()101 public void testDescribeContents() { 102 mPoint = new Point(10, 20); 103 assertEquals(0, mPoint.describeContents()); 104 } 105 106 @Test testParceling()107 public void testParceling() { 108 mPoint = new Point(10, 20); 109 Parcel p = Parcel.obtain(); 110 mPoint.writeToParcel(p, 0); 111 p.setDataPosition(0); 112 113 mPoint = new Point(); 114 mPoint.readFromParcel(p); 115 assertEquals(10, mPoint.x); 116 assertEquals(20, mPoint.y); 117 } 118 } 119