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

Commit 0b938dae authored by Victor Chang's avatar Victor Chang Committed by Automerger Merge Worker
Browse files

Merge "Add ResourcesLocaleTest#testDeprecatedISOLanguageCode test" into main...

Merge "Add ResourcesLocaleTest#testDeprecatedISOLanguageCode test" into main am: 704d2fff am: 1b53d7fc

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2705153



Change-Id: I2e655d25431e0f71fbd34d1bbd379fd0007ac3c5
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 281ad61b 1b53d7fc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Used in ResourcesLocaleTest. -->
    <string name="locale_test_res_1">Pengujian ID</string>
</resources>
+5 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Used in ResourcesLocaleTest. -->
    <string name="locale_test_res_2">Pengujian IN</string>
</resources>
+7 −0
Original line number Diff line number Diff line
@@ -131,6 +131,13 @@

    <string name="textview_hebrew_text">&#x05DD;&#x05DE;ab?!</string>

    <!-- Used in ResourcesLocaleTest. Also defined in values-id. "id" is the new ISO code for Indonesian. -->
    <string name="locale_test_res_1">Testing ID</string>
    <!-- Used in ResourcesLocaleTest. Also defined in values-in. "in" is the deprecated ISO code for Indonesian. -->
    <string name="locale_test_res_2">Testing IN</string>
    <!-- Used in ResourcesLocaleTest. -->
    <string name="locale_test_res_3">Testing EN</string>

    <!-- SizeAdaptiveLayout -->
    <string name="first">Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.</string>
    <string name="actor">Abe Lincoln</string>
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.res;

import android.content.Context;
import android.os.FileUtils;
import android.os.LocaleList;
import android.platform.test.annotations.Presubmit;
@@ -97,4 +98,24 @@ public class ResourcesLocaleTest extends AndroidTestCase {
        assertEquals(Locale.forLanguageTag("pl-PL"),
                resources.getConfiguration().getLocales().get(0));
    }

    @SmallTest
    public void testDeprecatedISOLanguageCode() {
        assertResGetString(Locale.US, R.string.locale_test_res_1, "Testing ID");
        assertResGetString(Locale.forLanguageTag("id"), R.string.locale_test_res_2, "Pengujian IN");
        assertResGetString(Locale.forLanguageTag("id"), R.string.locale_test_res_3, "Testing EN");
        assertResGetString(new Locale("id"), R.string.locale_test_res_2, "Pengujian IN");
        assertResGetString(new Locale("id"), R.string.locale_test_res_3, "Testing EN");
        // The new ISO code "id" isn't supported yet, and thus the values-id are ignored.
        assertResGetString(new Locale("id"), R.string.locale_test_res_1, "Testing ID");
        assertResGetString(Locale.forLanguageTag("id"), R.string.locale_test_res_1, "Testing ID");
    }

    private void assertResGetString(Locale locale, int resId, String expectedString) {
        LocaleList locales = new LocaleList(locale);
        final Configuration config = new Configuration();
        config.setLocales(locales);
        Context newContext = getContext().createConfigurationContext(config);
        assertEquals(expectedString, newContext.getResources().getString(resId));
    }
}