use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.XXHDPI 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");
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.XXHDPI 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");
}
}
}
Aggregations