/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.exoplayer.text.subrip;

import android.test.InstrumentationTestCase;

import com.google.android.exoplayer.C;

import java.io.IOException;
import java.io.InputStream;

/**
 * Unit test for {@link SubripParser}.
 */
public class SubripParserTest extends InstrumentationTestCase {

  private static final String TYPICAL_SUBRIP_FILE = "subrip/typical";
  private static final String EMPTY_SUBRIP_FILE = "subrip/empty";

  public void testParseNullSubripFile() throws IOException {
    SubripParser parser = new SubripParser();
    InputStream inputStream =
        getInstrumentation().getContext().getResources().getAssets().open(EMPTY_SUBRIP_FILE);

    try {
      parser.parse(inputStream, C.UTF8_NAME, 0);
      fail("Expected IOException");
    } catch (IOException expected) {
      // Do nothing.
    }
  }

  public void testParseTypicalSubripFile() throws IOException {
    SubripParser parser = new SubripParser();
    InputStream inputStream =
        getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_SUBRIP_FILE);
    SubripSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME, 0);

    // test start time and event count
    long startTimeUs = 0;
    assertEquals(startTimeUs, subtitle.getStartTime());
    assertEquals(4, subtitle.getEventTimeCount());

    // test first cue
    assertEquals(startTimeUs, subtitle.getEventTime(0));
    assertEquals("This is the first subtitle.",
        subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
    assertEquals(startTimeUs + 1234000, subtitle.getEventTime(1));

    // test second cue
    assertEquals(startTimeUs + 2345000, subtitle.getEventTime(2));
    assertEquals("This is the second subtitle.\nSecond subtitle with second line.",
        subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
    assertEquals(startTimeUs + 3456000, subtitle.getEventTime(3));
  }

}

@@ -675,84 +675,84 @@
 ort 
-android.test.InstrumentationTestCase;%0A%0Aimport com.google.android.exoplayer.C
+com.google.android.exoplayer.C;%0A%0Aimport android.test.InstrumentationTestCase
 ;%0A%0Ai
@@ -1291,24 +1291,37 @@
 E);%0A
-%0A
     
-try %7B%0A     
+SubripSubtitle subtitle =
  par
@@ -1368,103 +1368,143 @@
     
-  fail(%22Expected IOException%22);%0A    %7D catch (IOException expected) %7B%0A      // Do nothing.%0A    %7D
+// Assert that the subtitle is empty.%0A    assertEquals(0, subtitle.getEventTimeCount());%0A    assertTrue(subtitle.getCues(0).isEmpty());
 %0A  %7D
@@ -1818,25 +1818,25 @@
 0);%0A%0A    // 
-t
+T
 est start ti
@@ -1857,34 +1857,9 @@
 ount
-%0A    long startTimeUs = 0;
+.
 %0A   
@@ -1868,35 +1868,25 @@
 ssertEquals(
-startTimeUs
+0
 , subtitle.g
@@ -1956,25 +1956,25 @@
 ));%0A%0A    // 
-t
+T
 est first cu
@@ -1970,24 +1970,25 @@
 st first cue
+.
 %0A    assertE
@@ -1993,27 +1993,17 @@
 tEquals(
-startTimeUs
+0
 , subtit
@@ -2164,30 +2164,16 @@
 tEquals(
-startTimeUs + 
 1234000,
@@ -2208,17 +2208,17 @@
 %0A    // 
-t
+T
 est seco
@@ -2223,16 +2223,17 @@
 cond cue
+.
 %0A    ass
@@ -2242,30 +2242,16 @@
 tEquals(
-startTimeUs + 
 2345000,
@@ -2459,22 +2459,8 @@
 als(
-startTimeUs + 
 3456

Fix SRT test