2 Copyright (C) 2022 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 "web_vtt_reader.h"
23 #include "exceptions.h"
25 #include <boost/test/unit_test.hpp>
26 #include <boost/filesystem.hpp>
37 /* Test reading of a VTT file */
38 BOOST_AUTO_TEST_CASE(vtt_reader_test)
40 auto f = fopen("test/data/test.vtt", "r");
41 sub::WebVTTReader reader(f);
43 auto subs = sub::collect<std::vector<sub::Subtitle>>(reader.subtitles());
45 auto i = subs.begin();
50 BOOST_REQUIRE(i != subs.end());
51 BOOST_CHECK_EQUAL(i->from, sub::Time::from_hms(0, 0, 41, 90));
52 BOOST_CHECK_EQUAL(i->to, sub::Time::from_hms(0, 0, 42, 210));
54 auto j = i->lines.begin();
55 BOOST_CHECK(j != i->lines.end());
56 BOOST_REQUIRE_EQUAL(j->blocks.size(), 1);
57 auto b = j->blocks[0];
58 BOOST_CHECK_EQUAL(b.text, "This is a subtitle");
59 /* No font is specified by WebVTT, so none should be seen here */
61 BOOST_CHECK(!b.font_size.specified());
62 BOOST_CHECK_EQUAL(b.bold, false);
63 BOOST_CHECK_EQUAL(b.italic, false);
64 BOOST_CHECK_EQUAL(b.underline, false);
65 BOOST_REQUIRE(j->vertical_position.line);
66 BOOST_CHECK_EQUAL(j->vertical_position.line.get(), 0);
67 BOOST_CHECK_EQUAL(j->vertical_position.reference.get(), sub::TOP_OF_SUBTITLE);
70 BOOST_CHECK(j != i->lines.end());
71 BOOST_REQUIRE_EQUAL(j->blocks.size(), 1);
73 BOOST_CHECK_EQUAL(b.text, "and that's a line break");
74 /* No font is specified by WebVTT, so none should be seen here */
76 BOOST_CHECK(!b.font_size.specified());
77 BOOST_CHECK_EQUAL(b.bold, false);
78 BOOST_CHECK_EQUAL(b.italic, false);
79 BOOST_CHECK_EQUAL(b.underline, false);
80 BOOST_REQUIRE(j->vertical_position.line);
81 BOOST_CHECK_EQUAL(j->vertical_position.line.get(), 1);
82 BOOST_CHECK_EQUAL(j->vertical_position.reference.get(), sub::TOP_OF_SUBTITLE);
88 BOOST_REQUIRE(i != subs.end());
89 BOOST_CHECK_EQUAL(i->from, sub::Time::from_hms(0, 1, 1, 10));
90 BOOST_CHECK_EQUAL(i->to, sub::Time::from_hms(0, 1, 2, 100));
92 BOOST_CHECK_EQUAL(i->lines.size(), 1);
93 sub::Line l = i->lines[0];
94 BOOST_CHECK_EQUAL(l.blocks.size(), 1);
95 BOOST_CHECK_EQUAL(l.vertical_position.line.get(), 0);
96 BOOST_CHECK_EQUAL(l.vertical_position.reference.get(), sub::TOP_OF_SUBTITLE);
98 BOOST_REQUIRE_EQUAL(l.blocks.size(), 1U);
100 BOOST_CHECK_EQUAL(b.text, "This is some stuff.");
101 /* No font is specified by WebVTT, so none should be seen here */
102 BOOST_CHECK(!b.font);
103 BOOST_CHECK(!b.font_size.specified());
104 BOOST_CHECK_EQUAL(b.bold, false);
105 BOOST_CHECK_EQUAL(b.italic, false);
106 BOOST_CHECK_EQUAL(b.underline, false);