Search in sources :

Example 6 with TargetDeviceOptions

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

the class AdbHelperTest method testDeviceFilterMultipleDevices.

/**
   * Verify that multi-install is not enabled and multiple devices
   * pass the filter null is returned. Also verify that if multiple
   * devices are passing the filter and multi-install mode is enabled
   * they all appear in resulting list.
   */
@Test
public void testDeviceFilterMultipleDevices() throws CmdLineException {
    IDevice[] devices = new IDevice[] { createEmulator("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("4", IDevice.DeviceState.ONLINE), createRealDevice("5", IDevice.DeviceState.ONLINE) };
    List<IDevice> filteredDevicesNoMultiInstall = basicAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevicesNoMultiInstall);
    assertEquals(devices.length, filteredDevicesNoMultiInstall.size());
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(0, true), new TargetDeviceOptions());
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(devices.length, filteredDevices.size());
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 7 with TargetDeviceOptions

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

the class AdbHelperTest method testEmulatorAddsGenymotionDevices.

@Test
public void testEmulatorAddsGenymotionDevices() throws Throwable {
    AdbHelper adbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.empty()));
    IDevice[] devices = new IDevice[] { TestDevice.createRealDevice("foobarblahblah"), TestDevice.createRealDevice("192.168.57.101:5555") };
    List<IDevice> filtered = adbHelper.filterDevices(devices);
    assertNotNull(filtered);
    assertEquals(1, filtered.size());
    assertEquals("192.168.57.101:5555", 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 8 with TargetDeviceOptions

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

the class AdbHelperTest method testQuietDeviceInstall.

@Test
public void testQuietDeviceInstall() throws InterruptedException {
    final File apk = new File("/some/file.apk");
    final AtomicReference<String> apkPath = new AtomicReference<>();
    TestDevice device = new TestDevice() {

        @Override
        public void installPackage(String s, boolean b, String... strings) throws InstallException {
            apkPath.set(s);
        }
    };
    device.setSerialNumber("serial#1");
    device.setName("testDevice");
    final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
    TestConsole console = new TestConsole();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {

        @Override
        protected boolean isDeviceTempWritable(IDevice device, String name) {
            return true;
        }

        @Override
        public List<IDevice> getDevices(boolean quiet) {
            return deviceList;
        }
    };
    boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {

        @Override
        public boolean call(IDevice device) throws Exception {
            return basicAdbHelper.installApkOnDevice(device, apk, false, true);
        }

        @Override
        public String toString() {
            return "install apk";
        }
    }, true);
    assertTrue(success);
    assertEquals(apk.getAbsolutePath(), apkPath.get());
    assertEquals("", console.getTextWrittenToStdOut());
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IDevice(com.android.ddmlib.IDevice) AtomicReference(java.util.concurrent.atomic.AtomicReference) AdbOptions(com.facebook.buck.step.AdbOptions) CmdLineException(org.kohsuke.args4j.CmdLineException) InstallException(com.android.ddmlib.InstallException) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) TestConsole(com.facebook.buck.testutil.TestConsole) File(java.io.File) Test(org.junit.Test)

Example 9 with TargetDeviceOptions

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

the class AdbHelperTest method testDeviceFilterCombos.

/**
   * Verify that different combinations of arguments work correctly.
   */
@Test
public void testDeviceFilterCombos() throws CmdLineException {
    TestDevice realDevice1 = createRealDevice("1", IDevice.DeviceState.ONLINE);
    TestDevice realDevice2 = createRealDevice("2", IDevice.DeviceState.ONLINE);
    TestDevice emulator1 = createEmulator("3", IDevice.DeviceState.ONLINE);
    TestDevice emulator2 = createEmulator("4", IDevice.DeviceState.ONLINE);
    IDevice[] devices = new IDevice[] { realDevice1, emulator1, realDevice2, emulator2 };
    AdbHelper myAdbHelper;
    // Filter by serial in "real device" mode with serial number for real device.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.of(realDevice1.getSerialNumber())));
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(1, filteredDevices.size());
    assertSame(realDevice1, filteredDevices.get(0));
    // Filter by serial in "real device" mode with serial number for emulator.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.of(emulator1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
    // Filter by serial in "emulator" mode with serial number for real device.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.of(realDevice1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
    // Filter by serial in "real device" mode with serial number for emulator.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.of(emulator1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(1, filteredDevices.size());
    assertSame(emulator1, filteredDevices.get(0));
    // Filter in both "real device" mode and "emulator mode".
    myAdbHelper = createAdbHelper(new AdbOptions(0, true), new TargetDeviceOptions(true, true, Optional.empty()));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(devices.length, filteredDevices.size());
    for (IDevice device : devices) {
        assertTrue(filteredDevices.contains(device));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 10 with TargetDeviceOptions

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

the class AdbHelperTest method testDeviceFilterRealDevices.

/**
   * Verify that when real-device-only mode is enabled only real devices appear in result.
   */
@Test
public void testDeviceFilterRealDevices() throws CmdLineException {
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.empty()));
    IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("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)

Aggregations

TargetDeviceOptions (com.facebook.buck.step.TargetDeviceOptions)14 Test (org.junit.Test)14 IDevice (com.android.ddmlib.IDevice)11 AdbOptions (com.facebook.buck.step.AdbOptions)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