mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Renamed raw data type.
This commit is contained in:
@@ -330,138 +330,138 @@ public class ReaderImplTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes8() throws Exception {
|
||||
public void testReadRaw8() throws Exception {
|
||||
byte[] longest = new byte[Byte.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
// {1, 2, 3}, {}, and 127 zero bytes
|
||||
setContents("51" + "03" + "010203" + "51" + "00" +
|
||||
"51" + "7F" + longHex);
|
||||
assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(new byte[0], r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(new byte[] {1, 2, 3}, r.readRaw(Integer.MAX_VALUE));
|
||||
assertArrayEquals(new byte[0], r.readRaw(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest, r.readRaw(Integer.MAX_VALUE));
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes8ChecksMaxLength() throws Exception {
|
||||
public void testReadRaw8ChecksMaxLength() throws Exception {
|
||||
// {1, 2, 3} twice
|
||||
setContents("51" + "03" + "010203" + "51" + "03" + "010203");
|
||||
assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes(3));
|
||||
assertTrue(r.hasBytes());
|
||||
assertArrayEquals(new byte[] {1, 2, 3}, r.readRaw(3));
|
||||
assertTrue(r.hasRaw());
|
||||
try {
|
||||
r.readBytes(2);
|
||||
r.readRaw(2);
|
||||
fail();
|
||||
} catch(FormatException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipBytes8() throws Exception {
|
||||
public void testSkipRaw8() throws Exception {
|
||||
byte[] longest = new byte[Byte.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
// {1, 2, 3}, {}, and 127 zero bytes
|
||||
setContents("51" + "03" + "010203" + "51" + "00" +
|
||||
"51" + "7F" + longHex);
|
||||
r.skipBytes();
|
||||
r.skipBytes();
|
||||
r.skipBytes();
|
||||
r.skipRaw();
|
||||
r.skipRaw();
|
||||
r.skipRaw();
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes16() throws Exception {
|
||||
public void testReadRaw16() throws Exception {
|
||||
byte[] shortest = new byte[Byte.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
byte[] longest = new byte[Short.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
// 128 zero bytes and 2^15 - 1 zero bytes
|
||||
setContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex);
|
||||
assertArrayEquals(shortest, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(shortest, r.readRaw(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest, r.readRaw(Integer.MAX_VALUE));
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes16ChecksMaxLength() throws Exception {
|
||||
public void testReadRaw16ChecksMaxLength() throws Exception {
|
||||
byte[] shortest = new byte[Byte.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
// 128 zero bytes, twice
|
||||
setContents("52" + "0080" + shortHex + "52" + "0080" + shortHex);
|
||||
assertArrayEquals(shortest, r.readBytes(Byte.MAX_VALUE + 1));
|
||||
assertTrue(r.hasBytes());
|
||||
assertArrayEquals(shortest, r.readRaw(Byte.MAX_VALUE + 1));
|
||||
assertTrue(r.hasRaw());
|
||||
try {
|
||||
r.readBytes(Byte.MAX_VALUE);
|
||||
r.readRaw(Byte.MAX_VALUE);
|
||||
fail();
|
||||
} catch(FormatException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipBytes16() throws Exception {
|
||||
public void testSkipRaw16() throws Exception {
|
||||
byte[] shortest = new byte[Byte.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
byte[] longest = new byte[Short.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
// 128 zero bytes and 2^15 - 1 zero bytes
|
||||
setContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex);
|
||||
r.skipBytes();
|
||||
r.skipBytes();
|
||||
r.skipRaw();
|
||||
r.skipRaw();
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes32() throws Exception {
|
||||
public void testReadRaw32() throws Exception {
|
||||
byte[] shortest = new byte[Short.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
// 2^15 zero bytes
|
||||
setContents("54" + "00008000" + shortHex);
|
||||
assertArrayEquals(shortest, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(shortest, r.readRaw(Integer.MAX_VALUE));
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBytes32ChecksMaxLength() throws Exception {
|
||||
public void testReadRaw32ChecksMaxLength() throws Exception {
|
||||
byte[] shortest = new byte[Short.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
// 2^15 zero bytes, twice
|
||||
setContents("54" + "00008000" + shortHex +
|
||||
"54" + "00008000" + shortHex);
|
||||
assertArrayEquals(shortest, r.readBytes(Short.MAX_VALUE + 1));
|
||||
assertTrue(r.hasBytes());
|
||||
assertArrayEquals(shortest, r.readRaw(Short.MAX_VALUE + 1));
|
||||
assertTrue(r.hasRaw());
|
||||
try {
|
||||
r.readBytes(Short.MAX_VALUE);
|
||||
r.readRaw(Short.MAX_VALUE);
|
||||
fail();
|
||||
} catch(FormatException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipBytes32() throws Exception {
|
||||
public void testSkipRaw32() throws Exception {
|
||||
byte[] shortest = new byte[Short.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
// 2^15 zero bytes, twice
|
||||
setContents("54" + "00008000" + shortHex +
|
||||
"54" + "00008000" + shortHex);
|
||||
r.skipBytes();
|
||||
r.skipBytes();
|
||||
r.skipRaw();
|
||||
r.skipRaw();
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytesMustHaveMinimalLength() throws Exception {
|
||||
public void testRawMustHaveMinimalLength() throws Exception {
|
||||
// RAW_16 could be encoded as RAW_8
|
||||
byte[] longest8 = new byte[Byte.MAX_VALUE];
|
||||
String long8Hex = StringUtils.toHexString(longest8);
|
||||
setContents("51" + "7F" + long8Hex + "52" + "007F" + long8Hex);
|
||||
assertArrayEquals(longest8, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest8, r.readRaw(Integer.MAX_VALUE));
|
||||
try {
|
||||
r.readBytes(Integer.MAX_VALUE);
|
||||
r.readRaw(Integer.MAX_VALUE);
|
||||
fail();
|
||||
} catch(FormatException expected) {}
|
||||
// RAW_32 could be encoded as RAW_16
|
||||
byte[] longest16 = new byte[Short.MAX_VALUE];
|
||||
String long16Hex = StringUtils.toHexString(longest16);
|
||||
setContents("52" + "7FFF" + long16Hex + "54" + "00007FFF" + long16Hex);
|
||||
assertArrayEquals(longest16, r.readBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(longest16, r.readRaw(Integer.MAX_VALUE));
|
||||
try {
|
||||
r.readBytes(Integer.MAX_VALUE);
|
||||
r.readRaw(Integer.MAX_VALUE);
|
||||
fail();
|
||||
} catch(FormatException expected) {}
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ public class WriterImplTest extends BriarTestCase {
|
||||
public void testWriteBytes8() throws IOException {
|
||||
byte[] longest = new byte[Byte.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
w.writeBytes(new byte[] {1, 2, 3});
|
||||
w.writeBytes(longest);
|
||||
w.writeRaw(new byte[] {1, 2, 3});
|
||||
w.writeRaw(longest);
|
||||
// RAW_8 tag, length 3, bytes, RAW_8 tag, length 127, bytes
|
||||
checkContents("51" + "03" + "010203" + "51" + "7F" + longHex);
|
||||
}
|
||||
@@ -128,8 +128,8 @@ public class WriterImplTest extends BriarTestCase {
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
byte[] longest = new byte[Short.MAX_VALUE];
|
||||
String longHex = StringUtils.toHexString(longest);
|
||||
w.writeBytes(shortest);
|
||||
w.writeBytes(longest);
|
||||
w.writeRaw(shortest);
|
||||
w.writeRaw(longest);
|
||||
// RAW_16 tag, length 128, bytes, RAW_16 tag, length 2^15 - 1, bytes
|
||||
checkContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class WriterImplTest extends BriarTestCase {
|
||||
public void testWriteBytes32() throws IOException {
|
||||
byte[] shortest = new byte[Short.MAX_VALUE + 1];
|
||||
String shortHex = StringUtils.toHexString(shortest);
|
||||
w.writeBytes(shortest);
|
||||
w.writeRaw(shortest);
|
||||
// RAW_32 tag, length 2^15, bytes
|
||||
checkContents("54" + "00008000" + shortHex);
|
||||
}
|
||||
|
||||
@@ -144,9 +144,9 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
w.writeListStart();
|
||||
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
|
||||
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
|
||||
w.writeBytes(TestUtils.getRandomId());
|
||||
w.writeRaw(TestUtils.getRandomId());
|
||||
}
|
||||
if(tooBig) w.writeBytes(TestUtils.getRandomId());
|
||||
if(tooBig) w.writeRaw(TestUtils.getRandomId());
|
||||
w.writeListEnd();
|
||||
w.writeListEnd();
|
||||
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
|
||||
@@ -178,9 +178,9 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
w.writeListStart();
|
||||
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
|
||||
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
|
||||
w.writeBytes(TestUtils.getRandomId());
|
||||
w.writeRaw(TestUtils.getRandomId());
|
||||
}
|
||||
if(tooBig) w.writeBytes(TestUtils.getRandomId());
|
||||
if(tooBig) w.writeRaw(TestUtils.getRandomId());
|
||||
w.writeListEnd();
|
||||
w.writeListEnd();
|
||||
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
|
||||
@@ -212,9 +212,9 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
w.writeListStart();
|
||||
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
|
||||
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
|
||||
w.writeBytes(TestUtils.getRandomId());
|
||||
w.writeRaw(TestUtils.getRandomId());
|
||||
}
|
||||
if(tooBig) w.writeBytes(TestUtils.getRandomId());
|
||||
if(tooBig) w.writeRaw(TestUtils.getRandomId());
|
||||
w.writeListEnd();
|
||||
w.writeListEnd();
|
||||
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
|
||||
|
||||
Reference in New Issue
Block a user