diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-28 21:12:10 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-28 21:12:10 +0000 |
| commit | 7f20aa518356f188946eb508239caf7c113da819 (patch) | |
| tree | 8647f9b6e6f87415cfd38e47365b14cf3e6df30f /test | |
First version.
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/test.stl | 9 | ||||
| -rw-r--r-- | test/stl_reader_test.cc | 120 | ||||
| -rw-r--r-- | test/test.cc | 22 | ||||
| -rw-r--r-- | test/wscript | 23 |
4 files changed, 174 insertions, 0 deletions
diff --git a/test/data/test.stl b/test/data/test.stl new file mode 100644 index 0000000..abb755a --- /dev/null +++ b/test/data/test.stl @@ -0,0 +1,9 @@ +$FontName = Arial +$Bold = False +$Italic = False +$Underlined = False +$FontSize = 42 +// This is a comment which we should ignore +// These timecodes are H:M:S:F +00:00:41:09 , 00:00:42:21 , This is a subtitle | and that's a line break +00:01:01:01 , 00:01:02:10 , This is some ^Bbold^B and some ^B^Ibold italic^B^I and some ^Uunderlined^U. diff --git a/test/stl_reader_test.cc b/test/stl_reader_test.cc new file mode 100644 index 0000000..14a6ada --- /dev/null +++ b/test/stl_reader_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 <fstream> +#include "stl_reader.h" +#include "subtitle.h" + +using std::list; +using std::ifstream; + +/* Test reading of an STL file */ +BOOST_AUTO_TEST_CASE (stl_reader_test) +{ + ifstream file ("test/data/test.stl"); + sub::STLReader reader (file); + list<sub::Subtitle> subs = reader.subtitles (); + + list<sub::Subtitle>::iterator i = subs.begin (); + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 0, 41, 9)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 0, 42, 21)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, " This is a subtitle "); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 0, 41, 9)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 0, 42, 21)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, " and that's a line break"); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, " This is some "); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, "bold"); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, " and some "); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, true); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, "bold italic"); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, " and some "); + ++i; + + BOOST_CHECK (i != subs.end ()); + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, true); + BOOST_CHECK_EQUAL (i->text, "underlined"); + ++i; + + BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10)); + BOOST_CHECK_EQUAL (i->bold, false); + BOOST_CHECK_EQUAL (i->italic, false); + BOOST_CHECK_EQUAL (i->underline, false); + BOOST_CHECK_EQUAL (i->text, "."); + ++i; + + BOOST_CHECK (i == subs.end ()); +} + + diff --git a/test/test.cc b/test/test.cc new file mode 100644 index 0000000..eb6eecf --- /dev/null +++ b/test/test.cc @@ -0,0 +1,22 @@ +/* + 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. + +*/ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE libsub_test +#include <boost/test/unit_test.hpp> diff --git a/test/wscript b/test/wscript new file mode 100644 index 0000000..5d16abb --- /dev/null +++ b/test/wscript @@ -0,0 +1,23 @@ +def configure(conf): + conf.check_cxx(fragment=""" + #define BOOST_TEST_MODULE Config test\n + #include <boost/test/unit_test.hpp>\n + int main() {} + """, + msg='Checking for boost unit testing library', + lib='boost_unit_test_framework', + uselib_store='BOOST_TEST') + + conf.env.prepend_value('LINKFLAGS', '-Lsrc') + +def build(bld): + obj = bld(features='cxx cxxprogram') + obj.name = 'tests' + obj.uselib = 'BOOST_TEST' + obj.use = 'libsub' + obj.source = """ + stl_reader_test.cc + test.cc + """ + obj.target = 'tests' + obj.install_path = '' |
