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);
}
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");
}
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());
}
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");
}
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.");
}
Aggregations