use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class DumpManagerTest method dumpResources_resourceName.
@Test
public void dumpResources_resourceName() throws Exception {
createBundle(bundlePath, new ResourceTableBuilder().addPackage("com.app").addStringResource("icon", "Icon").addMipmapResource("icon", "res/mipmap-hdpi/icon.png").addDrawableResource("icon", "res/drawable/icon.png").build());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.RESOURCES).setOutputStream(new PrintStream(outputStream)).setResourceName("string/icon").build().execute();
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).isEqualTo(String.format("Package 'com.app':%n" + "0x7f010000 - string/icon%n" + "\t(default)%n%n"));
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class WearApkLocatorTest method resourceReferencedInMetadataDoesNotExist_throws.
@Test
public void resourceReferencedInMetadataDoesNotExist_throws() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).build();
AndroidManifest androidManifest = AndroidManifest.create(androidManifest(PACKAGE_NAME, withMetadataResource(WEAR_APK_1_0_METADATA_KEY, 0x7F000000)));
ImmutableList<ModuleEntry> entries = buildEntriesForEmbeddedWearApk(wearableApkPath);
ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
assertThat(exception).hasMessageThat().isEqualTo("Resource 0x7f000000 is referenced in the manifest in the " + "'com.google.android.wearable.beta.app' metadata, but was not found in the " + "resource table.");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class WearApkLocatorTest method xmlDescriptionResourceNotPointingAtFile_throws.
@Test
public void xmlDescriptionResourceNotPointingAtFile_throws() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).addResource(XML_TYPE, WEAR_DESC_XML_RES_NAME, ConfigValue.newBuilder().setValue(newStringValue(WEAR_DESC_XML_RES_PATH)).build()).addFileResource(RAW_TYPE, WEAR_APK_RES_NAME, WEAR_APK_RES_PATH).build();
AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
ImmutableList<ModuleEntry> entries = buildEntriesForEmbeddedWearApk(wearableApkPath);
ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
assertThat(exception).hasMessageThat().isEqualTo("No XML description file path found for Wear APK.");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class WearApkLocatorTest method xmlDescriptionFileNotFound_throws.
@Test
public void xmlDescriptionFileNotFound_throws() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).addXmlResource(WEAR_DESC_XML_RES_NAME, WEAR_DESC_XML_RES_PATH).addFileResource(RAW_TYPE, WEAR_APK_RES_NAME, wearableApkPath.toString()).build();
AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
// No description XML file in the entries.
ImmutableList<ModuleEntry> entries = ImmutableList.of(createModuleEntryForFile(wearableApkPath.toString(), TestData.readBytes("testdata/apk/com.test.app.apk")));
ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
assertThat(exception).hasMessageThat().isEqualTo("Wear APK XML description file expected at 'res/xml/wearable_app_desc.xml' but was not " + "found.");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ResourcesUtilsTest method lookupEntryByResourceId_positiveId.
@Test
public void lookupEntryByResourceId_positiveId() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app", 0x7F).addXmlResource("layout", "res/xml/layout.xml").addStringResource("hello", "res/string/hello.xml").addStringResource("world", "res/string/world.xml").build();
Optional<Entry> layoutResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x7F010000);
assertThat(layoutResource).isPresent();
assertThat(extractFilePathValues(layoutResource.get())).containsExactly("res/xml/layout.xml");
Optional<Entry> helloResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x7F020000);
assertThat(helloResource).isPresent();
assertThat(extractStringValues(helloResource.get())).containsExactly("res/string/hello.xml");
Optional<Entry> worldResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x7F020001);
assertThat(worldResource).isPresent();
assertThat(extractStringValues(worldResource.get())).containsExactly("res/string/world.xml");
}
Aggregations