diff options
author | ByteHamster <info@bytehamster.com> | 2021-02-17 14:48:31 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-02-17 14:48:31 +0100 |
commit | 12e22849e69e3cadab44872b8a06e58e6a77142c (patch) | |
tree | 54354f86c5faf607c9c4bb071de67b9b313aa5ef /core/src/test | |
parent | 1c9f017a7e15fd21671c76f05d9c22eb43e34a41 (diff) | |
download | AntennaPod-12e22849e69e3cadab44872b8a06e58e6a77142c.zip |
Added more id3 parser tests
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/java/de/danoeh/antennapod/core/util/id3reader/Id3ReaderTest.java | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/id3reader/Id3ReaderTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/id3reader/Id3ReaderTest.java index 53e338416..584141b83 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/util/id3reader/Id3ReaderTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/id3reader/Id3ReaderTest.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class Id3ReaderTest { @@ -27,16 +28,74 @@ public class Id3ReaderTest { } @Test - public void testReadUtf16WithBom() throws IOException { + public void testReadMultipleStrings() throws IOException { + byte[] data = { + ID3Reader.ENCODING_ISO, + 'F', 'o', 'o', + 0, // Null-terminated + ID3Reader.ENCODING_ISO, + 'B', 'a', 'r', + 0 // Null-terminated + }; + CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(data)); + ID3Reader reader = new ID3Reader(inputStream); + assertEquals("Foo", reader.readEncodingAndString(1000)); + assertEquals("Bar", reader.readEncodingAndString(1000)); + } + + @Test + public void testReadingLimit() throws IOException { + byte[] data = { + ID3Reader.ENCODING_ISO, + 'A', 'B', 'C', 'D' + }; + CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(data)); + ID3Reader reader = new ID3Reader(inputStream); + assertEquals("ABC", reader.readEncodingAndString(4)); // Includes encoding + assertEquals('D', reader.readByte()); + } + + @Test + public void testReadUtf16RespectsBom() throws IOException { byte[] data = { ID3Reader.ENCODING_UTF16_WITH_BOM, - (byte) 0xff, (byte) 0xfe, // BOM + (byte) 0xff, (byte) 0xfe, // BOM: Little-endian 'A', 0, 'B', 0, 'C', 0, 0, 0, // Null-terminated + ID3Reader.ENCODING_UTF16_WITH_BOM, + (byte) 0xfe, (byte) 0xff, // BOM: Big-endian + 0, 'D', 0, 'E', 0, 'F', + 0, 0, // Null-terminated + }; + CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(data)); + ID3Reader reader = new ID3Reader(inputStream); + assertEquals("ABC", reader.readEncodingAndString(1000)); + assertEquals("DEF", reader.readEncodingAndString(1000)); + } + + @Test + public void testReadUtf16NullPrefix() throws IOException { + byte[] data = { + ID3Reader.ENCODING_UTF16_WITH_BOM, + (byte) 0xff, (byte) 0xfe, // BOM + 0x00, 0x01, // Latin Capital Letter A with macron (Ā) + 0, 0, // Null-terminated }; CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(data)); String string = new ID3Reader(inputStream).readEncodingAndString(1000); - assertEquals("ABC", string); + assertEquals("Ā", string); + } + + @Test + public void testReadingLimitUtf16() throws IOException { + byte[] data = { + ID3Reader.ENCODING_UTF16_WITHOUT_BOM, + 'A', 0, 'B', 0, 'C', 0, 'D', 0 + }; + CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(data)); + ID3Reader reader = new ID3Reader(inputStream); + reader.readEncodingAndString(6); // Includes encoding, produces broken string + assertTrue("Should respect limit even if it breaks a symbol", reader.getPosition() <= 6); } @Test |