Search in sources :

Example 36 with XmlNode

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

the class ManifestEditorTest method setFeatureSplit_forDynamicSplit_duplicateSplitId.

/**
 * Tests regression where we didn't handle properly manifests with already populated split id.
 */
@Test
public void setFeatureSplit_forDynamicSplit_duplicateSplitId() throws Exception {
    AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", ImmutableList.of(xmlAttribute("split", "feature1"), xmlAttribute("package", "com.test.app"), xmlAttribute("split", "feature1")), xmlNode(xmlElement("application")))));
    AndroidManifest editedManifest = androidManifest.toEditor().setSplitIdForFeatureSplit("feature1").save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.hasElement()).isTrue();
    XmlElement manifestElement = manifestRoot.getElement();
    assertThat(manifestElement.getName()).isEqualTo("manifest");
    assertThat(manifestElement.getChildList()).containsExactly(xmlNode(xmlElement("application")));
    assertThat(manifestElement.getAttributeList()).containsExactly(xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "isFeatureSplit", IS_FEATURE_SPLIT_RESOURCE_ID, true), xmlAttribute("split", "feature1"), xmlAttribute("package", "com.test.app"), xmlAttribute("split", "feature1"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 37 with XmlNode

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

the class ManifestEditorTest method setTargetSandboxVersion.

@Test
public void setTargetSandboxVersion() {
    AndroidManifest androidManifest = createManifestWithApplicationElement();
    AndroidManifest editedManifest = androidManifest.toEditor().setTargetSandboxVersion(2).save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.hasElement()).isTrue();
    XmlElement manifestElement = manifestRoot.getElement();
    assertThat(manifestElement.getName()).isEqualTo("manifest");
    assertThat(manifestElement.getAttributeList()).containsExactly(xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "targetSandboxVersion", TARGET_SANDBOX_VERSION_RESOURCE_ID, 2));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 38 with XmlNode

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

the class ManifestEditorTest method setSharedUserLabel.

@Test
public void setSharedUserLabel() {
    AndroidManifest androidManifest = createManifestWithApplicationElement();
    AndroidManifest editedManifest = androidManifest.toEditor().setSharedUserLabel(0x12345678).save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.getElement().getAttributeList()).containsExactly(xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, SHARED_USER_LABEL_ATTRIBUTE_NAME, SHARED_USER_LABEL_RESOURCE_ID, 0x12345678));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 39 with XmlNode

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

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

the class DumpManagerTest method dumpManifest_withXPath_noNamespaceDeclaration.

@Test
public void dumpManifest_withXPath_noNamespaceDeclaration() throws Exception {
    XmlNode manifestWithoutNamespaceDeclaration = androidManifest("com.app", withDebuggableAttribute(true), manifestElement -> manifestElement.getProto().clearNamespaceDeclaration());
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestWithoutNamespaceDeclaration)).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/@android:debuggable").setOutputStream(new PrintStream(outputStream)).build().execute();
    assertThat(new String(outputStream.toByteArray(), UTF_8).trim()).isEqualTo("true");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) XmlAttribute(com.android.aapt.Resources.XmlAttribute) DumpTarget(com.android.tools.build.bundletool.commands.DumpCommand.DumpTarget) Bundletool(com.android.bundle.Config.Bundletool) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Path(java.nio.file.Path) ResourceTable(com.android.aapt.Resources.ResourceTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) PrintStream(java.io.PrintStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withDebuggableAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDebuggableAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Compression(com.android.bundle.Config.Compression) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) PrintStream(java.io.PrintStream) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9