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.cts;
     18 
     19 import android.test.AndroidTestCase;
     20 import android.text.InputFilter;
     21 import android.text.SpannableStringBuilder;
     22 import android.text.InputFilter.AllCaps;
     23 
     24 public class InputFilter_AllCapsTest extends AndroidTestCase {
     25 
     26     public void testFilter() {
     27 
     28         // Implicitly invoked
     29         CharSequence source = "Caps";
     30         SpannableStringBuilder dest = new SpannableStringBuilder("AllTest");
     31         AllCaps allCaps = new AllCaps();
     32         InputFilter[] filters = {allCaps};
     33         dest.setFilters(filters);
     34 
     35         String expectedString1 = "AllCAPSTest";
     36         dest.insert(3, source);
     37         assertEquals(expectedString1 , dest.toString());
     38 
     39         String expectedString2 = "AllCAPSCAPS";
     40         dest.replace(7, 11, source);
     41         assertEquals(expectedString2, dest.toString());
     42 
     43         dest.delete(0, 4);
     44         String expectedString3 = "APSCAPS";
     45         assertEquals(expectedString3, dest.toString());
     46 
     47         // Explicitly invoked
     48         CharSequence beforeFilterSource = "TestFilter";
     49         String expectedAfterFilter = "STFIL";
     50         CharSequence actualAfterFilter =
     51             allCaps.filter(beforeFilterSource, 2, 7, dest, 0, beforeFilterSource.length());
     52         assertEquals(expectedAfterFilter, actualAfterFilter);
     53     }
     54 }
     55