Search in sources :

Example 21 with BundleModuleBuilder

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

the class AssetsTargetingValidatorTest method validateModule_emptyTargetedDirectory_throws.

@Test
public void validateModule_emptyTargetedDirectory_throws() throws Exception {
    Assets config = assets(targetedAssetsDirectory("assets/dir#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8))));
    BundleModule module = new BundleModuleBuilder("testModule").setAssetsConfig(config).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new AssetsTargetingValidator().validateModule(module));
    assertThat(e).hasMessageThat().contains("Targeted directory 'assets/dir#tcf_etc1' is empty.");
}
Also used : Assets(com.android.bundle.Files.Assets) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 22 with BundleModuleBuilder

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

the class AssetsTargetingValidatorTest method validateModule_pointDirectlyToAssets_succeeds.

@Test
public void validateModule_pointDirectlyToAssets_succeeds() throws Exception {
    Assets config = assets(targetedAssetsDirectory("assets", AssetsDirectoryTargeting.getDefaultInstance()));
    BundleModule module = new BundleModuleBuilder("testModule").addFile("assets/file.dat").setAssetsConfig(config).setManifest(androidManifest("com.test.app")).build();
    new AssetsTargetingValidator().validateModule(module);
}
Also used : Assets(com.android.bundle.Files.Assets) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 23 with BundleModuleBuilder

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

the class BundleConfigValidatorTest method optimizations_defaultDeviceTier_targeted_specified.

@Test
public void optimizations_defaultDeviceTier_targeted_specified() throws Exception {
    AppBundleBuilder appBundleBuilder = new AppBundleBuilder().setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, false, false, "1").build()).addModule(new BundleModuleBuilder("base").addFile("assets/textures#tier_1/level1.assets").addFile("assets/textures#tier_2/level1.assets").setManifest(androidManifest("com.test.app")).build());
    new BundleConfigValidator().validateBundle(appBundleBuilder.build());
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Test(org.junit.Test)

Example 24 with BundleModuleBuilder

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

the class VariantGeneratorTest method targetsPreLOnlyInManifest_throws.

@Test
public void targetsPreLOnlyInManifest_throws() throws Exception {
    int preL = 20;
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMaxSdkVersion(preL))).build();
    CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> new VariantGenerator().generateVariants(bundleModule));
    assertThat(exception).hasMessageThat().contains("does not target devices on Android L or above");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 25 with BundleModuleBuilder

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

the class VariantGeneratorTest method variantsWithV3SigningRestrictedToRPlus.

@Test
public void variantsWithV3SigningRestrictedToRPlus() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).build();
    VariantGenerator variantGenerator = new VariantGenerator();
    ImmutableCollection<VariantTargeting> splits = variantGenerator.generateVariants(bundleModule, ApkGenerationConfiguration.builder().setMinSdkForAdditionalVariantWithV3Rotation(ANDROID_R_API_VERSION).build());
    assertThat(splits).containsExactly(lPlusVariantTargeting(), variantMinSdkTargeting(ANDROID_R_API_VERSION));
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)349 Test (org.junit.Test)348 BundleModule (com.android.tools.build.bundletool.model.BundleModule)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)164 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)69 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)44 ResourceTable (com.android.aapt.Resources.ResourceTable)38 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)28 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)16 Truth.assertThat (com.google.common.truth.Truth.assertThat)16 RunWith (org.junit.runner.RunWith)16 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 ImmutableList (com.google.common.collect.ImmutableList)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)15 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)14 NativeLibraries (com.android.bundle.Files.NativeLibraries)13 HDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI)13 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)13