2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/test/unit_test.hpp>
21 #include "lib/subrip.h"
22 #include "lib/subrip_content.h"
26 using boost::shared_ptr;
28 /** Test SubRip::convert_time */
29 BOOST_AUTO_TEST_CASE (subrip_time_test)
31 BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), rint (((3 * 60) + 10 + 0.5) * TIME_HZ));
32 BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), rint (((4 * 3600) + (19 * 60) + 51 + 0.782) * TIME_HZ));
35 /** Test SubRip::convert_coordinate */
36 BOOST_AUTO_TEST_CASE (subrip_coordinate_test)
38 BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("foo:42"), 42);
39 BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("X1:999"), 999);
42 /** Test SubRip::convert_content */
43 BOOST_AUTO_TEST_CASE (subrip_content_test)
46 list<SubRipSubtitlePiece> p;
48 c.push_back ("Hello world");
49 p = SubRip::convert_content (c);
50 BOOST_CHECK_EQUAL (p.size(), 1);
51 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
54 c.push_back ("<b>Hello world</b>");
55 p = SubRip::convert_content (c);
56 BOOST_CHECK_EQUAL (p.size(), 1);
57 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
58 BOOST_CHECK_EQUAL (p.front().bold, true);
61 c.push_back ("<i>Hello world</i>");
62 p = SubRip::convert_content (c);
63 BOOST_CHECK_EQUAL (p.size(), 1);
64 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
65 BOOST_CHECK_EQUAL (p.front().italic, true);
68 c.push_back ("<u>Hello world</u>");
69 p = SubRip::convert_content (c);
70 BOOST_CHECK_EQUAL (p.size(), 1);
71 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
72 BOOST_CHECK_EQUAL (p.front().underline, true);
75 c.push_back ("{b}Hello world{/b}");
76 p = SubRip::convert_content (c);
77 BOOST_CHECK_EQUAL (p.size(), 1);
78 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
79 BOOST_CHECK_EQUAL (p.front().bold, true);
82 c.push_back ("{i}Hello world{/i}");
83 p = SubRip::convert_content (c);
84 BOOST_CHECK_EQUAL (p.size(), 1);
85 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
86 BOOST_CHECK_EQUAL (p.front().italic, true);
89 c.push_back ("{u}Hello world{/u}");
90 p = SubRip::convert_content (c);
91 BOOST_CHECK_EQUAL (p.size(), 1);
92 BOOST_CHECK_EQUAL (p.front().text, "Hello world");
93 BOOST_CHECK_EQUAL (p.front().underline, true);
96 c.push_back ("<b>This is <i>nesting</i> of subtitles</b>");
97 p = SubRip::convert_content (c);
98 BOOST_CHECK_EQUAL (p.size(), 3);
99 list<SubRipSubtitlePiece>::iterator i = p.begin ();
100 BOOST_CHECK_EQUAL (i->text, "This is ");
101 BOOST_CHECK_EQUAL (i->bold, true);
102 BOOST_CHECK_EQUAL (i->italic, false);
104 BOOST_CHECK_EQUAL (i->text, "nesting");
105 BOOST_CHECK_EQUAL (i->bold, true);
106 BOOST_CHECK_EQUAL (i->italic, true);
108 BOOST_CHECK_EQUAL (i->text, " of subtitles");
109 BOOST_CHECK_EQUAL (i->bold, true);
110 BOOST_CHECK_EQUAL (i->italic, false);
115 /** Test parsing of full SubRip file content */
116 BOOST_AUTO_TEST_CASE (subrip_parse_test)
118 SubRipContent content (shared_ptr<Film> (), "test/data/subrip.srt");
119 content.examine (shared_ptr<Job> ());