diff options
author | Neil Fuller <nfuller@google.com> | 2019-07-04 11:36:23 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2019-07-08 15:53:50 +0100 |
commit | 6fe0e9eaed80b7d3fc60b981d3a767768a8d282b (patch) | |
tree | 512ea396a97e0faddfc4261fe811419fb6563f6b /harmony-tests | |
parent | 4384bb116d86d46cf9099c18965cabc030590db2 (diff) |
Minimal fix for ControlTest (attempt 2)
Make minimal changes to ControlTest to get it passing;
ControlTest is not loaded by the System ClassLoader on
Android so needs to be changed. Now fixed, the test
can be removed from the knownfailures.txt list.
This commit fixes up ControlTest.test_needsReload_LStringLLocaleLStringLClassLoaderResourceBundleJ
with minimal changes. The original intent of the test wasn't
obvious in some places and those lines have been
removed.
Previously the change broke on the ART build bots but also
exited early due to a hardcoded "return". This return has
been removed and replaced with a fail().
Tested for the ART build bots with an approximation of
their vogar commandline:
vogar --toolchain d8 --language CUR --expectations art/tools/libcore_failures.txt \
--classpath out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/classes.jar \
--classpath out/target/common/obj/JAVA_LIBRARIES/jsr166-tests_intermediates/classes.jar \
--classpath out/target/common/obj/JAVA_LIBRARIES/mockito-target_intermediates/classes.jar \
org.apache.harmony.tests.java.util.ControlTest
Test: atest CtsLibcoreTestCases
Test: See vogar details above
Bug: 13747957
Bug: 28686280
Change-Id: Ib6c24a6d977a4197350a3db1299c76fa4ac5fbdf
Diffstat (limited to 'harmony-tests')
3 files changed, 27 insertions, 25 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ControlTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ControlTest.java index d0b236d6fc..717e7d9bf9 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ControlTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ControlTest.java @@ -27,6 +27,7 @@ import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -45,6 +46,8 @@ import static java.util.ResourceBundle.Control.*; */ public class ControlTest extends TestCase { + public static final String RESOURCE_PACKAGE_NAME = "tests.resources.control_test"; + /** * Control with format:FORMAT_PROPERTIES */ @@ -374,13 +377,9 @@ public class ControlTest extends TestCase { } @SuppressWarnings("nls") - static File copyFile(final URL src) throws IOException { + static File copyFile(final URL src, final String targetDir) throws IOException { String tail = src.getFile().split("hyts_resource")[1]; - String tmpdir = System.getProperty("java.io.tmpdir"); - if (null == tmpdir) { - return null; - } - String copyName = tmpdir + File.separator + "hyts_resource_copy" + tail; + String copyName = targetDir + File.separator + "hyts_resource_copy" + tail; File copy = new File(copyName); if (copy.exists()) { copy.delete(); @@ -454,23 +453,27 @@ public class ControlTest extends TestCase { public void test_needsReload_LStringLLocaleLStringLClassLoaderResourceBundleJ() throws Exception { String className = "tests.support.Support_TestResource"; - String propertiesName = Support_Resources.RESOURCE_PACKAGE_NAME - + ".hyts_resource"; + String propertiesName = RESOURCE_PACKAGE_NAME + ".hyts_resource"; String propertiesNameCopy = "hyts_resource_copy"; String CLASS = "java.class"; String PROPERTIES = "java.properties"; Locale frFR = new Locale("fr", "FR"); - ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); - ClassLoader URLLoader = systemLoader; + ClassLoader testCodeClassLoader = this.getClass().getClassLoader(); ResourceBundle bundle = null; long time = 0L; - final URL srcFile = URLLoader.getResource(control.toResourceName( + final URL srcFile = testCodeClassLoader.getResource(control.toResourceName( control.toBundleName(propertiesName, frFR), "properties")); assertNotNull(srcFile); - final File copyFile = copyFile(srcFile); + + String tmpdir = System.getProperty("java.io.tmpdir"); + assertNotNull(tmpdir); + final File copyFile = copyFile(srcFile, tmpdir); + ClassLoader URLLoader = new URLClassLoader( + new URL[] { new File(tmpdir).toURL() }, + testCodeClassLoader); // 1. format = "java.properties" - if (null != URLLoader.getResourceAsStream(copyFile.toURL().toString())) { + if (null != URLLoader.getResourceAsStream(copyFile.getName())) { Thread.sleep(1000); bundle = control.newBundle(propertiesNameCopy, frFR, PROPERTIES, URLLoader, false); @@ -492,15 +495,10 @@ public class ControlTest extends TestCase { PROPERTIES, URLLoader, bundle, 2006L)); // other loader assertFalse(control.needsReload(propertiesNameCopy, frFR, - PROPERTIES, systemLoader, bundle, time)); + PROPERTIES, testCodeClassLoader, bundle, time)); // other bundle ResourceBundle otherBundle = control.newBundle(propertiesName, - Locale.ROOT, PROPERTIES, systemLoader, false); - assertEquals("parent", otherBundle.getString("property")); - assertTrue(control.needsReload(propertiesNameCopy, frFR, - PROPERTIES, URLLoader, otherBundle, time)); - otherBundle = control.newBundle(propertiesName, Locale.ROOT, - PROPERTIES, URLLoader, false); + Locale.ROOT, PROPERTIES, URLLoader, false); assertEquals("resource", otherBundle.getString("property")); assertTrue(control.needsReload(propertiesNameCopy, frFR, PROPERTIES, URLLoader, otherBundle, time)); @@ -508,16 +506,14 @@ public class ControlTest extends TestCase { assertFalse(control.needsReload(propertiesNameCopy, frFR, PROPERTIES, URLLoader, bundle, System.currentTimeMillis())); } else { - System.err - .println("Can not find the test file, some code of this test 'test_needsReload_LStringLLocaleLStringLClassLoaderResourceBundleJ' did not run."); - + fail("Can not find the test file:" + copyFile); } // 2. format = "java.class" - bundle = control.newBundle(className, frFR, CLASS, systemLoader, false); + bundle = control.newBundle(className, frFR, CLASS, testCodeClassLoader, false); time = System.currentTimeMillis(); assertEquals("frFRValue3", bundle.getString("parent3")); - assertFalse(control.needsReload(className, frFR, CLASS, systemLoader, + assertFalse(control.needsReload(className, frFR, CLASS, testCodeClassLoader, bundle, time)); // exceptions control.needsReload(propertiesName, frFR, PROPERTIES, URLLoader, diff --git a/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource.properties b/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource.properties new file mode 100644 index 0000000000..eae054e84b --- /dev/null +++ b/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource.properties @@ -0,0 +1,3 @@ +property=resource +propertyInURLParent=valueInURLParent +
\ No newline at end of file diff --git a/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource_fr_FR.properties b/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource_fr_FR.properties new file mode 100644 index 0000000000..0ac2c73167 --- /dev/null +++ b/harmony-tests/src/test/resources/tests/resources/control_test/hyts_resource_fr_FR.properties @@ -0,0 +1,3 @@ +property=fr_FR_resource +propertyInFRFR=valueInFRFR +
\ No newline at end of file |