Search in sources :

Example 16 with XmlAttribute

use of com.android.aapt.Resources.XmlAttribute 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 17 with XmlAttribute

use of com.android.aapt.Resources.XmlAttribute 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 18 with XmlAttribute

use of com.android.aapt.Resources.XmlAttribute 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 19 with XmlAttribute

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

the class XmlProtoElementTest method getAttribute_attributeDoesNotExist.

@Test
public void getAttribute_attributeDoesNotExist() {
    XmlAttribute attribute = XmlAttribute.newBuilder().setName("attribute1").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addAttribute(attribute).build());
    assertThat(element.getAttribute("attribute2")).isEmpty();
    assertThat(element.getAttribute("namespace", "attribute1")).isEmpty();
}
Also used : XmlAttribute(com.android.aapt.Resources.XmlAttribute) Test(org.junit.Test)

Example 20 with XmlAttribute

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

the class XmlProtoElementTest method getAttribute_withName.

@Test
public void getAttribute_withName() {
    XmlAttribute attribute1 = XmlAttribute.newBuilder().setName("attribute1").build();
    XmlAttribute attribute2 = XmlAttribute.newBuilder().setName("attribute1").setNamespaceUri("namespace").build();
    XmlAttribute attribute3 = XmlAttribute.newBuilder().setName("attribute2").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addAttribute(attribute1).addAttribute(attribute2).addAttribute(attribute3).build());
    assertThat(element.getAttribute("attribute1")).hasValue(new XmlProtoAttribute(attribute1));
}
Also used : XmlAttribute(com.android.aapt.Resources.XmlAttribute) Test(org.junit.Test)

Aggregations

XmlAttribute (com.android.aapt.Resources.XmlAttribute)20 Test (org.junit.Test)20 XmlElement (com.android.aapt.Resources.XmlElement)8 XmlNode (com.android.aapt.Resources.XmlNode)2 TestData (com.android.tools.build.bundletool.TestData)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 ALLOW_BACKUP_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.ALLOW_BACKUP_RESOURCE_ID)2 DATA_EXTRACTION_RULES_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.DATA_EXTRACTION_RULES_ATTRIBUTE_NAME)2 DATA_EXTRACTION_RULES_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.DATA_EXTRACTION_RULES_RESOURCE_ID)2 DESCRIPTION_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.DESCRIPTION_ATTRIBUTE_NAME)2 DESCRIPTION_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.DESCRIPTION_RESOURCE_ID)2 FULL_BACKUP_CONTENT_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.FULL_BACKUP_CONTENT_ATTRIBUTE_NAME)2 FULL_BACKUP_CONTENT_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.FULL_BACKUP_CONTENT_RESOURCE_ID)2 FULL_BACKUP_ONLY_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.FULL_BACKUP_ONLY_ATTRIBUTE_NAME)2 FULL_BACKUP_ONLY_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.FULL_BACKUP_ONLY_RESOURCE_ID)2 HAS_CODE_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.HAS_CODE_RESOURCE_ID)2 HAS_FRAGILE_USER_DATA_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.HAS_FRAGILE_USER_DATA_ATTRIBUTE_NAME)2 HAS_FRAGILE_USER_DATA_RESOURCE_ID (com.android.tools.build.bundletool.model.AndroidManifest.HAS_FRAGILE_USER_DATA_RESOURCE_ID)2 ICON_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.ICON_ATTRIBUTE_NAME)2