Loading core/tests/coretests/src/android/graphics/TypefaceTest.java +34 −18 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; import java.util.Random; Loading Loading @@ -218,6 +219,10 @@ public class TypefaceTest { @SmallTest @Test public void testSetSystemFontMap() throws Exception { // Typeface.setSystemFontMap mutate the returned map. So copying for the backup. HashMap<String, Typeface> backup = new HashMap<>(Typeface.getSystemFontMap()); Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Resources res = context.getResources(); Map<String, Typeface> fontMap = Map.of( Loading @@ -226,6 +231,8 @@ public class TypefaceTest { "monospace", Typeface.create(res.getFont(R.font.samplefont3), Typeface.NORMAL), "sample", Typeface.create(res.getFont(R.font.samplefont4), Typeface.NORMAL), "sample-italic", Typeface.create(res.getFont(R.font.samplefont4), Typeface.ITALIC)); try { Typeface.setSystemFontMap(fontMap); // Test public static final fields Loading @@ -246,7 +253,16 @@ public class TypefaceTest { // Test create() assertEquals(fontMap.get("sample"), Typeface.create("sample", Typeface.NORMAL)); assertEquals( fontMap.get("sample-italic"), Typeface.create("sample-italic", Typeface.ITALIC)); fontMap.get("sample-italic"), Typeface.create("sample-italic", Typeface.ITALIC)); } finally { // This tests breaks many default font configuration and break the assumption of the // subsequent test cases. To recover the original configuration, call the // setSystemFontMap function with the original data even if it is a test target. // Ideally, this test should be isolated and app should be restart after this test // been executed. Typeface.setSystemFontMap(backup); } } private static float measureText(Typeface typeface, String text) { Loading Loading
core/tests/coretests/src/android/graphics/TypefaceTest.java +34 −18 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; import java.util.Random; Loading Loading @@ -218,6 +219,10 @@ public class TypefaceTest { @SmallTest @Test public void testSetSystemFontMap() throws Exception { // Typeface.setSystemFontMap mutate the returned map. So copying for the backup. HashMap<String, Typeface> backup = new HashMap<>(Typeface.getSystemFontMap()); Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Resources res = context.getResources(); Map<String, Typeface> fontMap = Map.of( Loading @@ -226,6 +231,8 @@ public class TypefaceTest { "monospace", Typeface.create(res.getFont(R.font.samplefont3), Typeface.NORMAL), "sample", Typeface.create(res.getFont(R.font.samplefont4), Typeface.NORMAL), "sample-italic", Typeface.create(res.getFont(R.font.samplefont4), Typeface.ITALIC)); try { Typeface.setSystemFontMap(fontMap); // Test public static final fields Loading @@ -246,7 +253,16 @@ public class TypefaceTest { // Test create() assertEquals(fontMap.get("sample"), Typeface.create("sample", Typeface.NORMAL)); assertEquals( fontMap.get("sample-italic"), Typeface.create("sample-italic", Typeface.ITALIC)); fontMap.get("sample-italic"), Typeface.create("sample-italic", Typeface.ITALIC)); } finally { // This tests breaks many default font configuration and break the assumption of the // subsequent test cases. To recover the original configuration, call the // setSystemFontMap function with the original data even if it is a test target. // Ideally, this test should be isolated and app should be restart after this test // been executed. Typeface.setSystemFontMap(backup); } } private static float measureText(Typeface typeface, String text) { Loading