Search in sources :

Example 61 with XmlElement

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

the class XmlProtoElementTest method getOptionalChildElement_withNamespace_oneElement.

@Test
public void getOptionalChildElement_withNamespace_oneElement() {
    XmlElement childElement = XmlElement.newBuilder().setName("child").setNamespaceUri("namespace").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(XmlNode.newBuilder().setElement(childElement)).build());
    assertThat(element.getOptionalChildElement("namespace", "child")).hasValue(new XmlProtoElement(childElement));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 62 with XmlElement

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

the class XmlProtoElementTest method getChildElement_manyElements_throws.

@Test
public void getChildElement_manyElements_throws() {
    XmlElement childElement = XmlElement.newBuilder().setName("child").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(childElement)).build());
    assertThrows(XmlProtoException.class, () -> element.getChildElement("child"));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 63 with XmlElement

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

the class XmlProtoElementTest method getOptionalChildElement_withNamespace_manyElements_throws.

@Test
public void getOptionalChildElement_withNamespace_manyElements_throws() {
    XmlElement childElement = XmlElement.newBuilder().setName("child").setNamespaceUri("namespace").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(childElement)).build());
    assertThrows(XmlProtoException.class, () -> element.getOptionalChildElement("namespace", "child"));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 64 with XmlElement

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

the class XmlProtoElementTest method getChildrenElements_withNameAndNamespace.

@Test
public void getChildrenElements_withNameAndNamespace() {
    XmlElement childElement1 = XmlElement.newBuilder().setName("child").setNamespaceUri("namespace").build();
    XmlElement childElement2 = XmlElement.newBuilder().setName("child").setNamespaceUri("namespace").addAttribute(XmlAttribute.newBuilder().setName("test").build()).build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(childElement1)).addChild(XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("other"))).addChild(XmlNode.newBuilder().setElement(childElement1.toBuilder().clearNamespaceUri())).addChild(XmlNode.newBuilder().setElement(childElement2)).build());
    assertThat(element.getChildrenElements("namespace", "child")).containsExactly(new XmlProtoElement(childElement1), new XmlProtoElement(childElement2));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 65 with XmlElement

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

the class ModuleSplitterTest method splitNameNotRemovedForInstantSplit.

@Test
public void splitNameNotRemovedForInstantSplit() throws Exception {
    XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "testModule"));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
    ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createNoStamp(bundleModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule")).splitModule();
    assertThat(moduleSplits).hasSize(1);
    ModuleSplit masterSplit = moduleSplits.get(0);
    ImmutableList<XmlElement> activities = masterSplit.getAndroidManifest().getManifestRoot().getElement().getChildElement("application").getChildrenElements(ACTIVITY_ELEMENT_NAME).map(XmlProtoElement::getProto).collect(toImmutableList());
    assertThat(activities).hasSize(2);
    XmlElement activityElement = activities.get(1);
    assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "FooActivity"), xmlAttribute(ANDROID_NAMESPACE_URI, "splitName", SPLIT_NAME_RESOURCE_ID, "testModule"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) XmlElement(com.android.aapt.Resources.XmlElement) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

XmlElement (com.android.aapt.Resources.XmlElement)67 Test (org.junit.Test)65 XmlNode (com.android.aapt.Resources.XmlNode)27 XmlAttribute (com.android.aapt.Resources.XmlAttribute)10 BundleModule (com.android.tools.build.bundletool.model.BundleModule)4 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)4 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)4 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)4 RunWith (org.junit.runner.RunWith)4 JUnit4 (org.junit.runners.JUnit4)4 SourcePosition (com.android.aapt.Resources.SourcePosition)3 XmlNamespace (com.android.aapt.Resources.XmlNamespace)2 TestData (com.android.tools.build.bundletool.TestData)2 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)2 ACTIVITY_ELEMENT_NAME (com.android.tools.build.bundletool.model.AndroidManifest.ACTIVITY_ELEMENT_NAME)2 ALLOW_BACKUP_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.ALLOW_BACKUP_ATTRIBUTE_NAME)2