mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Test cleanup. #280
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package org.briarproject.transport;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.transport.ReorderingWindow.Change;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -14,12 +14,12 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
private static final int BITMAP_BYTES = REORDERING_WINDOW_SIZE / 8;
|
||||
|
||||
@Test
|
||||
public void testBitmapConversion() {
|
||||
Random random = new Random();
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
random.nextBytes(bitmap);
|
||||
byte[] bitmap = TestUtils.getRandomBytes(BITMAP_BYTES);
|
||||
ReorderingWindow window = new ReorderingWindow(0L, bitmap);
|
||||
assertArrayEquals(bitmap, window.getBitmap());
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowSlidesWhenFirstElementIsSeen() {
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
byte[] bitmap = new byte[BITMAP_BYTES];
|
||||
ReorderingWindow window = new ReorderingWindow(0L, bitmap);
|
||||
// Set the first element seen
|
||||
Change change = window.setSeen(0L);
|
||||
@@ -42,7 +42,7 @@ public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowDoesNotSlideWhenElementBelowMidpointIsSeen() {
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
byte[] bitmap = new byte[BITMAP_BYTES];
|
||||
ReorderingWindow window = new ReorderingWindow(0L, bitmap);
|
||||
// Set an element below the midpoint seen
|
||||
Change change = window.setSeen(1L);
|
||||
@@ -57,7 +57,7 @@ public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowSlidesWhenElementAboveMidpointIsSeen() {
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
byte[] bitmap = new byte[BITMAP_BYTES];
|
||||
ReorderingWindow window = new ReorderingWindow(0, bitmap);
|
||||
long aboveMidpoint = REORDERING_WINDOW_SIZE / 2;
|
||||
// Set an element above the midpoint seen
|
||||
@@ -74,7 +74,7 @@ public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowSlidesUntilLowestElementIsUnseenWhenFirstElementIsSeen() {
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
byte[] bitmap = new byte[BITMAP_BYTES];
|
||||
ReorderingWindow window = new ReorderingWindow(0L, bitmap);
|
||||
window.setSeen(1L);
|
||||
// Set the first element seen
|
||||
@@ -90,7 +90,7 @@ public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowSlidesUntilLowestElementIsUnseenWhenElementAboveMidpointIsSeen() {
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
byte[] bitmap = new byte[BITMAP_BYTES];
|
||||
ReorderingWindow window = new ReorderingWindow(0L, bitmap);
|
||||
window.setSeen(1L);
|
||||
long aboveMidpoint = REORDERING_WINDOW_SIZE / 2;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.transport;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.crypto.StreamDecrypter;
|
||||
import org.briarproject.api.crypto.StreamEncrypter;
|
||||
import org.junit.Test;
|
||||
@@ -10,7 +11,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
@@ -21,18 +21,13 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TransportIntegrationTest extends BriarTestCase {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Test
|
||||
public void testWriteAndRead() throws Exception {
|
||||
// Generate a random tag
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
random.nextBytes(tag);
|
||||
byte[] tag = TestUtils.getRandomBytes(TAG_LENGTH);
|
||||
// Generate two frames with random payloads
|
||||
byte[] payload1 = new byte[123];
|
||||
random.nextBytes(payload1);
|
||||
byte[] payload2 = new byte[321];
|
||||
random.nextBytes(payload2);
|
||||
byte[] payload1 = TestUtils.getRandomBytes(123);
|
||||
byte[] payload2 = TestUtils.getRandomBytes(321);
|
||||
// Write the tag and the frames
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
StreamEncrypter encrypter = new TestStreamEncrypter(out, tag);
|
||||
|
||||
@@ -46,9 +46,9 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
private final long rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
||||
private final ContactId contactId = new ContactId(123);
|
||||
private final ContactId contactId1 = new ContactId(234);
|
||||
private final SecretKey tagKey = TestUtils.createSecretKey();
|
||||
private final SecretKey headerKey = TestUtils.createSecretKey();
|
||||
private final SecretKey masterKey = TestUtils.createSecretKey();
|
||||
private final SecretKey tagKey = TestUtils.getSecretKey();
|
||||
private final SecretKey headerKey = TestUtils.getSecretKey();
|
||||
private final SecretKey masterKey = TestUtils.getSecretKey();
|
||||
private final Random random = new Random();
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user