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))));
}
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");
}
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();
}
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;
}
}
}
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");
}
}
Aggregations