Search in sources :

Example 36 with ResourceTableBuilder

use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.

the class ResourceTableValidatorTest method validateModule_nonReferencedFile_throws.

@Test
public void validateModule_nonReferencedFile_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("contains references to non-existing files: [res/drawable/icon.png]");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 37 with ResourceTableBuilder

use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.

the class ResourceTableValidatorTest method validateModule_fileOutsideRes_throws.

@Test
public void validateModule_fileOutsideRes_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").addFile("assets/icon.png").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "assets/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("references file 'assets/icon.png' outside of the 'res/' directory");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 38 with ResourceTableBuilder

use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.

the class BundleConfigValidatorTest method masterResources_valid_ok.

@Test
public void masterResources_valid_ok() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("label", "Hello World").build();
    int resourceId = ResourcesUtils.entries(resourceTable).findFirst().get().getResourceId().getFullResourceId();
    AppBundle appBundle = createAppBundleBuilder(BundleConfigBuilder.create().addResourcePinnedToMasterSplit(resourceId)).addModule("feature", module -> module.setResourceTable(resourceTable).setManifest(androidManifest("com.test.app"))).build();
    new BundleConfigValidator().validateBundle(appBundle);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SuffixStripping(com.android.bundle.Config.SuffixStripping) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) Value(com.android.bundle.Config.SplitDimension.Value) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) BundleConfig(com.android.bundle.Config.BundleConfig) ResourcesUtils(com.android.tools.build.bundletool.model.utils.ResourcesUtils) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) SplitDimension(com.android.bundle.Config.SplitDimension) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ResourceTable(com.android.aapt.Resources.ResourceTable) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 39 with ResourceTableBuilder

use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.

the class ResourceTableValidatorTest method validateModule_validWithResources_succeeds.

@Test
public void validateModule_validWithResources_succeeds() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").addFile("res/drawable/icon.png").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
    new ResourceTableValidator().validateModule(module);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 40 with ResourceTableBuilder

use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.

the class ModuleSplitTest method forArchive_filtersResources.

@Test
public void forArchive_filtersResources() throws Exception {
    BundleModule module = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).addFile("res/drawable/icon.jpg", DUMMY_CONTENT).addFile("res/drawable/background.jpg", DUMMY_CONTENT).build();
    AndroidManifest archivedManifest = AndroidManifest.create(androidManifest("com.test.app", ManifestProtoUtils.withVersionCode(123)));
    ResourceTable archivedResourceTable = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.jpg").build();
    Path archivedClassesDexFile = createTempClassesDexFile(DUMMY_CONTENT);
    ModuleSplit split = ModuleSplit.forArchive(module, archivedManifest, Optional.of(archivedResourceTable), archivedClassesDexFile);
    assertThat(split.getResourceTable().get()).isEqualTo(archivedResourceTable);
    assertThat(extractPaths(split.getEntries())).containsExactly("res/drawable/icon.jpg", "dex/classes.dex");
}
Also used : Path(java.nio.file.Path) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) 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