Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43f31565 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix FrameworksCoreTest failue due to system font modification

Bug: 230618860
Bug: 230619302
Test: atest FrameworksCoreTests:android.graphics \
      FrameworksCoreTests:android.text
Change-Id: I3fcd7ac97141f587e9a009265f1955abad27479b
parent a3dcd36d
Loading
Loading
Loading
Loading
+34 −18
Original line number Diff line number Diff line
@@ -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;

@@ -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(
@@ -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
@@ -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) {