#4306 - extends test case with line and position anchor verifications

This commit is contained in:
Arnold Szabo 2018-10-01 23:16:48 +03:00
parent fc5eb12e79
commit 75a7385bbb
3 changed files with 104 additions and 1 deletions

View file

@ -176,7 +176,7 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
// Extract tags
int replacedCharacters = 0;
StringBuilder processedLine = new StringBuilder(trimmedLine);
Matcher matcher = SUBRIP_TAG_PATTERN.matcher(processedLine);
Matcher matcher = SUBRIP_TAG_PATTERN.matcher(trimmedLine);
while (matcher.find()) {
String tag = matcher.group();

View file

@ -18,3 +18,39 @@ This { \an2} is the fourth subtitle.
5
00:00:013,567 --> 00:00:14,901
This {\an2} is the fifth subtitle with multiple {\xyz} valid {\qwe} tags.
6
00:00:015,567 --> 00:00:15,901
This {\an1} is a lines.
7
00:00:016,567 --> 00:00:16,901
This {\an2} is a line.
8
00:00:017,567 --> 00:00:17,901
This {\an3} is a line.
9
00:00:018,567 --> 00:00:18,901
This {\an4} is a line.
10
00:00:019,567 --> 00:00:19,901
This {\an5} is a line.
11
00:00:020,567 --> 00:00:20,901
This {\an6} is a line.
12
00:00:021,567 --> 00:00:22,901
This {\an7} is a line.
13
00:00:023,567 --> 00:00:23,901
This {\an8} is a line.
14
00:00:024,567 --> 00:00:24,901
This {\an9} is a line.

View file

@ -18,6 +18,8 @@ package com.google.android.exoplayer2.text.subrip;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.text.Cue;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -174,6 +176,71 @@ public final class SubripDecoderTest {
assertThat(subtitle.getCues(subtitle.getEventTime(8)).get(0).text.toString())
.isEqualTo("This is the fifth subtitle with multiple valid tags.");
// Verify positions
// {/an1}
assertThat(subtitle.getCues(subtitle.getEventTime(10)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
assertThat(subtitle.getCues(subtitle.getEventTime(10)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
// {/an2}
assertThat(subtitle.getCues(subtitle.getEventTime(12)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
assertThat(subtitle.getCues(subtitle.getEventTime(12)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
// {/an3}
assertThat(subtitle.getCues(subtitle.getEventTime(14)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
assertThat(subtitle.getCues(subtitle.getEventTime(14)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
// {/an4}
assertThat(subtitle.getCues(subtitle.getEventTime(16)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
assertThat(subtitle.getCues(subtitle.getEventTime(16)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
// {/an5}
assertThat(subtitle.getCues(subtitle.getEventTime(18)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
assertThat(subtitle.getCues(subtitle.getEventTime(18)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
// {/an6}
assertThat(subtitle.getCues(subtitle.getEventTime(20)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
assertThat(subtitle.getCues(subtitle.getEventTime(20)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
// {/an7}
assertThat(subtitle.getCues(subtitle.getEventTime(22)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
assertThat(subtitle.getCues(subtitle.getEventTime(22)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
// {/an8}
assertThat(subtitle.getCues(subtitle.getEventTime(24)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
assertThat(subtitle.getCues(subtitle.getEventTime(24)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
// {/an9}
assertThat(subtitle.getCues(subtitle.getEventTime(26)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);
assertThat(subtitle.getCues(subtitle.getEventTime(26)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
}
private static void assertTypicalCue1(SubripSubtitle subtitle, int eventIndex) {