Search in sources :

Example 16 with XmlElement

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

the class ManifestEditorTest method setHasCode_true.

@Test
public void setHasCode_true() throws Exception {
    AndroidManifest androidManifest = createManifestWithApplicationElement();
    AndroidManifest editedManifest = androidManifest.toEditor().setHasCode(true).save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.hasElement()).isTrue();
    XmlElement manifestElement = manifestRoot.getElement();
    assertThat(manifestElement.getName()).isEqualTo("manifest");
    assertThat(manifestElement.getChildCount()).isEqualTo(1);
    XmlNode applicationNode = manifestElement.getChild(0);
    assertThat(applicationNode.hasElement()).isTrue();
    XmlElement applicationElement = manifestElement.getChild(0).getElement();
    assertThat(applicationElement.getAttributeList()).containsExactly(xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "hasCode", HAS_CODE_RESOURCE_ID, true));
    assertThat(applicationElement.getChildList()).isEmpty();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 17 with XmlElement

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

the class XmlProtoElementBuilderTest method getOrCreateAttribute_attributeAlreadyExists.

@Test
public void getOrCreateAttribute_attributeAlreadyExists() {
    XmlAttribute attribute = XmlAttribute.newBuilder().setName("attribute").build();
    XmlElement protoElement = XmlElement.newBuilder().addAttribute(attribute).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    XmlProtoAttributeBuilder fetchedAttribute = element.getOrCreateAttribute("attribute");
    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 XmlElement

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

the class XmlProtoElementBuilderTest method removeAndroidAttribute_namespaceNotMatching.

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

Example 19 with XmlElement

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

the class XmlProtoElementBuilderTest method addChildText.

@Test
public void addChildText() {
    XmlElement protoElement = XmlElement.getDefaultInstance();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.addChildText("hello");
    assertThat(element.getProto().build()).isEqualTo(protoElement.toBuilder().addChild(XmlNode.newBuilder().setText("hello")).build());
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 20 with XmlElement

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

the class XmlProtoElementBuilderTest method removeAndroidAttribute_resourceNotMatching.

@Test
public void removeAndroidAttribute_resourceNotMatching() {
    XmlElement protoElement = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("attribute").setNamespaceUri(ANDROID_NAMESPACE_URI).setResourceId(0x1234)).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.removeAndroidAttribute(0x123);
    assertThat(element.getProto().build()).isEqualTo(protoElement);
}
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