Search in sources :

Example 26 with ResourceTableBuilder

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"));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 27 with ResourceTableBuilder

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.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 28 with ResourceTableBuilder

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.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 29 with ResourceTableBuilder

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.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 30 with ResourceTableBuilder

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");
}
Also used : Entry(com.android.aapt.Resources.Entry) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Aggregations

ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)77 Test (org.junit.Test)77 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)44 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)44 BundleModule (com.android.tools.build.bundletool.model.BundleModule)40 ResourceTable (com.android.aapt.Resources.ResourceTable)35 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)25 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)24 Truth.assertThat (com.google.common.truth.Truth.assertThat)24 RunWith (org.junit.runner.RunWith)24 ImmutableMap (com.google.common.collect.ImmutableMap)21 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)21 ImmutableList (com.google.common.collect.ImmutableList)20 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)20 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)20 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)18 Theories (org.junit.experimental.theories.Theories)18 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)16 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)16 Collection (java.util.Collection)16