summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-01-28 22:41:09 +0000
committerCarl Hetherington <cth@carlh.net>2014-01-28 22:41:09 +0000
commit75aa6e480d998b29205c0eab328697a5d007986b (patch)
treeac53060d67ac2f6c64994e405220977c5ae5d817 /test
parent7f20aa518356f188946eb508239caf7c113da819 (diff)
Basic writer.
Diffstat (limited to 'test')
-rw-r--r--test/ref/test.stl5
-rw-r--r--test/stl_reader_test.cc75
-rw-r--r--test/stl_writer_test.cc51
-rw-r--r--test/test.cc24
-rw-r--r--test/test.h22
-rw-r--r--test/wscript1
6 files changed, 153 insertions, 25 deletions
diff --git a/test/ref/test.stl b/test/ref/test.stl
new file mode 100644
index 0000000..f65dd80
--- /dev/null
+++ b/test/ref/test.stl
@@ -0,0 +1,5 @@
+
+$FontName = Arial
+$FontSize = 42
+0:0:41:9,0:0:42:21, This is a subtitle | and that's a line break
+0:1:1:1,0:1:2: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
index 14a6ada..92b0d58 100644
--- a/test/stl_reader_test.cc
+++ b/test/stl_reader_test.cc
@@ -35,83 +35,108 @@ BOOST_AUTO_TEST_CASE (stl_reader_test)
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->text, " This is a subtitle ");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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 ");
+ BOOST_CHECK_EQUAL (i->line, 0);
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 0, 41, 9));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 0, 42, 21));
++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->text, " and that's a line break");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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");
+ BOOST_CHECK_EQUAL (i->line, 1);
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 0, 41, 9));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 0, 42, 21));
++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->text, " This is some ");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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 ");
+ BOOST_CHECK_EQUAL (i->line, 0);
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
++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->text, "bold");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
BOOST_CHECK_EQUAL (i->bold, true);
BOOST_CHECK_EQUAL (i->italic, false);
BOOST_CHECK_EQUAL (i->underline, false);
- BOOST_CHECK_EQUAL (i->text, "bold");
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
++i;
BOOST_CHECK (i != subs.end ());
+ BOOST_CHECK_EQUAL (i->text, " and some ");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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 ");
+ BOOST_CHECK_EQUAL (i->line, 0);
++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->text, "bold italic");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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");
+ BOOST_CHECK_EQUAL (i->line, 0);
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
++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->text, " and some ");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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 ");
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
++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->text, "underlined");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
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->line, 0);
BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
+ ++i;
+
+ BOOST_CHECK_EQUAL (i->text, ".");
+ BOOST_CHECK_EQUAL (i->font, "Arial");
+ BOOST_CHECK_EQUAL (i->font_size, 42);
BOOST_CHECK_EQUAL (i->bold, false);
BOOST_CHECK_EQUAL (i->italic, false);
BOOST_CHECK_EQUAL (i->underline, false);
- BOOST_CHECK_EQUAL (i->text, ".");
+ BOOST_CHECK_EQUAL (i->line, 0);
+ BOOST_CHECK_EQUAL (i->from, sub::Time (0, 1, 1, 1));
+ BOOST_CHECK_EQUAL (i->to, sub::Time (0, 1, 2, 10));
++i;
BOOST_CHECK (i == subs.end ());
diff --git a/test/stl_writer_test.cc b/test/stl_writer_test.cc
new file mode 100644
index 0000000..91b03b4
--- /dev/null
+++ b/test/stl_writer_test.cc
@@ -0,0 +1,51 @@
+/*
+ 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_writer.h"
+#include "subtitle.h"
+#include "test.h"
+
+using std::list;
+using std::ifstream;
+using std::ofstream;
+
+/* Test writing of an STL file */
+BOOST_AUTO_TEST_CASE (stl_writer_test)
+{
+ list<sub::Subtitle> subs;
+ subs.push_back (sub::Subtitle (" This is a subtitle ", "Arial", 42, false, false, false, 0, sub::Time (0, 0, 41, 9), sub::Time (0, 0, 42, 21)));
+ subs.push_back (sub::Subtitle (" and that's a line break", "Arial", 42, false, false, false, 1, sub::Time (0, 0, 41, 9), sub::Time (0, 0, 42, 21)));
+ subs.push_back (sub::Subtitle (" This is some ", "Arial", 42, false, false, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle ("bold", "Arial", 42, true, false, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle (" and some ", "Arial", 42, false, false, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle ("bold italic", "Arial", 42, true, true, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle (" and some ", "Arial", 42, false, false, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle ("underlined", "Arial", 42, false, false, true, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+ subs.push_back (sub::Subtitle (".", "Arial", 42, false, false, false, 0, sub::Time (0, 1, 1, 1), sub::Time (0, 1, 2, 10)));
+
+ ofstream f ("build/test/test.stl");
+ sub::STLWriter writer (subs, f);
+ f.close ();
+
+ check_text ("test/ref/test.stl", "build/test/test.stl");
+}
+
+
diff --git a/test/test.cc b/test/test.cc
index eb6eecf..3556fa5 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -20,3 +20,27 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE libsub_test
#include <boost/test/unit_test.hpp>
+#include <fstream>
+#include <string>
+
+using std::string;
+using std::ifstream;
+using std::getline;
+
+void
+check_text (string a, string b)
+{
+ ifstream p (a.c_str ());
+ ifstream q (b.c_str ());
+
+ string x;
+ string y;
+ while (p.good() && q.good()) {
+ getline (p, x);
+ getline (q, y);
+ BOOST_CHECK_EQUAL (x, y);
+ }
+
+ BOOST_CHECK (p.good() == false);
+ BOOST_CHECK (q.good() == false);
+}
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 0000000..a898694
--- /dev/null
+++ b/test/test.h
@@ -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.
+
+*/
+
+#include <string>
+
+void check_text (std::string a, std::string b);
diff --git a/test/wscript b/test/wscript
index 5d16abb..8de63f8 100644
--- a/test/wscript
+++ b/test/wscript
@@ -17,6 +17,7 @@ def build(bld):
obj.use = 'libsub'
obj.source = """
stl_reader_test.cc
+ stl_writer_test.cc
test.cc
"""
obj.target = 'tests'