Search in sources :

Example 41 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ModuleMatcherTest method matchesModuleTargeting_negative_featureNotPresent.

@Test
public void matchesModuleTargeting_negative_featureNotPresent() {
    ModuleTargeting targeting = mergeModuleTargeting(moduleMinSdkVersionTargeting(21), moduleFeatureTargeting("feature1"));
    DeviceSpec deviceSpecNoFeature = mergeSpecs(deviceWithSdk(21), deviceFeatures("feature2"));
    ModuleMatcher moduleMatcher = new ModuleMatcher(deviceSpecNoFeature);
    assertThat(moduleMatcher.matchesModuleTargeting(targeting)).isFalse();
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) TargetingUtils.mergeModuleTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeModuleTargeting) ModuleTargeting(com.android.bundle.Targeting.ModuleTargeting) Test(org.junit.Test)

Example 42 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetDeviceSpecCommandTest method oneDevice_badSdkVersion_throws.

@Test
public void oneDevice_badSdkVersion_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(1), density(360), abis("x86_64", "x86"), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    // We set up a fake ADB server because the real one won't work on Forge.
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device SDK version");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 43 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetDeviceSpecCommandTest method nonExistentParentDirectory_works.

@Test
public void nonExistentParentDirectory_works() {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("non-existent-parent-directory").resolve("device.json");
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    assertThat(command.execute()).isEqualTo(deviceSpec);
    assertThat(Files.exists(outputPath)).isTrue();
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 44 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ExtractApksCommandTest method deviceSpecViaJavaApi_invalid_throws.

@Test
public void deviceSpecViaJavaApi_invalid_throws() throws Exception {
    DeviceSpec invalidDeviceSpec = deviceWithSdk(-1);
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    Throwable exception = assertThrows(InvalidDeviceSpecException.class, () -> ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(invalidDeviceSpec).build());
    assertThat(exception).hasMessageThat().contains("Device spec SDK version");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Example 45 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ExtractApksCommandTest method builderAndFlagsConstruction_inJavaViaProtos_equivalent.

@Test
public void builderAndFlagsConstruction_inJavaViaProtos_equivalent() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ExtractApksCommand fromFlags = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).build();
    assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7