use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class HeartbeatSenderThreadTest method testRun_exception.
@Suppress
@MediumTest
public void testRun_exception() {
// IO Exception test
MockByteArrayOutputStream baos = new MockByteArrayOutputStream();
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
null);
hbSender.setOutputStream(baos);
try {
baos.close();
} catch (IOException e) {
}
hbSender.startConnection();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
assertTrue(connThread.getDidErrorOccur());
hbSender.stopConnection();
connThread = null;
hbSender = null;
// NP Exception test
connThread = new MockTcpConnectionThread(new DecoderThread(), null);
hbSender = new MockHeartbeatSenderThread(connThread, null, //QUICKFIX: Not sure about this value
null);
hbSender.setOutputStream(null);
hbSender.startConnection();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
assertTrue(connThread.getDidErrorOccur());
hbSender.stopConnection();
connThread = null;
hbSender = null;
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class ResponseReaderThreadTest method testStopConnection.
@Suppress
@MediumTest
public void testStopConnection() {
DecoderThread decoder = new DecoderThread();
MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
null);
MockOTAInputStream mIs = new MockOTAInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
respReader.setInputStream(new BufferedInputStream(mIs));
respReader.startConnection();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
Thread t = respReader.getConnectionThread();
assertNotNull(t);
if (null != t) {
assertTrue(t.isAlive());
assertTrue(respReader.getIsConnectionRunning());
}
// now comes the actual test
respReader.stopConnection();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
assertNull(respReader.getInputStream());
assertNull(respReader.getConnectionThread());
assertFalse(respReader.getIsConnectionRunning());
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class ResponseReaderThreadTest method testSetInputstream.
@MediumTest
public void testSetInputstream() {
DecoderThread decoder = new DecoderThread();
MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
null);
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 });
respReader.setInputStream(new BufferedInputStream(bais));
DataInputStream dis = (DataInputStream) respReader.getInputStream();
assertNotNull(dis);
// let's test all the bytes...
if (null != dis) {
boolean areBytesCorrect = true;
for (int i = 1; i < 6; i++) {
try {
int j = dis.readByte();
if (-1 == j) {
fail("Unexpected end of the DataInputStream");
areBytesCorrect = false;
} else if (i != j) {
fail("Characters differ: i: " + i + " vs. j: " + j);
areBytesCorrect = false;
}
} catch (IOException e) {
}
}
assertTrue(areBytesCorrect);
}
respReader.setInputStream(null);
assertNull(respReader.getInputStream());
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class DecoderThread method startThread.
/**
* Start decoder thread
*/
protected void startThread() {
mRunning = true;
Thread decoderThread = new Thread(this);
decoderThread.setName(THREAD_NAME);
decoderThread.start();
}
Aggregations