mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Add UTF-8 tests for BDF Reader and Writer
This commit is contained in:
@@ -273,6 +273,19 @@ public class BdfReaderImplTest extends BriarTestCase {
|
|||||||
assertTrue(r.eof());
|
assertTrue(r.eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadUtf8String() throws Exception {
|
||||||
|
String str = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \uFDD0\uFDD1\uFDD2\uFDD3\uFDD1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||||
|
String strHex = StringUtils.toHexString(str.getBytes("UTF-8"));
|
||||||
|
// STRING_8 tag, "foo", the empty string, and the test string
|
||||||
|
setContents("41" + "03" + "666F6F" + "41" + "00" +
|
||||||
|
"41" + "35" + strHex);
|
||||||
|
assertEquals("foo", r.readString(Integer.MAX_VALUE));
|
||||||
|
assertEquals("", r.readString(Integer.MAX_VALUE));
|
||||||
|
assertEquals(str, r.readString(Integer.MAX_VALUE));
|
||||||
|
assertTrue(r.eof());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadRaw8() throws Exception {
|
public void testReadRaw8() throws Exception {
|
||||||
byte[] longest = new byte[Byte.MAX_VALUE];
|
byte[] longest = new byte[Byte.MAX_VALUE];
|
||||||
|
|||||||
@@ -9,12 +9,11 @@ import org.junit.Test;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
public class BdfWriterImplTest extends BriarTestCase {
|
public class BdfWriterImplTest extends BriarTestCase {
|
||||||
|
|
||||||
@@ -113,6 +112,15 @@ public class BdfWriterImplTest extends BriarTestCase {
|
|||||||
checkContents("44" + "00008000" + shortHex);
|
checkContents("44" + "00008000" + shortHex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWriteUtf8String() throws IOException {
|
||||||
|
String str = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \uFDD0\uFDD1\uFDD2\uFDD3\uFDD1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||||
|
String strHex = StringUtils.toHexString(str.getBytes("UTF-8"));
|
||||||
|
w.writeString(str);
|
||||||
|
// STRING_8 tag, length 53, UTF-8 bytes
|
||||||
|
checkContents("41" + "35" + strHex);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteBytes8() throws IOException {
|
public void testWriteBytes8() throws IOException {
|
||||||
byte[] longest = new byte[Byte.MAX_VALUE];
|
byte[] longest = new byte[Byte.MAX_VALUE];
|
||||||
@@ -225,7 +233,7 @@ public class BdfWriterImplTest extends BriarTestCase {
|
|||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
byte[] expected = StringUtils.fromHexString(hex);
|
byte[] expected = StringUtils.fromHexString(hex);
|
||||||
assertTrue(StringUtils.toHexString(out.toByteArray()),
|
assertArrayEquals(StringUtils.toHexString(out.toByteArray()),
|
||||||
Arrays.equals(expected, out.toByteArray()));
|
expected, out.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user