Search in sources :

Example 1 with AdbOptions

use of com.facebook.buck.step.AdbOptions in project buck by facebook.

the class AdbHelperTest method testDeviceFilterEmulator.

/**
   * Verify that when emulator-only mode is enabled only emulators appear in result.
   */
@Test
public void testDeviceFilterEmulator() throws CmdLineException {
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.empty()));
    IDevice[] devices = new IDevice[] { createEmulator("1", IDevice.DeviceState.ONLINE), createRealDevice("2", IDevice.DeviceState.ONLINE) };
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(1, filteredDevices.size());
    assertSame(devices[0], filteredDevices.get(0));
}
Also used : TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IDevice(com.android.ddmlib.IDevice) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 2 with AdbOptions

use of com.facebook.buck.step.AdbOptions in project buck by facebook.

the class AdbHelperTest method whenSerialNumberSetInEnvironmentThenCorrectDeviceFound.

/**
   * Verify that filtering by environment variable works.
   */
@Test
public void whenSerialNumberSetInEnvironmentThenCorrectDeviceFound() throws CmdLineException {
    IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
    for (int i = 0; i < devices.length; i++) {
        AdbHelper myAdbHelper = createAdbHelper(TestExecutionContext.newBuilder().setEnvironment(ImmutableMap.of(AdbHelper.SERIAL_NUMBER_ENV, devices[i].getSerialNumber())).build(), new AdbOptions(), new TargetDeviceOptions());
        List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
        assertNotNull(filteredDevices);
        assertEquals(1, filteredDevices.size());
        assertSame(devices[i], filteredDevices.get(0));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 3 with AdbOptions

use of com.facebook.buck.step.AdbOptions in project buck by facebook.

the class AdbHelperTest method testDeviceFilterBySerial.

/**
   * Verify that filtering by serial number works.
   */
@Test
public void testDeviceFilterBySerial() throws CmdLineException {
    IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
    for (int i = 0; i < devices.length; i++) {
        AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, false, Optional.of(devices[i].getSerialNumber())));
        List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
        assertNotNull(filteredDevices);
        assertEquals(1, filteredDevices.size());
        assertSame(devices[i], filteredDevices.get(0));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 4 with AdbOptions

use of com.facebook.buck.step.AdbOptions in project buck by facebook.

the class AdbHelperTest method testGenymotionIsntARealDevice.

@Test
public void testGenymotionIsntARealDevice() throws Throwable {
    AdbHelper adbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.empty()));
    IDevice[] devices = new IDevice[] { TestDevice.createRealDevice("foobar"), TestDevice.createRealDevice("192.168.57.101:5555") };
    List<IDevice> filtered = adbHelper.filterDevices(devices);
    assertNotNull(filtered);
    assertEquals(1, filtered.size());
    assertEquals("foobar", filtered.get(0).getSerialNumber());
}
Also used : TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IDevice(com.android.ddmlib.IDevice) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 5 with AdbOptions

use of com.facebook.buck.step.AdbOptions in project buck by facebook.

the class AdbHelperTest method testDeviceFilterNoMatchingDevices.

/**
   * Verify that if no devices match filters null is returned.
   */
@Test
public void testDeviceFilterNoMatchingDevices() throws CmdLineException {
    IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, false, Optional.of("invalid-serial")));
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Aggregations

AdbOptions (com.facebook.buck.step.AdbOptions)14 Test (org.junit.Test)14 IDevice (com.android.ddmlib.IDevice)11 TargetDeviceOptions (com.facebook.buck.step.TargetDeviceOptions)11 InstallException (com.android.ddmlib.InstallException)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 TestConsole (com.facebook.buck.testutil.TestConsole)2 File (java.io.File)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2