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 import static org.junit.Assert.assertEquals; 20 21 import android.graphics.Color; 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.ForegroundColorSpan; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @SmallTest 32 @RunWith(AndroidJUnit4.class) 33 public class ForegroundColorSpanTest { 34 @Test 35 public void testConstructor() { 36 ForegroundColorSpan f = new ForegroundColorSpan(Color.GREEN); 37 38 final Parcel p = Parcel.obtain(); 39 try { 40 f.writeToParcel(p, 0); 41 p.setDataPosition(0); 42 new ForegroundColorSpan(p); 43 } finally { 44 p.recycle(); 45 } 46 } 47 48 @Test 49 public void testGetForegroundColor() { 50 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLUE); 51 assertEquals(Color.BLUE, foregroundColorSpan.getForegroundColor()); 52 53 foregroundColorSpan = new ForegroundColorSpan(Color.BLACK); 54 assertEquals(Color.BLACK, foregroundColorSpan.getForegroundColor()); 55 } 56 57 @Test 58 public void testUpdateDrawState() { 59 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.CYAN); 60 61 TextPaint tp = new TextPaint(); 62 tp.setColor(0); 63 assertEquals(0, tp.getColor()); 64 foregroundColorSpan.updateDrawState(tp); 65 assertEquals(Color.CYAN, tp.getColor()); 66 67 foregroundColorSpan = new ForegroundColorSpan(Color.DKGRAY); 68 foregroundColorSpan.updateDrawState(tp); 69 assertEquals(Color.DKGRAY, tp.getColor()); 70 } 71 72 @Test(expected=NullPointerException.class) 73 public void testUpdateDrawStateNull() { 74 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.CYAN); 75 76 foregroundColorSpan.updateDrawState(null); 77 } 78 79 @Test 80 public void testDescribeContents() { 81 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED); 82 foregroundColorSpan.describeContents(); 83 } 84 85 @Test 86 public void testGetSpanTypeId() { 87 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED); 88 foregroundColorSpan.getSpanTypeId(); 89 } 90 91 @Test 92 public void testWriteToParcel() { 93 Parcel p = Parcel.obtain(); 94 try { 95 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED); 96 foregroundColorSpan.writeToParcel(p, 0); 97 p.setDataPosition(0); 98 ForegroundColorSpan f = new ForegroundColorSpan(p); 99 assertEquals(Color.RED, f.getForegroundColor()); 100 } finally { 101 p.recycle(); 102 } 103 104 p = Parcel.obtain(); 105 try { 106 ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.MAGENTA); 107 foregroundColorSpan.writeToParcel(p, 0); 108 p.setDataPosition(0); 109 ForegroundColorSpan f = new ForegroundColorSpan(p); 110 assertEquals(Color.MAGENTA, f.getForegroundColor()); 111 } finally { 112 p.recycle(); 113 } 114 } 115 } 116