diff options
| author | 2023-08-23 04:43:24 +0000 | |
|---|---|---|
| committer | 2023-08-23 04:43:24 +0000 | |
| commit | 22399c4f96c2307d45d909d1bb93d6c67301a00d (patch) | |
| tree | 3ead943be63bb255947ab0ad62b773d60362a2bd | |
| parent | f8b473dd899301a4997d6192d4ed64cb0c7b8ccc (diff) | |
| parent | 0b938dae1b42a87c3e0bce1e305a05e6f1d32505 (diff) | |
Merge "Add ResourcesLocaleTest#testDeprecatedISOLanguageCode test" into main am: 704d2fffec am: 1b53d7fc34 am: 0b938dae1b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2705153
Change-Id: I3a39d3bdc9cfdad50019ef9730685b3889b34d7c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
4 files changed, 38 insertions, 0 deletions
diff --git a/core/tests/coretests/res/values-id/strings.xml b/core/tests/coretests/res/values-id/strings.xml new file mode 100644 index 000000000000..6d71c90866cc --- /dev/null +++ b/core/tests/coretests/res/values-id/strings.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <!-- Used in ResourcesLocaleTest. --> + <string name="locale_test_res_1">Pengujian ID</string> +</resources> diff --git a/core/tests/coretests/res/values-in/strings.xml b/core/tests/coretests/res/values-in/strings.xml new file mode 100644 index 000000000000..63846603ed60 --- /dev/null +++ b/core/tests/coretests/res/values-in/strings.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <!-- Used in ResourcesLocaleTest. --> + <string name="locale_test_res_2">Pengujian IN</string> +</resources> diff --git a/core/tests/coretests/res/values/strings.xml b/core/tests/coretests/res/values/strings.xml index e51eab60a998..09e1c690f4e2 100644 --- a/core/tests/coretests/res/values/strings.xml +++ b/core/tests/coretests/res/values/strings.xml @@ -131,6 +131,13 @@ <string name="textview_hebrew_text">םמ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> diff --git a/core/tests/coretests/src/android/content/res/ResourcesLocaleTest.java b/core/tests/coretests/src/android/content/res/ResourcesLocaleTest.java index 25c3db5c6910..26e4349243a5 100644 --- a/core/tests/coretests/src/android/content/res/ResourcesLocaleTest.java +++ b/core/tests/coretests/src/android/content/res/ResourcesLocaleTest.java @@ -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)); + } } |