Search in sources :

Example 51 with XmlElement

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

the class XmlProtoElementBuilderTest method getAndroidAttribute_duplicate.

@Test
public void getAndroidAttribute_duplicate() {
    XmlAttribute attribute = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace").setResourceId(42).build();
    XmlElement protoElement = XmlElement.newBuilder().addAttribute(attribute).addAttribute(attribute).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    XmlProtoAttributeBuilder fetchedAttribute = element.getAndroidAttribute(42).get();
    assertThat(fetchedAttribute.getProto().build()).isEqualTo(attribute);
    assertThat(element.getProto().build()).isEqualTo(protoElement);
}
Also used : XmlAttribute(com.android.aapt.Resources.XmlAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 52 with XmlElement

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

the class XmlProtoElementBuilderTest method getAttribute_duplicate.

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

Example 53 with XmlElement

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

the class XmlProtoElementBuilderTest method getOrCreateChildElement_withNamespace_childDoesNotExist.

@Test
public void getOrCreateChildElement_withNamespace_childDoesNotExist() {
    XmlElement protoElement = XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("hello"))).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    XmlProtoElementBuilder fetchedElement = element.getOrCreateChildElement("namespace", "hello");
    assertThat(fetchedElement.getProto().build()).isEqualTo(XmlElement.newBuilder().setName("hello").setNamespaceUri("namespace").build());
    assertThat(element.getProto().build()).isEqualTo(protoElement.toBuilder().addChild(XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("hello").setNamespaceUri("namespace"))).build());
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 54 with XmlElement

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

the class XmlProtoElementBuilderTest method getOrCreateAndroidAttribute_attributeAlreadyExists.

@Test
public void getOrCreateAndroidAttribute_attributeAlreadyExists() {
    XmlAttribute attributeNotAndroid = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace").setResourceId(0x123).build();
    XmlAttribute attributeAndroid = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri(ANDROID_NAMESPACE_URI).setResourceId(0x123).build();
    XmlAttribute attributeNoNamespace = XmlAttribute.newBuilder().setName("attribute").setResourceId(0x123).build();
    XmlElement protoElement = XmlElement.newBuilder().addAttribute(attributeNotAndroid).addAttribute(attributeAndroid).addAttribute(attributeNoNamespace).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    XmlProtoAttributeBuilder fetchedAttribute = element.getOrCreateAndroidAttribute("attribute", 0x123);
    assertThat(fetchedAttribute.getProto().build()).isEqualTo(attributeAndroid);
    assertThat(element.getProto().build()).isEqualTo(protoElement);
}
Also used : XmlAttribute(com.android.aapt.Resources.XmlAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 55 with XmlElement

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

the class XmlProtoElementBuilderTest method getNamespaceDeclarations.

@Test
public void getNamespaceDeclarations() {
    XmlElement protoElement = XmlElement.getDefaultInstance();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.addNamespaceDeclaration("ns", "http://namespace");
    element.addNamespaceDeclaration("ns2", "http://namespace2");
    assertThat(element.getNamespaceDeclarations()).containsExactly(XmlProtoNamespace.create("ns", "http://namespace"), XmlProtoNamespace.create("ns2", "http://namespace2"));
}
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