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.text.style.cts; 18 19 20 import static org.junit.Assert.assertEquals; 21 22 import android.os.Parcel; 23 import android.support.test.filters.SmallTest; 24 import android.support.test.runner.AndroidJUnit4; 25 import android.text.TextPaint; 26 import android.text.style.SubscriptSpan; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @SmallTest 32 @RunWith(AndroidJUnit4.class) 33 public class SubscriptSpanTest { 34 @Test 35 public void testConstructor() { 36 SubscriptSpan subscriptSpan = new SubscriptSpan(); 37 38 Parcel p = Parcel.obtain(); 39 try { 40 subscriptSpan.writeToParcel(p, 0); 41 p.setDataPosition(0); 42 new SubscriptSpan(p); 43 } finally { 44 p.recycle(); 45 } 46 } 47 48 @Test 49 public void testUpdateMeasureState() { 50 // the expected result is: tp.baselineShift -= (int) (tp.ascent() / 2) 51 SubscriptSpan subscriptSpan = new SubscriptSpan(); 52 53 TextPaint tp = new TextPaint(); 54 float ascent = tp.ascent(); 55 int baselineShift = 100; 56 tp.baselineShift = baselineShift; 57 58 subscriptSpan.updateMeasureState(tp); 59 assertEquals(baselineShift - (int) (ascent / 2), tp.baselineShift); 60 } 61 62 @Test(expected=NullPointerException.class) 63 public void testUpdateMeasureStateNull() { 64 SubscriptSpan subscriptSpan = new SubscriptSpan(); 65 66 subscriptSpan.updateMeasureState(null); 67 } 68 69 @Test 70 public void testUpdateDrawState() { 71 // the expected result is: tp.baselineShift -= (int) (tp.ascent() / 2) 72 SubscriptSpan subscriptSpan = new SubscriptSpan(); 73 74 TextPaint tp = new TextPaint(); 75 float ascent = tp.ascent(); 76 int baselineShift = 50; 77 tp.baselineShift = baselineShift; 78 79 subscriptSpan.updateDrawState(tp); 80 assertEquals(baselineShift - (int) (ascent / 2), tp.baselineShift); 81 } 82 83 @Test(expected=NullPointerException.class) 84 public void testUpdateDrawStateNull() { 85 SubscriptSpan subscriptSpan = new SubscriptSpan(); 86 87 subscriptSpan.updateDrawState(null); 88 } 89 90 @Test 91 public void testDescribeContents() { 92 SubscriptSpan subscriptSpan = new SubscriptSpan(); 93 subscriptSpan.describeContents(); 94 } 95 96 @Test 97 public void testGetSpanTypeId() { 98 SubscriptSpan subscriptSpan = new SubscriptSpan(); 99 subscriptSpan.getSpanTypeId(); 100 } 101 102 @Test 103 public void testWriteToParcel() { 104 Parcel p = Parcel.obtain(); 105 try { 106 SubscriptSpan subscriptSpan = new SubscriptSpan(); 107 subscriptSpan.writeToParcel(p, 0); 108 p.setDataPosition(0); 109 new SubscriptSpan(p); 110 } finally { 111 p.recycle(); 112 } 113 } 114 } 115