Search in sources :

Example 66 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method allSplitsPresentWithResourceTable.

@Test
public void allSplitsPresentWithResourceTable() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
    ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    for (ModuleSplit resourceSplit : densitySplits) {
        assertThat(resourceSplit.getResourceTable().isPresent()).isTrue();
    }
    List<ApkTargeting> targeting = densitySplits.stream().map(split -> split.getApkTargeting()).collect(Collectors.toList());
    assertThat(targeting).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance(), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.MDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.HDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.TVDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI))));
}
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) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 67 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method resourcesPinnedToMaster_splittingSupressed.

@Test
public void resourcesPinnedToMaster_splittingSupressed() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-mdpi/image2.jpg").addFile("res/drawable-hdpi/image2.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/image.jpg", /* hdpi */
    240, "res/drawable-hdpi/image.jpg")).addDrawableResourceForMultipleDensities("image2", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/image2.jpg", /* hdpi */
    240, "res/drawable-hdpi/image2.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
    Predicate<ResourceId> masterResourcesPredicate = resourceId -> resourceId.getFullResourceId() == 0x7f010000;
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), masterResourcesPredicate, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster= */
    false);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(configSplits).isNotEmpty();
    for (ModuleSplit configSplit : configSplits) {
        assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-mdpi/image.jpg");
        assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-hdpi/image.jpg");
    }
    ModuleSplit masterSplit = densitySplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
    assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-mdpi/image.jpg", "res/drawable-hdpi/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) ResourceId(com.android.tools.build.bundletool.model.ResourceId) 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)

Example 68 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method lowestDensityStylesPinnedToMaster_enabled.

@Test
public void lowestDensityStylesPinnedToMaster_enabled() 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= */
    true);
    ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule));
    ModuleSplit masterSplit = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(extractStyleValues(masterSplit, "title_text_size")).containsExactly("default");
    ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get();
    assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens");
    Optional<ModuleSplit> mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI);
    assertThat(mdpiSplit).isEmpty();
}
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)

Example 69 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method picksTheResourceForExactDensity.

@Test
public void picksTheResourceForExactDensity() throws Exception {
    ResourceTable table = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.<Integer, String>builder().put(LDPI_VALUE, "res/drawable-ldpi/image.jpg").put(MDPI_VALUE, "res/drawable-mdpi/image.jpg").put(TVDPI_VALUE, "res/drawable-tvdpi/image.jpg").put(HDPI_VALUE, "res/drawable-hdpi/image.jpg").put(XHDPI_VALUE, "res/drawable-xhdpi/image.jpg").put(XXHDPI_VALUE, "res/drawable-xxhdpi/image.jpg").put(XXXHDPI_VALUE, "res/drawable-xxxhdpi/image.jpg").build()).build();
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-tvdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-xhdpi/image.jpg").addFile("res/drawable-xxhdpi/image.jpg").addFile("res/drawable-xxxhdpi/image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    assertThat(densitySplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
    assertThat(densitySplits.stream().map(split -> split.getApkTargeting()).collect(toImmutableSet())).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance(), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.MDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.HDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.TVDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI))));
    for (ModuleSplit densitySplit : densitySplits) {
        assertThat(densitySplit.getResourceTable().isPresent()).isTrue();
        ResourceTable splitResourceTable = densitySplit.getResourceTable().get();
        // we are not verifying the default split in this test.
        if (densitySplit.getApkTargeting().equals(ApkTargeting.getDefaultInstance())) {
            continue;
        }
        assertThat(densitySplit.getApkTargeting().hasScreenDensityTargeting()).isTrue();
        switch(densitySplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias()) {
            case LDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(LDPI);
                break;
            case MDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(MDPI);
                break;
            case TVDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(TVDPI);
                break;
            case HDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(HDPI);
                break;
            case XHDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XHDPI);
                break;
            case XXHDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XXHDPI);
                break;
            case XXXHDPI:
                assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XXXHDPI);
                break;
            default:
                break;
        }
    }
}
Also used : 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) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 70 with ResourceTableBuilder

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

the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster.

@Test
public void lowestDensityConfigsPinnedToMaster() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-mdpi/image2.jpg").addFile("res/drawable-hdpi/image2.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/image.jpg", /* hdpi */
    240, "res/drawable-hdpi/image.jpg")).addDrawableResourceForMultipleDensities("image2", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/image2.jpg", /* hdpi */
    240, "res/drawable-hdpi/image2.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
    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-mdpi/image.jpg");
    ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(configSplits).isNotEmpty();
    for (ModuleSplit configSplit : configSplits) {
        assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-mdpi/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) ResourceId(com.android.tools.build.bundletool.model.ResourceId) 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