From 53a81ebb98c5d9abe7b264291d555404ab36fb56 Mon Sep 17 00:00:00 2001 From: Ian Baker Date: Thu, 23 May 2024 15:20:30 +0100 Subject: [PATCH] Rename and reshuffle tests --- .../extractor/text/cea/Cea708DecoderTest.java | 59 +++++++------------ 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/libraries/extractor/src/test/java/androidx/media3/extractor/text/cea/Cea708DecoderTest.java b/libraries/extractor/src/test/java/androidx/media3/extractor/text/cea/Cea708DecoderTest.java index 19f26c8a573..c1f662589cb 100644 --- a/libraries/extractor/src/test/java/androidx/media3/extractor/text/cea/Cea708DecoderTest.java +++ b/libraries/extractor/src/test/java/androidx/media3/extractor/text/cea/Cea708DecoderTest.java @@ -86,40 +86,14 @@ public void singleServiceAndWindowDefinition() throws Exception { assertThat(getOnlyCue(firstSubtitle).text.toString()).isEqualTo("test subtitle"); } + /** + * ExoPlayer's incomplete implementation of the 'set pen location' command appends a newline if + * the 'new' row location is different to the 'current' row (this is to ensure that subtitles that + * are meant to be on different lines aren't concatenated together on a single line). This test + * demonstrates this, even though the target row is 2, only a single newline is appended. + */ @Test - public void singleServiceAndWindowDefinition_ignoresRowLock() throws Exception { - Cea708Decoder cea708Decoder = - new Cea708Decoder( - /* accessibilityChannel= */ Format.NO_VALUE, /* initializationData= */ null); - byte[] windowDefinition = - TestUtil.createByteArray( - 0x98, // DF0 command (define window 0) - 0b0010_0000, // visible=true, row lock and column lock disabled, priority=0 - 0xF0 | 50, // relative positioning, anchor vertical - 50, // anchor horizontal - 1, // anchor point = 0, row count = 1 - 30, // column count = 30 - 0b0000_1001); // window style = 1, pen style = 1 - byte[] setCurrentWindow = TestUtil.createByteArray(0x80); // CW0 (set current window to 0) - byte[] subtitleData = - encodePacketIntoBytePairs( - createPacket( - /* sequenceNumber= */ 0, - createServiceBlock( - Bytes.concat( - windowDefinition, - setCurrentWindow, - "row1\r\nrow2\r\nrow3\r\nrow4".getBytes(Charsets.UTF_8))))); - - Subtitle result = decodeSampleAndCopyResult(cea708Decoder, subtitleData); - - // Row count is 1 (which means 2 rows should be kept). Row lock is disabled in the media, - // but this is ignored and the result is still truncated to only the last two rows. - assertThat(getOnlyCue(result).text.toString()).isEqualTo("row3\nrow4"); - } - - @Test - public void setPenLocationTestWithNewLineTest1() throws Exception { + public void setPenLocation_appendsNewlineIfRowChanges() throws Exception { Cea708Decoder cea708Decoder = new Cea708Decoder( @@ -134,8 +108,8 @@ public void setPenLocationTestWithNewLineTest1() throws Exception { 30, // column count = 30 0b0000_1001); // window style = 1, pen style = 1 byte[] setCurrentWindow = TestUtil.createByteArray(0x80); // CW0 (set current window to 0) - byte[] setPenLocation = TestUtil.createByteArray(0x92,0x01,0x00); // COMMAND_SPL with row 1 and - byte[] newLine = TestUtil.createByteArray(0x0D); // new line + // COMMAND_SPL with row 2 and column 0 + byte[] setPenLocation = TestUtil.createByteArray(0x92, 0x02, 0x00); byte[] subtitleData = encodePacketIntoBytePairs( createPacket( @@ -145,7 +119,6 @@ public void setPenLocationTestWithNewLineTest1() throws Exception { windowDefinition, setCurrentWindow, "line1".getBytes(Charsets.UTF_8), - newLine, setPenLocation, "line2".getBytes(Charsets.UTF_8))))); @@ -154,8 +127,15 @@ public void setPenLocationTestWithNewLineTest1() throws Exception { assertThat(getOnlyCue(firstSubtitle).text.toString()).isEqualTo("line1\nline2"); } + /** + * ExoPlayer's incomplete implementation of the 'set pen location' command appends a newline if + * the 'new' row location is different to the 'current' row (this is to ensure that subtitles that + * are meant to be on different lines aren't concatenated together on a single line). This test + * ensures that if there's already an explicit newline appended before the command, a duplicate + * newline isn't appended. + */ @Test - public void setPenLocationTestWithNewLineTest2() throws Exception { + public void setPenLocation_explicitNewLineBefore_secondNewlineNotAdded() throws Exception { Cea708Decoder cea708Decoder = new Cea708Decoder( @@ -170,7 +150,9 @@ public void setPenLocationTestWithNewLineTest2() throws Exception { 30, // column count = 30 0b0000_1001); // window style = 1, pen style = 1 byte[] setCurrentWindow = TestUtil.createByteArray(0x80); // CW0 (set current window to 0) - byte[] setPenLocation = TestUtil.createByteArray(0x92,0x01,0x00); // COMMAND_SPL with row 1 and + // COMMAND_SPL with row 1 and column 0 + byte[] setPenLocation = TestUtil.createByteArray(0x92, 0x01, 0x00); + byte[] newLine = TestUtil.createByteArray(0x0D); // new line byte[] subtitleData = encodePacketIntoBytePairs( createPacket( @@ -180,6 +162,7 @@ public void setPenLocationTestWithNewLineTest2() throws Exception { windowDefinition, setCurrentWindow, "line1".getBytes(Charsets.UTF_8), + newLine, setPenLocation, "line2".getBytes(Charsets.UTF_8)))));