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