Fix small .srt parsing bug; add a test.
authorCarl Hetherington <cth@carlh.net>
Fri, 20 Jun 2014 09:30:36 +0000 (10:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 20 Jun 2014 09:30:36 +0000 (10:30 +0100)
src/lib/exceptions.cc
src/lib/subrip.cc
test/subrip_test.cc
test/test.cc

index 4d9ccc95c7fa7c11d09d83663caab10ed3010d1d..f34cebbfe04a69f94fa2e07df3bb74aab5d41a51 100644 (file)
@@ -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)
 {
-
+       
 }
index 3217a4df0803a1bd4b192e18c6846ff33f4ffaa8..11ad3302d3659abf107eed8b8fa69d33d8109c69 100644 (file)
@@ -66,13 +66,18 @@ SubRip::SubRip (shared_ptr<const SubRipContent> content)
                switch (state) {
                case COUNTER:
                {
+                       if (line.empty ()) {
+                               /* a blank line at the start is ok */
+                               break;
+                       }
+                       
                        int x = 0;
                        try {
                                x = lexical_cast<int> (line);
                        } catch (...) {
 
                        }
-                       
+
                        if (x == next_count) {
                                state = METADATA;
                                ++next_count;
index adb548f0c2344b1375620460d3efdaa2e2a53df0..9479e657e0d03a2bed4f930ac3d10ed2a06fd052 100644 (file)
@@ -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> film = new_test_film ("subrip_read_test");
+       boost::filesystem::path p = private_data / "sintel_en.srt";
+       shared_ptr<SubRipContent> s (new SubRipContent (film, p));
+       s->examine (shared_ptr<Job> ());
+}
index 32f74a7d2fb62b8243056d11c11b84eeb5eea0b1..c233a661ddf4666cb65bd89c68a413d44950fcdb 100644 (file)
@@ -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
 {