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