mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Added a test for MAX_PACKET_LENGTH.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
<test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/>
|
<test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/>
|
||||||
<test name='net.sf.briar.transport.ConnectionWindowImplTest'/>
|
<test name='net.sf.briar.transport.ConnectionWindowImplTest'/>
|
||||||
<test name='net.sf.briar.transport.ConnectionWriterImplTest'/>
|
<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.FrameReadWriteTest'/>
|
||||||
<test name='net.sf.briar.transport.PaddedConnectionWriterTest'/>
|
<test name='net.sf.briar.transport.PaddedConnectionWriterTest'/>
|
||||||
<test name='net.sf.briar.util.ByteUtilsTest'/>
|
<test name='net.sf.briar.util.ByteUtilsTest'/>
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class ConnectionWriterImplTest extends TransportTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCapacity() throws Exception {
|
public void testGetCapacity() throws Exception {
|
||||||
int overheadPerFrame = 4 + mac.getMacLength();
|
int overheadPerFrame = headerLength + macLength;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionEncrypter e = new NullConnectionEncrypter(out);
|
ConnectionEncrypter e = new NullConnectionEncrypter(out);
|
||||||
ConnectionWriterImpl w = new ConnectionWriterImpl(e, mac);
|
ConnectionWriterImpl w = new ConnectionWriterImpl(e, mac);
|
||||||
|
|||||||
49
test/net/sf/briar/transport/ConnectionWriterTest.java
Normal file
49
test/net/sf/briar/transport/ConnectionWriterTest.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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
|
@Test
|
||||||
public void testGetCapacity() throws Exception {
|
public void testGetCapacity() throws Exception {
|
||||||
int overheadPerFrame = 4 + mac.getMacLength();
|
int overheadPerFrame = headerLength + macLength;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionEncrypter e = new NullConnectionEncrypter(out);
|
ConnectionEncrypter e = new NullConnectionEncrypter(out);
|
||||||
PaddedConnectionWriter w = new PaddedConnectionWriter(e, mac);
|
PaddedConnectionWriter w = new PaddedConnectionWriter(e, mac);
|
||||||
|
|||||||
Reference in New Issue
Block a user