1 /* 2 * Copyright (C) 2018 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 21 import android.graphics.Insets; 22 import android.graphics.Rect; 23 import android.os.Parcel; 24 25 import androidx.test.filters.SmallTest; 26 import androidx.test.runner.AndroidJUnit4; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @SmallTest 32 @RunWith(AndroidJUnit4.class) 33 public class InsetsTest { 34 35 @Test testEmptyInsets()36 public void testEmptyInsets() { 37 assertEquals(Insets.NONE, Insets.of(0, 0, 0, 0)); 38 } 39 40 @Test testInsetsAppliedInOrder()41 public void testInsetsAppliedInOrder() { 42 Insets insets = Insets.of(1, 2, 3, 4); 43 assertEquals(1, insets.left); 44 assertEquals(2, insets.top); 45 assertEquals(3, insets.right); 46 assertEquals(4, insets.bottom); 47 } 48 49 @Test testInsetsFromNullRect()50 public void testInsetsFromNullRect() { 51 assertEquals(Insets.NONE, Insets.of(null)); 52 } 53 54 @Test testInsetsFromRect()55 public void testInsetsFromRect() { 56 Rect rect = new Rect(1, 2, 3, 4); 57 Insets insets = Insets.of(rect); 58 assertEquals(1, insets.left); 59 assertEquals(2, insets.top); 60 assertEquals(3, insets.right); 61 assertEquals(4, insets.bottom); 62 } 63 64 @Test testInsetsEquality()65 public void testInsetsEquality() { 66 Rect rect = new Rect(10, 20, 30, 40); 67 Insets insets1 = Insets.of(rect); 68 Insets insets2 = Insets.of(10, 20, 30, 40); 69 assertEquals(insets1, insets2); 70 } 71 72 @Test testAdd()73 public void testAdd() { 74 Insets insets1 = Insets.of(10, 20, 30, 40); 75 Insets insets2 = Insets.of(50, 60, 70, 80); 76 assertEquals(Insets.add(insets1, insets2), Insets.of(60, 80, 100, 120)); 77 } 78 79 @Test testSubtract()80 public void testSubtract() { 81 Insets insets1 = Insets.of(10, 20, 30, 40); 82 Insets insets2 = Insets.of(50, 70, 90, 110); 83 assertEquals(Insets.subtract(insets2, insets1), Insets.of(40, 50, 60, 70)); 84 } 85 86 @Test testMin()87 public void testMin() { 88 Insets insets1 = Insets.of(1, 10, 100, 1000); 89 Insets insets2 = Insets.of(1000, 100, 10, 1); 90 assertEquals(Insets.min(insets2, insets1), Insets.of(1, 10, 10, 1)); 91 } 92 93 @Test testMax()94 public void testMax() { 95 Insets insets1 = Insets.of(1, 10, 100, 1000); 96 Insets insets2 = Insets.of(1000, 100, 10, 1); 97 assertEquals(Insets.max(insets2, insets1), Insets.of(1000, 100, 100, 1000)); 98 } 99 100 @Test testParcel()101 public void testParcel() { 102 Insets inset = Insets.of(1, 3, 5, 7); 103 final Parcel parcel = Parcel.obtain(); 104 inset.writeToParcel(parcel, 0); 105 parcel.setDataPosition(0); 106 assertEquals(inset, Insets.CREATOR.createFromParcel(parcel)); 107 assertEquals(parcel.dataSize(), parcel.dataPosition()); 108 parcel.recycle(); 109 } 110 } 111