1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
Copyright (C) 2016 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 "test.h"
#include "ssa_reader.h"
#include "collect.h"
#include "subtitle.h"
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <cstdio>
using std::list;
BOOST_AUTO_TEST_CASE (ssa_reader_test)
{
boost::filesystem::path p = private_test / "example.ssa";
FILE* f = fopen (p.string().c_str(), "r");
sub::SSAReader reader (f);
fclose (f);
list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
list<sub::Subtitle>::iterator i = subs.begin ();
BOOST_REQUIRE (i != subs.end ());
BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 40, 650));
BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 41, 790));
list<sub::Line>::iterator j = i->lines.begin();
BOOST_REQUIRE (j != i->lines.end ());
BOOST_CHECK_EQUAL (j->vertical_position.proportional.get(), 0);
BOOST_CHECK_EQUAL (j->vertical_position.reference.get(), sub::BOTTOM_OF_SCREEN);
BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
sub::Block b = j->blocks.front ();
BOOST_CHECK_EQUAL (b.text, "Et les enregistrements de ses ondes delta ?");
BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
BOOST_CHECK_EQUAL (b.font_size.proportional().get(), 56.0 / 1024);
BOOST_CHECK_EQUAL (b.bold, false);
BOOST_CHECK_EQUAL (b.italic, false);
BOOST_CHECK_EQUAL (b.underline, false);
++i;
BOOST_REQUIRE (i != subs.end ());
BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 42, 420));
BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 44, 150));
j = i->lines.begin();
BOOST_REQUIRE (j != i->lines.end ());
BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
b = j->blocks.front ();
BOOST_CHECK_EQUAL (b.text, "Toujours rien.");
BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
BOOST_CHECK_EQUAL (b.font_size.proportional().get(), 56.0 / 1024);
BOOST_CHECK_EQUAL (b.bold, false);
BOOST_CHECK_EQUAL (b.italic, false);
BOOST_CHECK_EQUAL (b.underline, false);
++i;
BOOST_CHECK (i == subs.end());
}
static void
test (boost::filesystem::path p)
{
p = private_test / p;
FILE* f = fopen (p.string().c_str(), "r");
BOOST_REQUIRE (f);
sub::SSAReader r (f);
fclose (f);
}
/** Test of reading some typical .srt files */
BOOST_AUTO_TEST_CASE (ssa_reader_test2)
{
test ("DKH_UT_EN20160601def.ssa");
}
/** Test a file with some bits to exercise the parser */
BOOST_AUTO_TEST_CASE (ssa_reader_test3)
{
boost::filesystem::path p = "test/data/test.ssa";
FILE* f = fopen (p.string().c_str(), "r");
sub::SSAReader reader (f);
fclose (f);
list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
BOOST_REQUIRE_EQUAL (subs.size(), 2);
list<sub::Subtitle>::const_iterator i = subs.begin ();
BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 0, 1, 230));
BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 0, 4, 550));
BOOST_REQUIRE_EQUAL (i->lines.size(), 1);
list<sub::Line>::const_iterator j = i->lines.begin();
BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
sub::Block b = j->blocks.front ();
BOOST_CHECK_EQUAL (b.text, "Hello world");
++i;
BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 0, 5, 740));
BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 0, 11, 0));
BOOST_REQUIRE_EQUAL (i->lines.size(), 1);
j = i->lines.begin();
BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
b = j->blocks.front ();
BOOST_CHECK_EQUAL (b.text, "This is vertically moved");
++i;
}
|