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.os.Parcel;
     22 import android.support.test.filters.SmallTest;
     23 import android.support.test.runner.AndroidJUnit4;
     24 import android.text.Layout.Alignment;
     25 import android.text.style.AlignmentSpan.Standard;
     26 
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 
     30 /**
     31  * Test {@link Standard}.
     32  */
     33 @SmallTest
     34 @RunWith(AndroidJUnit4.class)
     35 public class AlignmentSpan_StandardTest {
     36     @Test
     37     public void testConstructor() {
     38         new Standard(Alignment.ALIGN_CENTER);
     39 
     40         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
     41         final Parcel p = Parcel.obtain();
     42         try {
     43             standard.writeToParcel(p, 0);
     44             p.setDataPosition(0);
     45             new Standard(p);
     46         } finally {
     47             p.recycle();
     48         }
     49     }
     50 
     51     @Test
     52     public void testGetAlignment() {
     53         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
     54         assertEquals(Alignment.ALIGN_NORMAL, standard.getAlignment());
     55 
     56         standard = new Standard(Alignment.ALIGN_OPPOSITE);
     57         assertEquals(Alignment.ALIGN_OPPOSITE, standard.getAlignment());
     58 
     59         standard = new Standard(Alignment.ALIGN_CENTER);
     60         assertEquals(Alignment.ALIGN_CENTER, standard.getAlignment());
     61     }
     62 
     63     @Test
     64     public void testDescribeContents() {
     65         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
     66         standard.describeContents();
     67     }
     68 
     69     @Test
     70     public void testGetSpanTypeId() {
     71         Standard standard = new Standard(Alignment.ALIGN_NORMAL);
     72         standard.getSpanTypeId();
     73     }
     74 
     75     @Test
     76     public void testWriteToParcel() {
     77         Parcel p = Parcel.obtain();
     78         try {
     79             Standard s = new Standard(Alignment.ALIGN_NORMAL);
     80             s.writeToParcel(p, 0);
     81             p.setDataPosition(0);
     82             Standard standard = new Standard(p);
     83             assertEquals(Alignment.ALIGN_NORMAL, standard.getAlignment());
     84         } finally {
     85             p.recycle();
     86         }
     87 
     88         p = Parcel.obtain();
     89         try {
     90             Standard s = new Standard(Alignment.ALIGN_OPPOSITE);
     91             s.writeToParcel(p, 0);
     92             p.setDataPosition(0);
     93             Standard standard = new Standard(p);
     94             assertEquals(Alignment.ALIGN_OPPOSITE, standard.getAlignment());
     95         } finally {
     96             p.recycle();
     97         }
     98 
     99         p = Parcel.obtain();
    100         try {
    101             Standard s = new Standard(Alignment.ALIGN_CENTER);
    102             s.writeToParcel(p, 0);
    103             p.setDataPosition(0);
    104             Standard standard = new Standard(p);
    105             assertEquals(Alignment.ALIGN_CENTER, standard.getAlignment());
    106         } finally {
    107             p.recycle();
    108         }
    109     }
    110 }
    111