Search in sources :

Example 1 with StringPool

use of com.android.aapt.Resources.StringPool in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method preservesSourcePool.

@Test
public void preservesSourcePool() throws Exception {
    StringPool sourcePool = StringPool.newBuilder().setData(ByteString.copyFrom(new byte[] { 'x' })).build();
    ResourceTable table = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build().toBuilder().setSourcePool(sourcePool).build();
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/test.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    assertThat(densitySplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
    for (ModuleSplit densitySplit : densitySplits) {
        assertThat(densitySplit.getResourceTable()).isPresent();
        assertThat(densitySplit.getResourceTable().get().getSourcePool()).isEqualTo(sourcePool);
    }
}
Also used : StringPool(com.android.aapt.Resources.StringPool) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 2 with StringPool

use of com.android.aapt.Resources.StringPool in project bundletool by google.

the class ResourceTableMergerTest method sourcePools_equal_sourceReferencesPreserved.

@Test
public void sourcePools_equal_sourceReferencesPreserved() throws Exception {
    StringPool commonSourcePool = StringPool.newBuilder().setData(ByteString.copyFrom(DUMMY_BYTES)).build();
    Source source1 = Source.newBuilder().setPathIdx(42).build();
    Source source2 = Source.newBuilder().setPathIdx(24).build();
    ResourceTable table1 = resourceTable(commonSourcePool, pkg(0x01, "package", type(0x11, "type", entry(0x21, "entry", value("ldpi", LDPI, source1)))));
    ResourceTable table2 = resourceTable(commonSourcePool, pkg(0x02, "package", type(0x11, "type", entry(0x21, "entry", value("ldpi", LDPI, source2)))));
    ResourceTable merged = new ResourceTableMerger().merge(table1, table2);
    assertThat(merged).ignoringRepeatedFieldOrder().isEqualTo(resourceTable(commonSourcePool, pkg(0x01, "package", type(0x11, "type", entry(0x21, "entry", value("ldpi", LDPI, source1)))), pkg(0x02, "package", type(0x11, "type", entry(0x21, "entry", value("ldpi", LDPI, source2))))));
}
Also used : StringPool(com.android.aapt.Resources.StringPool) Source(com.android.aapt.Resources.Source) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 3 with StringPool

use of com.android.aapt.Resources.StringPool in project bundletool by google.

the class ResourceTableMergerTest method sourcePools_presentAndEqual_okAndPreserved.

@Test
public void sourcePools_presentAndEqual_okAndPreserved() throws Exception {
    StringPool sourcePool = StringPool.newBuilder().setData(ByteString.copyFrom("hello", StandardCharsets.UTF_8)).build();
    ResourceTable table = resourceTable().toBuilder().setSourcePool(sourcePool).build();
    assertThat(table.hasSourcePool()).isTrue();
    ResourceTable merged = new ResourceTableMerger().merge(table, table);
    assertThat(merged.hasSourcePool()).isTrue();
    assertThat(merged.getSourcePool()).isEqualTo(sourcePool);
}
Also used : StringPool(com.android.aapt.Resources.StringPool) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 4 with StringPool

use of com.android.aapt.Resources.StringPool in project bundletool by google.

the class LanguageResourcesSplitterTest method languageResources_sourcePoolPreserved.

@Test
public void languageResources_sourcePoolPreserved() throws Exception {
    StringPool sourcePool = StringPool.newBuilder().setData(ByteString.copyFrom(new byte[] { 'x' })).build();
    ResourceTable resourceTable = getStringResourceTable(locale("de"), "Willkommen", Configuration.getDefaultInstance(), "Welcome").toBuilder().setSourcePool(sourcePool).build();
    BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
    ModuleSplit baseSplit = ModuleSplit.forResources(module);
    Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
    assertThat(languageSplits).hasSize(2);
    assertThat(languageSplits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    for (ModuleSplit split : languageSplits) {
        assertThat(split.getResourceTable()).isPresent();
        assertThat(split.getResourceTable().get().getSourcePool()).isEqualTo(sourcePool);
    }
}
Also used : StringPool(com.android.aapt.Resources.StringPool) 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

ResourceTable (com.android.aapt.Resources.ResourceTable)4 StringPool (com.android.aapt.Resources.StringPool)4 Test (org.junit.Test)4 BundleModule (com.android.tools.build.bundletool.model.BundleModule)2 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)2 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)2 Source (com.android.aapt.Resources.Source)1 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)1