Search in sources :

Example 11 with AdbOptions

use of com.facebook.buck.step.AdbOptions 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)

Example 12 with AdbOptions

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

the class AdbHelperTest method testNonQuietShowsOutput.

@Test
public void testNonQuietShowsOutput() 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, false);
        }

        @Override
        public String toString() {
            return "install apk";
        }
    }, false);
    assertTrue(success);
    assertEquals(apk.getAbsolutePath(), apkPath.get());
    assertEquals("", console.getTextWrittenToStdOut());
    assertEquals("Successfully ran install apk on 1 device(s)\n", 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 13 with AdbOptions

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

the class InstallCommandOptionsTest method testInstallCommandOptionsMultiInstallMode.

@Test
public void testInstallCommandOptionsMultiInstallMode() throws CmdLineException, IOException {
    // Short form.
    AdbOptions options = getAdbOptions(false, AdbCommandLineOptions.MULTI_INSTALL_MODE_SHORT_ARG);
    assertTrue(options.isMultiInstallModeEnabled());
    // Long form.
    options = getAdbOptions(false, AdbCommandLineOptions.MULTI_INSTALL_MODE_LONG_ARG);
    assertTrue(options.isMultiInstallModeEnabled());
    // Is off by default.
    options = getAdbOptions(false);
    assertFalse(options.isMultiInstallModeEnabled());
}
Also used : AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 14 with AdbOptions

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

the class InstallCommandOptionsTest method testInstallCommandOptionsAdbThreads.

@Test
public void testInstallCommandOptionsAdbThreads() throws CmdLineException, IOException {
    // Short form.
    AdbOptions options = getAdbOptions(false, AdbCommandLineOptions.ADB_THREADS_SHORT_ARG, "4");
    assertEquals(4, options.getAdbThreadCount());
    // Long form.
    options = getAdbOptions(false, AdbCommandLineOptions.ADB_THREADS_LONG_ARG, "4");
    assertEquals(4, options.getAdbThreadCount());
    // Is zero by default and overridden when creating the thread pool.
    options = getAdbOptions(false);
    assertEquals(0, options.getAdbThreadCount());
}
Also used : 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