use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.
the class AndroidImplTest method pullTraceFilesFromDevice_returnIsFalse.
@Test
public void pullTraceFilesFromDevice_returnIsFalse() throws TimeoutException, AdbCommandRejectedException, IOException, SyncException {
IDevice device = mock(IDevice.class);
SyncService syncServ = mock(SyncService.class);
when(device.getSyncService()).thenReturn(syncServ);
when(filereader.createFile(any(String.class), any(String.class))).thenReturn(folder.newFile("cpu"));
doThrow(SyncException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
doThrow(TimeoutException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
doThrow(IOException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
}
use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.
the class AndroidImplTest method pushFile_ServiceHasReturn.
@Test
public void pushFile_ServiceHasReturn() throws SyncException, IOException, TimeoutException {
IDevice device = mock(IDevice.class);
SyncService service = mock(SyncService.class);
try {
when(device.getSyncService()).thenReturn(service);
} catch (AdbCommandRejectedException e) {
e.printStackTrace();
}
doNothing().when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertTrue(androidImpl.pushFile(device, "", ""));
doThrow(SyncException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pushFile(device, "", ""));
doThrow(TimeoutException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pushFile(device, "", ""));
doThrow(IOException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
assertFalse(androidImpl.pushFile(device, "", ""));
}
use of com.android.ddmlib.SyncService in project android by JetBrains.
the class AndroidDbUtil method downloadDatabase.
public static boolean downloadDatabase(@NotNull IDevice device, @NotNull String packageName, @NotNull String dbName, boolean external, @NotNull File localDbFile, @NotNull final ProgressIndicator progressIndicator, @NotNull AndroidDbErrorReporter errorReporter) {
try {
final MyShellOutputReceiver receiver = new MyShellOutputReceiver(progressIndicator, device);
device.executeShellCommand(getRunAsPrefix(packageName, external) + "cat " + getDatabaseRemoteFilePath(packageName, dbName, external) + " >" + TEMP_REMOTE_DB_PATH, receiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
final String output = receiver.getOutput();
if (!output.isEmpty()) {
errorReporter.reportError(output);
return false;
}
progressIndicator.checkCanceled();
final File parent = localDbFile.getParentFile();
if (!parent.exists()) {
if (!parent.mkdirs()) {
errorReporter.reportError("cannot create directory '" + parent.getPath() + "'");
return false;
}
}
final SyncService syncService = device.getSyncService();
try {
syncService.pullFile(TEMP_REMOTE_DB_PATH, localDbFile.getPath(), new MySyncProgressMonitor(progressIndicator));
} finally {
syncService.close();
}
} catch (Exception e) {
errorReporter.reportError(e);
return false;
}
return true;
}
use of com.android.ddmlib.SyncService in project android by JetBrains.
the class AndroidDbUtil method uploadDatabase.
public static boolean uploadDatabase(@NotNull IDevice device, @NotNull String packageName, @NotNull String dbName, boolean external, @NotNull String localDbPath, @NotNull final ProgressIndicator progressIndicator, @NotNull AndroidDbErrorReporter errorReporter) {
try {
final SyncService syncService = device.getSyncService();
try {
syncService.pushFile(localDbPath, TEMP_REMOTE_DB_PATH, new MySyncProgressMonitor(progressIndicator));
} finally {
syncService.close();
}
final String remoteDbPath = getDatabaseRemoteFilePath(packageName, dbName, external);
final String remoteDbDirPath = remoteDbPath.substring(0, remoteDbPath.lastIndexOf('/'));
MyShellOutputReceiver outputReceiver = new MyShellOutputReceiver(progressIndicator, device);
device.executeShellCommand(getRunAsPrefix(packageName, external) + "mkdir " + remoteDbDirPath, outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
String output = outputReceiver.getOutput();
if (!output.isEmpty() && !output.startsWith("mkdir failed")) {
errorReporter.reportError(output);
return false;
}
// recreating is needed for Genymotion emulator (IDEA-114732)
if (!external && !recreateRemoteFile(device, packageName, remoteDbPath, errorReporter, progressIndicator)) {
return false;
}
outputReceiver = new MyShellOutputReceiver(progressIndicator, device);
device.executeShellCommand(getRunAsPrefix(packageName, external) + "cat " + TEMP_REMOTE_DB_PATH + " >" + remoteDbPath, outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
output = outputReceiver.getOutput();
if (!output.isEmpty()) {
errorReporter.reportError(output);
return false;
}
progressIndicator.checkCanceled();
} catch (Exception e) {
errorReporter.reportError(e);
return false;
}
return true;
}
use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.
the class AdbServiceImplTest method fail_pullFile.
@SuppressWarnings("rawtypes")
@Test
public void fail_pullFile() throws Exception {
SyncService syncservice = Mockito.mock(SyncService.class);
// Mockito.doNothing().when(syncservice).pullFile(Mockito.anyString(), Mockito.anyString(), (ISyncProgressMonitor) Mockito.any());
Mockito.doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
throw new IOException("its Mocking!");
}
}).when(syncservice).pullFile(Mockito.anyString(), Mockito.anyString(), (ISyncProgressMonitor) Mockito.any());
boolean success = adbService.pullFile(syncservice, "remote", "file", "local");
assertTrue(!success);
}
Aggregations