diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-11 14:04:58 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-11 14:04:58 +0000 |
| commit | 3af978d2d688cb1e4be7c8d95155a6b8cc7456a3 (patch) | |
| tree | fdb7f3fe7eea7a433d38d14307e78731d1e49dc2 /test | |
| parent | 0523d4a83d7d334560d261686bdb329eea8bfb96 (diff) | |
Various work on SubRip.
Diffstat (limited to 'test')
| -rw-r--r-- | test/subrip_test.cc | 120 | ||||
| -rw-r--r-- | test/wscript | 1 |
2 files changed, 121 insertions, 0 deletions
diff --git a/test/subrip_test.cc b/test/subrip_test.cc new file mode 100644 index 000000000..f23fc8a0b --- /dev/null +++ b/test/subrip_test.cc @@ -0,0 +1,120 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <boost/test/unit_test.hpp> +#include "lib/subrip.h" +#include "lib/subrip_content.h" + +using std::list; +using std::string; +using boost::shared_ptr; + +/** Test SubRip::convert_time */ +BOOST_AUTO_TEST_CASE (subrip_time_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), rint (((3 * 60) + 10 + 0.5) * TIME_HZ)); + BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), rint (((4 * 3600) + (19 * 60) + 51 + 0.782) * TIME_HZ)); +} + +/** Test SubRip::convert_coordinate */ +BOOST_AUTO_TEST_CASE (subrip_coordinate_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("foo:42"), 42); + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("X1:999"), 999); +} + +/** Test SubRip::convert_content */ +BOOST_AUTO_TEST_CASE (subrip_content_test) +{ + list<string> c; + list<SubRipSubtitlePiece> p; + + c.push_back ("Hello world"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + c.clear (); + + c.push_back ("<b>Hello world</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("<i>Hello world</i>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("<u>Hello world</u>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("{b}Hello world{/b}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("{i}Hello world{/i}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("{u}Hello world{/u}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("<b>This is <i>nesting</i> of subtitles</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 3); + list<SubRipSubtitlePiece>::iterator i = p.begin (); + BOOST_CHECK_EQUAL (i->text, "This is "); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + BOOST_CHECK_EQUAL (i->text, "nesting"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, true); + ++i; + BOOST_CHECK_EQUAL (i->text, " of subtitles"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + c.clear (); +} + +/** Test parsing of full SubRip file content */ +BOOST_AUTO_TEST_CASE (subrip_parse_test) +{ + SubRipContent content (shared_ptr<Film> (), "test/data/subrip.srt"); + content.examine (shared_ptr<Job> ()); +} diff --git a/test/wscript b/test/wscript index 5aa95e324..834491e19 100644 --- a/test/wscript +++ b/test/wscript @@ -40,6 +40,7 @@ def build(bld): scaling_test.cc silence_padding_test.cc stream_test.cc + subrip_test.cc test.cc threed_test.cc util_test.cc |
