Search in sources :

Example 21 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class AdbShellCommandTaskTest method commandExecution_IOException.

@Test
public void commandExecution_IOException() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.injectShellCommandOutput("getprop", () -> {
        throw new IOException("I/O error.");
    });
    AdbShellCommandTask task = new AdbShellCommandTask(fakeDevice, "getprop");
    Throwable e = assertThrows(CommandExecutionException.class, () -> task.execute());
    assertThat(e).hasMessageThat().contains("I/O error while executing 'adb shell");
    assertThat(e).hasCauseThat().isInstanceOf(IOException.class);
}
Also used : IOException(java.io.IOException) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 22 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallApksCommandTest method installsOnlySpecifiedModules.

@Test
@Theory
public void installsOnlySpecifiedModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet("feature1", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet("feature2", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))))).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("base", "feature2")).build().execute();
    assertThat(getFileNames(installedApks)).containsExactly("base-master.apk", "feature1-master.apk", "feature2-master.apk");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 23 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallApksCommandTest method localTestingMode_additionalLocalTestingFiles.

@Test
public void localTestingMode_additionalLocalTestingFiles() throws Exception {
    ZipPath baseApk = ZipPath.create("base-master.apk");
    ZipPath baseEnApk = ZipPath.create("base-en.apk");
    ZipPath onDemandFeatureMasterApk = ZipPath.create("ondemand_feature-master.apk");
    Path additionalXml = tmpDir.resolve("additional.xml");
    Files.write(additionalXml, new byte[0]);
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
    false)), createSplitApkSet("ondemand_feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
    Path apksFile = createApks(tableOfContent, /* apksInDirectory= */
    false);
    List<Path> installedApks = new ArrayList<>();
    List<Path> pushedFiles = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setAdditionalLocalTestingFiles(ImmutableList.of(additionalXml)).build().execute();
    // Base, install-time and on-demand features and install-time assets.
    assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString());
    // Base config splits, install-time and on-demand features and on-demand assets. All languages.
    assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), onDemandFeatureMasterApk.toString(), additionalXml.getFileName().toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 24 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallApksCommandTest method badAbisDevice_throws.

@Test
@Theory
public void badAbisDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), locales("en-US"));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device ABIs");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 25 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallApksCommandTest method incompleteApksFile_missingAbiSplitMatchedForDevice_throws.

@Test
public void incompleteApksFile_missingAbiSplitMatchedForDevice_throws() throws Exception {
    // Partial APK Set file where 'x86' split is included and 'x86_64' split is not included because
    // device spec sent to 'build-apks' command doesn't support it.
    // Next, device spec that should be matched to 'x86_64' split is provided to 'install-apks'
    // command and command must throw IncompatibleDeviceException as mathed split 'x86_64' is not
    // available.
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"))))).build();
    Path apksFile = createApks(tableOfContent, /* apksInDirectory= */
    false);
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(DensityAlias.MDPI), abis("x86_64", "x86"), locales("en-US"));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("Missing APKs for [ABI] dimensions in the module 'base' for the provided device.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)32 Test (org.junit.Test)32 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)24 AdbServer (com.android.tools.build.bundletool.device.AdbServer)17 Path (java.nio.file.Path)17 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 BuildApksResult (com.android.bundle.Commands.BuildApksResult)13 DeviceSpec (com.android.bundle.Devices.DeviceSpec)10 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 Duration (java.time.Duration)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 DeviceState (com.android.ddmlib.IDevice.DeviceState)1 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 InstallOptions (com.android.tools.build.bundletool.device.Device.InstallOptions)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 DeviceFactory.lDeviceWithLocales (com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1