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