use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetDeviceSpecCommandTest method overwriteSet_overwritesFile.
@Test
public void overwriteSet_overwritesFile() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US"));
Path outputPath = tmp.getRoot().toPath().resolve("device.json");
Files.createFile(outputPath);
GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).setOverwriteOutput(true).build().execute();
assertThat(outputPath.toFile().length()).isGreaterThan(0L);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetDeviceSpecCommandTest method overwriteNotSet_outputFileExists_throws.
@Test
public void overwriteNotSet_outputFileExists_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US"));
Path outputPath = tmp.getRoot().toPath().resolve("device.json");
Files.createFile(outputPath);
GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
Throwable exception = assertThrows(IllegalArgumentException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("File '" + outputPath + "' already exists.");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetSizeCommandTest method builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaApi_equivalent.
@Test
public void builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaApi_equivalent() throws Exception {
DeviceSpec deviceSpec = deviceWithSdk(21);
Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
GetSizeCommand fromFlags = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--apks=" + apksArchiveFile, // Optional values.
"--device-spec=" + deviceSpecFile));
GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setGetSizeSubCommand(GetSizeSubcommand.TOTAL).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetSizeCommandTest method checkFlagsConstructionWithDeviceSpec.
@Test
@Theory
public void checkFlagsConstructionWithDeviceSpec(@FromDataPoints("deviceSpecs") String deviceSpecPath) throws Exception {
DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
try (Reader reader = TestData.openReader(deviceSpecPath)) {
JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
}
DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
Path deviceSpecFile = copyToTempDir(deviceSpecPath);
GetSizeCommand command = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetSizeCommandTest method deviceSpecUnknownExtension_throws.
@Test
public void deviceSpecUnknownExtension_throws() throws Exception {
DeviceSpec deviceSpec = deviceWithSdk(21);
Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("bad_filename.dat"));
BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
ParsedFlags flags = new FlagParser().parse("get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile);
Throwable exception = assertThrows(InvalidDeviceSpecException.class, () -> GetSizeCommand.fromFlags(flags));
assertThat(exception).hasMessageThat().contains("Expected .json extension for the device spec");
}
Aggregations