mirror of
https://github.com/revanced/jadb.git
synced 2025-04-30 14:44:31 +02:00
Adding test case for pulling file.
This commit is contained in:
parent
39ea2d92d6
commit
a58587f794
@ -4,6 +4,7 @@ import se.vidstige.jadb.JadbException;
|
|||||||
import se.vidstige.jadb.RemoteFile;
|
import se.vidstige.jadb.RemoteFile;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vidstige on 20/03/14.
|
* Created by vidstige on 20/03/14.
|
||||||
@ -13,4 +14,5 @@ public interface AdbDeviceResponder {
|
|||||||
String getType();
|
String getType();
|
||||||
|
|
||||||
void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
|
void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
|
||||||
|
void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,14 @@ public class AdbProtocolHandler implements Runnable {
|
|||||||
selected.filePushed(new RemoteFile(path), mode, buffer);
|
selected.filePushed(new RemoteFile(path), mode, buffer);
|
||||||
transport.sendStatus("OKAY", 0); // 0 = ignored
|
transport.sendStatus("OKAY", 0); // 0 = ignored
|
||||||
}
|
}
|
||||||
|
else if ("RECV".equals(id)) {
|
||||||
|
String remotePath = readString(input, length);
|
||||||
|
SyncTransport transport = new SyncTransport(output, input);
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
selected.filePulled(new RemoteFile(remotePath), buffer);
|
||||||
|
transport.sendStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||||
|
transport.sendStatus("DONE", 0); // ignored
|
||||||
|
}
|
||||||
else throw new JadbException("Unknown sync id " + id);
|
else throw new JadbException("Unknown sync id " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import se.vidstige.jadb.RemoteFile;
|
|||||||
import se.vidstige.jadb.test.fakes.FakeAdbServer;
|
import se.vidstige.jadb.test.fakes.FakeAdbServer;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -66,6 +68,16 @@ public class MockedTestCases {
|
|||||||
device.push(fileContents, parseDate("1981-08-25 13:37"), 0666, new RemoteFile("/remote/path/abc.txt"));
|
device.push(fileContents, parseDate("1981-08-25 13:37"), 0666, new RemoteFile("/remote/path/abc.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPullFile() throws Exception {
|
||||||
|
server.add("serial-123");
|
||||||
|
server.expectPull("serial-123", new RemoteFile("/remote/path/abc.txt")).withContent("foobar");
|
||||||
|
JadbDevice device = connection.getDevices().get(0);
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
device.pull(new RemoteFile("/remote/path/abc.txt"), buffer);
|
||||||
|
Assert.assertArrayEquals("foobar".getBytes(Charset.forName("utf-8")), buffer.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
private long parseDate(String date) throws ParseException {
|
private long parseDate(String date) throws ParseException {
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
return dateFormat.parse(date).getTime();
|
return dateFormat.parse(date).getTime();
|
||||||
|
@ -70,6 +70,10 @@ public class FakeAdbServer implements AdbResponder {
|
|||||||
return findBySerial(serial).expectPush(path);
|
return findBySerial(serial).expectPush(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExpectationBuilder expectPull(String serial, RemoteFile path) {
|
||||||
|
return findBySerial(serial).expectPull(path);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AdbDeviceResponder> getDevices() {
|
public List<AdbDeviceResponder> getDevices() {
|
||||||
return new ArrayList<AdbDeviceResponder>(devices);
|
return new ArrayList<AdbDeviceResponder>(devices);
|
||||||
@ -107,6 +111,20 @@ public class FakeAdbServer implements AdbResponder {
|
|||||||
new JadbException("Unexpected push to device " + serial + " at " + path);
|
new JadbException("Unexpected push to device " + serial + " at " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException {
|
||||||
|
for (FileExpectation fe : expectations) {
|
||||||
|
if (fe.matches(path))
|
||||||
|
{
|
||||||
|
expectations.remove(fe);
|
||||||
|
fe.throwIfFail();
|
||||||
|
fe.returnFile(buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new JadbException("Unexpected push to device " + serial + " at " + path);
|
||||||
|
}
|
||||||
|
|
||||||
public void verifyExpectations() {
|
public void verifyExpectations() {
|
||||||
org.junit.Assert.assertEquals(0, expectations.size());
|
org.junit.Assert.assertEquals(0, expectations.size());
|
||||||
}
|
}
|
||||||
@ -149,6 +167,10 @@ public class FakeAdbServer implements AdbResponder {
|
|||||||
public void verifyContent(byte[] content) {
|
public void verifyContent(byte[] content) {
|
||||||
org.junit.Assert.assertArrayEquals(this.content, content);
|
org.junit.Assert.assertArrayEquals(this.content, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void returnFile(ByteArrayOutputStream buffer) throws IOException {
|
||||||
|
buffer.write(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpectationBuilder expectPush(RemoteFile path) {
|
public ExpectationBuilder expectPush(RemoteFile path) {
|
||||||
@ -156,5 +178,12 @@ public class FakeAdbServer implements AdbResponder {
|
|||||||
expectations.add(expectation);
|
expectations.add(expectation);
|
||||||
return expectation;
|
return expectation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExpectationBuilder expectPull(RemoteFile path) {
|
||||||
|
FileExpectation expectation = new FileExpectation(path);
|
||||||
|
expectations.add(expectation);
|
||||||
|
return expectation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user