Search in sources :

Example 26 with XmlElement

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

the class XmlProtoElementTest method getChildElement_oneElement.

@Test
public void getChildElement_oneElement() {
    XmlElement childElement = XmlElement.newBuilder().setName("child").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(XmlNode.newBuilder().setElement(childElement)).build());
    assertThat(element.getChildElement("child")).isEqualTo(new XmlProtoElement(childElement));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 27 with XmlElement

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

the class XmlProtoElementTest method getChildElement_withNamespace_manyElements_throws.

@Test
public void getChildElement_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.getChildElement("namespace", "child"));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 28 with XmlElement

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

the class XmlProtoElementBuilderTest method removeAttribute_nameNotMatching.

@Test
public void removeAttribute_nameNotMatching() {
    XmlElement protoElement = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace")).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.removeAttribute("namespace", "otherName");
    assertThat(element.getProto().build()).isEqualTo(protoElement);
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 29 with XmlElement

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

the class XmlProtoElementBuilderTest method removeSourceDataRecursive.

@Test
public void removeSourceDataRecursive() {
    SourcePosition sourcePosition = SourcePosition.newBuilder().setLineNumber(12).setColumnNumber(32).build();
    XmlElement element = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setSource(sourcePosition).setName("name1").setValue("value")).addAttribute(XmlAttribute.newBuilder().setSource(sourcePosition).setName("name2").setValue("value")).addNamespaceDeclaration(XmlNamespace.newBuilder().setSource(sourcePosition).setPrefix("pref").setUri("http://uri")).addChild(XmlNode.newBuilder().setElement(XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setSource(sourcePosition).setName("nested").setValue("another")))).addChild(XmlNode.newBuilder().setSource(sourcePosition).setText("Text1")).addChild(XmlNode.newBuilder().setSource(sourcePosition).setText("Text2")).build();
    XmlElement elementWithoutSource = new XmlProtoElementBuilder(element.toBuilder()).removeSourceDataRecursive().build().getProto();
    XmlElement expected = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("name1").setValue("value")).addAttribute(XmlAttribute.newBuilder().setName("name2").setValue("value")).addNamespaceDeclaration(XmlNamespace.newBuilder().setPrefix("pref").setUri("http://uri")).addChild(XmlNode.newBuilder().setElement(XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("nested").setValue("another")))).addChild(XmlNode.newBuilder().setText("Text1")).addChild(XmlNode.newBuilder().setText("Text2")).build();
    assertThat(elementWithoutSource).isEqualTo(expected);
}
Also used : SourcePosition(com.android.aapt.Resources.SourcePosition) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 30 with XmlElement

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

the class XmlProtoElementBuilderTest method addNamespaceDeclaration.

@Test
public void addNamespaceDeclaration() {
    XmlElement protoElement = XmlElement.getDefaultInstance();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.addNamespaceDeclaration("ns", "http://namespace");
    assertThat(element.getProto().build()).isEqualTo(protoElement.toBuilder().addNamespaceDeclaration(XmlNamespace.newBuilder().setPrefix("ns").setUri("http://namespace")).build());
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) 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