Home | History | Annotate | Download | only in text
      1 /*
      2  * Copyright (C) 2016 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 static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.fail;
     21 
     22 import android.graphics.fonts.FontVariationAxis;
     23 import android.platform.test.annotations.Presubmit;
     24 import android.support.test.filters.SmallTest;
     25 import android.support.test.runner.AndroidJUnit4;
     26 
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 
     30 @Presubmit
     31 @SmallTest
     32 @RunWith(AndroidJUnit4.class)
     33 public class VariationParserTest {
     34     private static final String[] INVALID_STYLE_VALUES = {
     35         "", "x", "\t", "\n"
     36     };
     37 
     38     @Test
     39     public void testFromFontVariationSetting_InvalidStyleValue() {
     40         // Test with invalid styleValue
     41         for (String invalidStyle : INVALID_STYLE_VALUES) {
     42             try {
     43                 FontVariationAxis.fromFontVariationSettings("'wdth' " + invalidStyle);
     44                 fail();
     45             } catch (IllegalArgumentException e) {
     46                 // pass
     47             }
     48         }
     49         for (String invalidStyle : INVALID_STYLE_VALUES) {
     50             try {
     51                 FontVariationAxis.fromFontVariationSettings("'wght' 1, 'wdth' "
     52                     + invalidStyle);
     53                 fail();
     54             } catch (IllegalArgumentException e) {
     55                 // pass
     56             }
     57         }
     58     }
     59 
     60     @Test
     61     public void testOpenTypeTagValue() {
     62       assertEquals(0x77647468,
     63           new FontVariationAxis("wdth", 0).getOpenTypeTagValue());
     64       assertEquals(0x41582020,
     65           new FontVariationAxis("AX  ", 0).getOpenTypeTagValue());
     66       assertEquals(0x20202020,
     67           new FontVariationAxis("    ", 0).getOpenTypeTagValue());
     68     }
     69 }
     70