Search in sources :

Example 71 with BundleModuleBuilder

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

the class SanitizerNativeLibrariesSplitterTest method splittingBySanitizer.

@Test
public void splittingBySanitizer() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").addFile("lib/arm64-v8a-hwasan/libtest.so").setManifest(androidManifest("com.test.app")).build();
    SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
    ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
    ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
    assertThat(splits).hasSize(2);
    ModuleSplit nonHwasanSplit = splits.asList().get(1);
    assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
    assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
    ModuleSplit hwasanSplit = splits.asList().get(0);
    assertThat(hwasanSplit.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(ARM64_V8A), apkSanitizerTargeting(HWADDRESS)));
    assertThat(extractPaths(hwasanSplit.getEntries())).containsExactly("lib/arm64-v8a-hwasan/libtest.so");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 72 with BundleModuleBuilder

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

the class ScreenDensityResourcesSplitterTest method complexDensitySplit.

@Test
public void complexDensitySplit() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "mipmap", entry(0x01, "launcher_icon", fileReference("res/mipmap-hdpi/launcher_icon.png", HDPI), fileReference("res/mipmap/launcher_icon.png", Configuration.getDefaultInstance()))), type(0x02, "drawable", entry(0x01, "title_image", fileReference("res/drawable-hdpi/title_image.jpg", HDPI), fileReference("res/drawable-xhdpi/title_image.jpg", XHDPI)))));
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/mipmap/launcher_icon.png").addFile("res/mipmap-hdpi/launcher_icon.png").addFile("res/drawable-hdpi/title_image.jpg").addFile("res/drawable-xhdpi/title_image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> allSplits = splitter.split(ModuleSplit.forResources(testModule));
    assertThat(allSplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
    assertForSingleDefaultSplit(allSplits, defaultSplit -> {
        assertThat(defaultSplit.getResourceTable()).isPresent();
        ResourceTable resourceTable = defaultSplit.getResourceTable().get();
        assertThat(resourceTable).containsResource("com.test.app:mipmap/launcher_icon").withConfigSize(2).withDensity(HDPI_VALUE).withDensity(DEFAULT_DENSITY_VALUE);
        assertThat(resourceTable).doesNotContainResource("com.test.app:drawable/title_image");
    });
    assertForNonDefaultSplits(allSplits, densitySplit -> {
        assertThat(densitySplit.getResourceTable()).isPresent();
        ResourceTable resourceTable = densitySplit.getResourceTable().get();
        assertThat(resourceTable).hasPackage("com.test.app").withNoType("mipmap");
        assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").withConfigSize(1);
        assertThat(densitySplit.getApkTargeting().hasScreenDensityTargeting()).isTrue();
        switch(densitySplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias()) {
            case LDPI:
            case MDPI:
            case TVDPI:
            case HDPI:
                assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(HDPI);
                break;
            case XHDPI:
            case XXHDPI:
            case XXXHDPI:
                assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(XHDPI);
                break;
            default:
                fail(String.format("Unexpected targeting: %s", densitySplit.getApkTargeting()));
                break;
        }
    });
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 73 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder 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)

Example 74 with BundleModuleBuilder

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

the class ScreenDensityResourcesSplitterTest method twoDensitiesInSameBucket.

@Test
public void twoDensitiesInSameBucket() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-xxhdpi/image.png", XXHDPI), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
    BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-xxhdpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
    ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
    assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable resourceTable = xxxhdpiSplit.getResourceTable().get();
    assertThat(resourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(XXXHDPI_VALUE).withDensity(560);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 75 with BundleModuleBuilder

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

the class ScreenDensityResourcesSplitterTest method densityBucket_neighbouringResources_edgeCase.

/**
 * An edge case where xxxhdpi split capturing devices from 527dpi and above should capture 512dpi
 * resources and above.
 *
 * <p>The 512dpi threshold depends on what other dpi values are available. Here, it's driven by
 * the presence of 560dpi config value. A 527dpi device prefers 512dpi over 560dpi.
 *
 * <p>The 512dpi resource should also be present in the xxhdpi split. It targets all devices up to
 * 526dpi.
 */
@Test
public void densityBucket_neighbouringResources_edgeCase() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-mdpi/image.png", MDPI), fileReference("res/drawable-512dpi/image.png", forDpi(512)), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
    BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-mdpi/image.png").addFile("res/drawable-512dpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(ImmutableSet.of(DensityAlias.XXHDPI, DensityAlias.XXXHDPI), BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster =*/
    false);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
    ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
    assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable xxxHdpiResourceTable = xxxhdpiSplit.getResourceTable().get();
    assertThat(xxxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(3).withDensity(XXXHDPI_VALUE).withDensity(560).withDensity(512);
    ModuleSplit xxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXHDPI).build());
    Truth8.assertThat(xxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable xxHdpiResourceTable = xxhdpiSplit.getResourceTable().get();
    assertThat(xxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(MDPI_VALUE).withDensity(512);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)349 Test (org.junit.Test)348 BundleModule (com.android.tools.build.bundletool.model.BundleModule)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)164 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)69 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)44 ResourceTable (com.android.aapt.Resources.ResourceTable)38 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)28 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)16 Truth.assertThat (com.google.common.truth.Truth.assertThat)16 RunWith (org.junit.runner.RunWith)16 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 ImmutableList (com.google.common.collect.ImmutableList)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)15 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)14 NativeLibraries (com.android.bundle.Files.NativeLibraries)13 HDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI)13 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)13