PaintCompatHasGlyphTest.java revision 7b4fde9d7c2a45a477d3629ab990c3da361a3e73
1/* 2 * Copyright (C) 2017 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 17package android.support.v4.graphics; 18 19import static android.os.Build.VERSION.SDK_INT; 20 21import static org.junit.Assert.assertEquals; 22 23import android.graphics.Paint; 24import android.support.test.filters.SmallTest; 25 26import org.junit.Test; 27import org.junit.runner.RunWith; 28import org.junit.runners.Parameterized; 29 30import java.util.Arrays; 31import java.util.Collection; 32 33@RunWith(Parameterized.class) 34@SmallTest 35public class PaintCompatHasGlyphTest { 36 37 @Parameterized.Parameters 38 public static Collection<Object[]> data() { 39 return Arrays.asList(new Object[][]{ 40 {"B", true}, 41 {"\uDB3F\uDFFD", false}, 42 {"Ō", true}, 43 {"£", true}, 44 {"⅓", true}, 45 {"Hello", false}, 46 {"\u0020", true}, // white space 47 {"\t\t\t", false}, // more white space 48 {"☺", SDK_INT >= 16}, // glyph added in API 16 49 {"\uD83D\uDC66\uD83C\uDFFF", SDK_INT >= 24}, // glyph added in API 24 50 }); 51 } 52 53 private final String mTestString; 54 private final boolean mExpectedResult; 55 56 public PaintCompatHasGlyphTest(String testString, boolean expectedResult) { 57 mTestString = testString; 58 mExpectedResult = expectedResult; 59 } 60 61 @Test 62 public void testHasGlyph() { 63 final boolean hasGlyph = PaintCompat.hasGlyph(new Paint(), mTestString); 64 assertEquals("hasGlyph() returned " + hasGlyph + " for '" + mTestString + "'", 65 mExpectedResult, hasGlyph); 66 } 67} 68