assertNotSame("Dynamically constructed string is not interned", tmp, intern);
assertEquals("Static string on initialized class is matches runtime interned string", intern,
StaticInternString.intent);
assertEquals("Static string on initialized class is pre-interned", BootInternedString.boot,
BootInternedString.boot.intern());
// TODO: Does this next check really provide us anything?
Field f = StaticInternString.class.getDeclaredField("intent");
assertEquals("String literals are interned properly", intern, f.get(null));
assertEquals("String literals are interned properly across classes",
StaticInternString.getIntent(), StaticInternString2.getIntent());
}
publicstaticvoid testReloadInternedString() throws Exception { // reload the class StaticInternString, check whether static strings interned properly
PathClassLoader loader = new PathClassLoader(DEX_FILE, LIBRARY_SEARCH_PATH, null); Class<?> staticInternString = loader.loadClass("StaticInternString");
assertTrue("Class in app image isn't loaded a second time after loading dex file again",
checkAppImageContains(staticInternString));
Method getIntent = staticInternString.getDeclaredMethod("getIntent");
assertEquals("Interned strings are still interned after multiple dex loads",
StaticInternString.getIntent(), getIntent.invoke(staticInternString));
}
publicstaticvoid testLoadingSecondaryAppImage() throws Exception { final ClassLoader parent = Main.class.getClassLoader();
// Initial check that the image isn't already loaded so we don't get bogus results below
assertFalse("Secondary app image isn't already loaded",
checkAppImageLoaded("596-app-images-ex"));
PathClassLoader pcl = new PathClassLoader(SECONDARY_DEX_FILE, parent);
assertTrue("Ensure app image is loaded if it should be",
checkAppImageLoaded("596-app-images-ex"));
Class<?> secondaryCls = pcl.loadClass("Secondary");
assertTrue("Ensure Secondary class is in the app image if the CLC is correct",
checkAppImageContains(secondaryCls));
assertTrue("Ensure Secondary class is preinitialized if the CLC is correct",
checkInitialized(secondaryCls));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.