From fa29763cef2fea6e54a89284afbc7698a7cc7820 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Fri, 11 Aug 2023 16:16:13 +0800 Subject: Add ResourcesLocaleTest#testDeprecatedISOLanguageCode test Bug: 291868760 Test: atest FrameworksCoreTests:android.content.res.ResourcesLocaleTest Change-Id: Id319f3726aa35c9f2b0323dae5a47b0f0f64cff4 --- core/tests/coretests/res/values-id/strings.xml | 5 +++++ core/tests/coretests/res/values-in/strings.xml | 5 +++++ core/tests/coretests/res/values/strings.xml | 7 +++++++ .../android/content/res/ResourcesLocaleTest.java | 21 +++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 core/tests/coretests/res/values-id/strings.xml create mode 100644 core/tests/coretests/res/values-in/strings.xml 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 @@ + + + + Pengujian ID + 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 @@ + + + + Pengujian IN + 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 @@ םמab?! + + Testing ID + + Testing IN + + Testing EN + 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. Abe Lincoln 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)); + } } -- cgit v1.2.3-59-g8ed1b