From 2cdecbe2b56233b009f6edfa13033c6ec9d198bf Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 20 Jun 2014 10:30:36 +0100 Subject: [PATCH] Fix small .srt parsing bug; add a test. --- src/lib/exceptions.cc | 4 ++-- src/lib/subrip.cc | 7 ++++++- test/subrip_test.cc | 9 +++++++++ test/test.cc | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc index 4d9ccc95c..f34cebbfe 100644 --- a/src/lib/exceptions.cc +++ b/src/lib/exceptions.cc @@ -63,7 +63,7 @@ PixelFormatError::PixelFormatError (string o, AVPixelFormat f) } SubRipError::SubRipError (string saw, string expecting, boost::filesystem::path f) - : FileError (String::compose (_("Error in SubRip file: saw %1 while expecting %2"), saw, expecting), f) + : FileError (String::compose (_("Error in SubRip file: saw %1 while expecting %2"), saw.empty() ? "[nothing]" : saw, expecting), f) { - + } diff --git a/src/lib/subrip.cc b/src/lib/subrip.cc index 3217a4df0..11ad3302d 100644 --- a/src/lib/subrip.cc +++ b/src/lib/subrip.cc @@ -66,13 +66,18 @@ SubRip::SubRip (shared_ptr content) switch (state) { case COUNTER: { + if (line.empty ()) { + /* a blank line at the start is ok */ + break; + } + int x = 0; try { x = lexical_cast (line); } catch (...) { } - + if (x == next_count) { state = METADATA; ++next_count; diff --git a/test/subrip_test.cc b/test/subrip_test.cc index adb548f0c..9479e657e 100644 --- a/test/subrip_test.cc +++ b/test/subrip_test.cc @@ -201,3 +201,12 @@ BOOST_AUTO_TEST_CASE (subrip_render_test) write_image (image.image, "build/test/subrip_render_test.png"); check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png"); } + +/** Test of reading a typical .srt */ +BOOST_AUTO_TEST_CASE (subrip_read_test) +{ + shared_ptr film = new_test_film ("subrip_read_test"); + boost::filesystem::path p = private_data / "sintel_en.srt"; + shared_ptr s (new SubRipContent (film, p)); + s->examine (shared_ptr ()); +} diff --git a/test/test.cc b/test/test.cc index 32f74a7d2..c233a661d 100644 --- a/test/test.cc +++ b/test/test.cc @@ -47,7 +47,7 @@ using std::cerr; using std::list; using boost::shared_ptr; -boost::filesystem::path private_data = boost::filesystem::path ("test") / boost::filesystem::path ("private"); +boost::filesystem::path private_data = boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"); class TestUISignaller : public UISignaller { -- 2.30.2