Skip to content
Snippets Groups Projects
Commit fadd95ae authored by akwizgran's avatar akwizgran
Browse files

Added a test for MAX_PACKET_LENGTH.

parent 10c3b217
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@
<test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/>
<test name='net.sf.briar.transport.ConnectionWindowImplTest'/>
<test name='net.sf.briar.transport.ConnectionWriterImplTest'/>
<test name='net.sf.briar.transport.ConnectionWriterTest'/>
<test name='net.sf.briar.transport.FrameReadWriteTest'/>
<test name='net.sf.briar.transport.PaddedConnectionWriterTest'/>
<test name='net.sf.briar.util.ByteUtilsTest'/>
......
......@@ -103,7 +103,7 @@ public class ConnectionWriterImplTest extends TransportTest {
@Test
public void testGetCapacity() throws Exception {
int overheadPerFrame = 4 + mac.getMacLength();
int overheadPerFrame = headerLength + macLength;
ByteArrayOutputStream out = new ByteArrayOutputStream();
ConnectionEncrypter e = new NullConnectionEncrypter(out);
ConnectionWriterImpl w = new ConnectionWriterImpl(e, mac);
......
package net.sf.briar.transport;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.transport.ConnectionWriter;
import net.sf.briar.api.transport.ConnectionWriterFactory;
import net.sf.briar.api.transport.TransportConstants;
import net.sf.briar.crypto.CryptoModule;
import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class ConnectionWriterTest extends TestCase {
private final ConnectionWriterFactory connectionWriterFactory;
private final byte[] secret = new byte[100];
private final int transportId = 999;
private final long connection = 1234L;
public ConnectionWriterTest() throws Exception {
super();
Injector i = Guice.createInjector(new CryptoModule(),
new TransportModule());
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
}
@Test
public void testOverhead() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream(
TransportConstants.MIN_CONNECTION_LENGTH);
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
true, transportId, connection, secret);
// Check that the connection writer thinks there's room for a packet
long capacity = w.getCapacity(TransportConstants.MIN_CONNECTION_LENGTH);
assertTrue(capacity >= ProtocolConstants.MAX_PACKET_LENGTH);
assertTrue(capacity <= TransportConstants.MIN_CONNECTION_LENGTH);
// Check that there really is room for a packet
byte[] payload = new byte[ProtocolConstants.MAX_PACKET_LENGTH];
w.getOutputStream().write(payload);
w.getOutputStream().flush();
long used = out.size();
assertTrue(used >= ProtocolConstants.MAX_PACKET_LENGTH);
assertTrue(used <= TransportConstants.MIN_CONNECTION_LENGTH);
}
}
......@@ -163,7 +163,7 @@ public class PaddedConnectionWriterTest extends TransportTest {
@Test
public void testGetCapacity() throws Exception {
int overheadPerFrame = 4 + mac.getMacLength();
int overheadPerFrame = headerLength + macLength;
ByteArrayOutputStream out = new ByteArrayOutputStream();
ConnectionEncrypter e = new NullConnectionEncrypter(out);
PaddedConnectionWriter w = new PaddedConnectionWriter(e, mac);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment