@Test
public void testDecodeInvalidPositions() throws IOException {

  SsaDecoder decoder = new SsaDecoder();
  byte[] bytes =
      TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), INVALID_POSITIONS);
  Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
  // Negative parameter to \pos() - fall back to the positions implied by middle-left alignment.
  Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
  assertWithMessage("Cue.position").that(firstCue.position).isEqualTo(0.05f);
  assertWithMessage("Cue.lineType").that(firstCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
  assertWithMessage("Cue.line").that(firstCue.line).isEqualTo(0.5f);
  // Negative parameter to \move() - fall back to the positions implied by middle-left alignment.
  Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
  assertWithMessage("Cue.position").that(secondCue.position).isEqualTo(0.05f);
  assertWithMessage("Cue.lineType").that(secondCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
  assertWithMessage("Cue.line").that(secondCue.line).isEqualTo(0.5f);
  // Check invalid alignment override (11) is skipped and style-provided one is used (4).
  Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
  assertWithMessage("Cue.positionAnchor")
      .that(thirdCue.positionAnchor)
      .isEqualTo(Cue.ANCHOR_TYPE_START);
  assertWithMessage("Cue.lineAnchor").that(thirdCue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
  assertWithMessage("Cue.textAlignment")
      .that(thirdCue.textAlignment)
      .isEqualTo(Layout.Alignment.ALIGN_NORMAL);
  // No braces - fall back to the positions implied by middle-left alignment
  Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
  assertWithMessage("Cue.position").that(fourthCue.position).isEqualTo(0.05f);
  assertWithMessage("Cue.lineType").that(fourthCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
  assertWithMessage("Cue.line").that(fourthCue.line).isEqualTo(0.5f);
}