Home | History | Annotate | Download | only in text
      1 /*
      2  * Copyright (C) 2007 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;
     18 
     19 import android.test.InstrumentationTestCase;
     20 import android.test.MoreAsserts;
     21 import android.test.suitebuilder.annotation.MediumTest;
     22 import android.text.Spannable;
     23 
     24 public abstract class SpannableTest extends InstrumentationTestCase {
     25 
     26     protected abstract Spannable newSpannableWithText(String text);
     27 
     28     @MediumTest
     29     public void testGetSpans() {
     30         Spannable spannable = newSpannableWithText("abcdef");
     31         Object emptySpan = new Object();
     32         spannable.setSpan(emptySpan, 1, 1, 0);
     33         Object unemptySpan = new Object();
     34         spannable.setSpan(unemptySpan, 1, 2, 0);
     35 
     36         Object[] spans;
     37 
     38         // Empty spans are included when they merely abut the query region
     39         // but other spans are not, unless the query region is empty, in
     40         // in which case any abutting spans are returned.
     41         spans = spannable.getSpans(0, 1, Object.class);
     42         MoreAsserts.assertEquals(new Object[]{emptySpan}, spans);
     43         spans = spannable.getSpans(0, 2, Object.class);
     44         MoreAsserts.assertEquals(new Object[]{emptySpan, unemptySpan}, spans);
     45         spans = spannable.getSpans(1, 2, Object.class);
     46         MoreAsserts.assertEquals(new Object[]{emptySpan, unemptySpan}, spans);
     47         spans = spannable.getSpans(2, 2, Object.class);
     48         MoreAsserts.assertEquals(new Object[]{unemptySpan}, spans);
     49     }
     50 }
     51