Search in sources :

Example 1 with ResourceTableBuilder

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

the class BundleConfigValidatorTest method masterResources_undefinedResourceId_throws.

@Test
public void masterResources_undefinedResourceId_throws() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("label", "Hello World").build();
    int nonExistentResourceId = ResourcesUtils.entries(resourceTable).findFirst().get().getResourceId().getFullResourceId() + 1;
    AppBundle appBundle = createAppBundleBuilder(BundleConfigBuilder.create().addResourcePinnedToMasterSplit(nonExistentResourceId)).addModule("feature", module -> module.setResourceTable(resourceTable).setManifest(androidManifest("com.test.app"))).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleConfigValidator().validateBundle(appBundle));
    assertThat(e).hasMessageThat().contains("The Master Resources list contains resource IDs not defined in any module. " + "For example: 0x7f010001");
}
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) 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 2 with ResourceTableBuilder

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

the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_mixedWithDefaultStrings.

@Test
public void resourcesPinnedToMasterSplit_mixedWithDefaultStrings() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("default_label", "label").addStringResourceForMultipleLocales("pinned_label", ImmutableMap.of("en", "yes")).addStringResourceForMultipleLocales("split_label", ImmutableMap.of("en", "no")).build();
    BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
    ModuleSplit baseSplit = ModuleSplit.forResources(module);
    LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(// pinned_label
    resource -> resource.getResourceId().getFullResourceId() == 0x7f010001);
    Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
    assertThat(languageSplits).hasSize(2);
    ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
    assertThat(masterSplit.getResourceTable()).hasValue(new ResourceTableBuilder().addPackage("com.test.app").addStringResource("default_label", "label").addStringResourceForMultipleLocales("pinned_label", ImmutableMap.of("en", "yes")).build());
    ModuleSplit configSplit = languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(onlyElement());
    assertThat(configSplit.getApkTargeting()).isEqualTo(apkLanguageTargeting("en"));
    assertThat(configSplit.getResourceTable()).hasValue(getStringResourceTable("split_label", 0x02, ImmutableList.of(value("no", locale("en")))));
}
Also used : Iterables(com.google.common.collect.Iterables) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) RunWith(org.junit.runner.RunWith) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) Map(java.util.Map) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Predicates(com.google.common.base.Predicates) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableMap(com.google.common.collect.ImmutableMap) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) TestCase.fail(junit.framework.TestCase.fail) ResourcesTableFactory(com.android.tools.build.bundletool.testing.ResourcesTableFactory) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) ByteString(com.google.protobuf.ByteString) StringPool(com.android.aapt.Resources.StringPool) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Ignore(org.junit.Ignore) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 3 with ResourceTableBuilder

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

the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_noSplitting_fileReferences.

@Test
public void resourcesPinnedToMasterSplit_noSplitting_fileReferences() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).addResource("drawable", "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))).build();
    BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).addFile("res/drawable-en-hdpi/image.jpg").addFile("res/drawable-fr-hdpi/image.jpg").addFile("res/drawable-en-hdpi/image2.jpg").addFile("res/drawable-fr-hdpi/image2.jpg").build();
    ModuleSplit baseSplit = ModuleSplit.forResources(module);
    LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(resource -> resource.getResourceId().getFullResourceId() == 0x7f010000);
    Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
    ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
    assertThat(masterSplit.getResourceTable()).hasValue(new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).build());
    assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image.jpg", "res/drawable-fr-hdpi/image.jpg");
    ImmutableList<ModuleSplit> configSplits = languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    ImmutableMap<ApkTargeting, ModuleSplit> configSplitMap = Maps.uniqueIndex(configSplits, ModuleSplit::getApkTargeting);
    assertThat(configSplitMap.keySet()).containsExactly(apkLanguageTargeting("en"), apkLanguageTargeting("fr"));
    ModuleSplit enSplit = configSplitMap.get(apkLanguageTargeting("en"));
    assertThat(enSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
    0x01, "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI))));
    assertThat(extractPaths(enSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image2.jpg");
    ModuleSplit frSplit = configSplitMap.get(apkLanguageTargeting("fr"));
    assertThat(frSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
    0x01, "image2", fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))));
    assertThat(extractPaths(frSplit.getEntries())).containsExactly("res/drawable-fr-hdpi/image2.jpg");
}
Also used : Iterables(com.google.common.collect.Iterables) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) RunWith(org.junit.runner.RunWith) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) Map(java.util.Map) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Predicates(com.google.common.base.Predicates) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableMap(com.google.common.collect.ImmutableMap) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) TestCase.fail(junit.framework.TestCase.fail) ResourcesTableFactory(com.android.tools.build.bundletool.testing.ResourcesTableFactory) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) ByteString(com.google.protobuf.ByteString) StringPool(com.android.aapt.Resources.StringPool) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Ignore(org.junit.Ignore) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 4 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster_mixedConfigsInSameDensityBucket.

@Test
public void lowestDensityConfigsPinnedToMaster_mixedConfigsInSameDensityBucket() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-ldpi-v21/image.jpg").addFile("res/drawable-ldpi-v24/image.jpg").addFile("res/drawable-xxhdpi/image.jpg").addFile("res/drawable-xxhdpi-v21/image.jpg").addFile("res/drawable-xxhdpi-v24/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.<Configuration, String>builder().put(mergeConfigs(LDPI), "res/drawable-ldpi/image.jpg").put(mergeConfigs(LDPI, sdk(21)), "res/drawable-ldpi-v21/image.jpg").put(mergeConfigs(LDPI, sdk(24)), "res/drawable-ldpi-v24/image.jpg").put(mergeConfigs(XXXHDPI), "res/drawable-xxhdpi/image.jpg").put(mergeConfigs(XXHDPI, sdk(21)), "res/drawable-xxhdpi-v21/image.jpg").put(mergeConfigs(XXHDPI, sdk(24)), "res/drawable-xxhdpi-v24/image.jpg").build()).build()).setManifest(androidManifest("com.test.app")).build();
    // 0x7f010000 is the "drawable/image" resource.
    Predicate<ResourceId> pinnedLowDensityResourcesPredicate = resourceId -> resourceId.getFullResourceId() == 0x7f010000;
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, pinnedLowDensityResourcesPredicate, /* pinLowestBucketOfStylesToMaster= */
    false);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    ModuleSplit masterSplit = densitySplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
    assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-ldpi/image.jpg", "res/drawable-ldpi-v21/image.jpg", "res/drawable-ldpi-v24/image.jpg");
    ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(configSplits).isNotEmpty();
    for (ModuleSplit configSplit : configSplits) {
        assertThat(extractPaths(configSplit.getEntries())).containsNoneOf("res/drawable-ldpi/image.jpg", "res/drawable-ldpi-v21/image.jpg", "res/drawable-ldpi-v24/image.jpg");
    }
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) ImmutableCollection(com.google.common.collect.ImmutableCollection) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ManifestMutator.withSplitsRequired(com.android.tools.build.bundletool.model.ManifestMutator.withSplitsRequired) Item(com.android.aapt.Resources.Item) LDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.LDPI_VALUE) TVDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TVDPI) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) Version(com.android.tools.build.bundletool.model.version.Version) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) XXHDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.XXHDPI) ResourceTable(com.android.aapt.Resources.ResourceTable) Theory(org.junit.experimental.theories.Theory) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) ImmutableSet(com.google.common.collect.ImmutableSet) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableMap(com.google.common.collect.ImmutableMap) XXXHDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.XXXHDPI) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) DEFAULT_DENSITY_BUCKETS(com.android.tools.build.bundletool.splitters.ScreenDensityResourcesSplitter.DEFAULT_DENSITY_BUCKETS) ResourcesTableFactory.sdk(com.android.tools.build.bundletool.testing.ResourcesTableFactory.sdk) XXXHDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.XXXHDPI_VALUE) Collectors(java.util.stream.Collectors) ScreenDensity(com.android.bundle.Targeting.ScreenDensity) Sets(com.google.common.collect.Sets) FromDataPoints(org.junit.experimental.theories.FromDataPoints) ByteString(com.google.protobuf.ByteString) List(java.util.List) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Optional(java.util.Optional) DataPoints(org.junit.experimental.theories.DataPoints) DEFAULT_DENSITY_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.DEFAULT_DENSITY_VALUE) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) Value(com.android.aapt.Resources.Value) RunWith(org.junit.runner.RunWith) MDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.MDPI_VALUE) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) Theories(org.junit.experimental.theories.Theories) TVDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.TVDPI_VALUE) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) Truth8(com.google.common.truth.Truth8) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Predicates(com.google.common.base.Predicates) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourcesTableFactory._560DPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory._560DPI) ManifestProtoUtils.compareManifestMutators(com.android.tools.build.bundletool.testing.ManifestProtoUtils.compareManifestMutators) LDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.LDPI) HDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.HDPI_VALUE) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) TestCase.fail(junit.framework.TestCase.fail) XXHDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.XXHDPI_VALUE) TargetingUtils.assertForNonDefaultSplits(com.android.tools.build.bundletool.testing.TargetingUtils.assertForNonDefaultSplits) Test(org.junit.Test) XHDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.XHDPI) Truth.assertThat(com.google.common.truth.Truth.assertThat) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) ResourcesTableFactory.forDpi(com.android.tools.build.bundletool.testing.ResourcesTableFactory.forDpi) StringPool(com.android.aapt.Resources.StringPool) XHDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.XHDPI_VALUE) TargetingUtils.assertForSingleDefaultSplit(com.android.tools.build.bundletool.testing.TargetingUtils.assertForSingleDefaultSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) ResourceId(com.android.tools.build.bundletool.model.ResourceId) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ByteString(com.google.protobuf.ByteString) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 5 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method lowestDensityStylesPinnedToMaster_disabled.

@Test
public void lowestDensityStylesPinnedToMaster_disabled() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addResource("style", "title_text_size", configValueWithDensity("320dens", Optional.of(XHDPI)), configValueWithDensity("default", Optional.empty())).build()).setManifest(androidManifest("com.test.app")).build();
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster= */
    false);
    ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule));
    ModuleSplit masterSplit = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(extractStyleValues(masterSplit, "title_text_size")).isEmpty();
    ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get();
    assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens");
    ModuleSplit mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI).get();
    assertThat(extractStyleValues(mdpiSplit, "title_text_size")).containsExactly("default");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) 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