use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI 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");
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method manifestMutatorToRequireSplits_registered_whenDensityResourcesPresent.
@Test
public void manifestMutatorToRequireSplits_registered_whenDensityResourcesPresent() 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(MDPI_VALUE, "res/drawable-ldpi/image.jpg", HDPI_VALUE, "res/drawable-dpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
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(compareManifestMutators(configSplit.getMasterManifestMutators(), withSplitsRequired(true))).isTrue();
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster_masterCoversRangeOfDensities.
@Test
public void lowestDensityConfigsPinnedToMaster_masterCoversRangeOfDensities() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-xxxhdpi/image.jpg").addFile("res/drawable-ldpi/other.jpg").addFile("res/drawable-mdpi/other.jpg").addFile("res/drawable-tvdpi/other.jpg").addFile("res/drawable-xhdpi/other.jpg").addFile("res/drawable-xxhdpi/other.jpg").addFile("res/drawable-xxxhdpi/other.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* ldpi */
120, "res/drawable-ldpi/image.jpg", /* xxxhdpi */
640, "res/drawable-xxxhdpi/image.jpg")).addDrawableResourceForMultipleDensities("other", ImmutableMap.<Integer, String>builder().put(/* ldpi */
120, "res/drawable-ldpi/other.jpg").put(/* mdpi */
160, "res/drawable-mdpi/other.jpg").put(/* tvdpi */
213, "res/drawable-tvdpi/other.jpg").put(/* hdpi */
240, "res/drawable-hdpi/other.jpg").put(/* xhdpi */
320, "res/drawable-xhdpi/other.jpg").put(/* xxhdpi */
480, "res/drawable-xxhdpi/other.jpg").put(/* xxxhdpi */
640, "res/drawable-xxxhdpi/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));
ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
assertThat(configSplits).isNotEmpty();
for (ModuleSplit configSplit : configSplits) {
DensityAlias targetDensity = configSplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias();
switch(targetDensity) {
case LDPI:
case MDPI:
// Devices <= MDPI are covered by the LDPI config.
assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-xxxhdpi/image.jpg");
break;
default:
// Devices > MDPI are covered by the XXXHDPI config.
assertThat(extractPaths(configSplit.getEntries())).contains("res/drawable-xxxhdpi/image.jpg");
}
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI 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.ResourcesTableFactory.HDPI 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");
}
Aggregations